Python未读取IF内部的条件



noob程序员。我遇到了一个问题,python没有读取或忽略我在if中写的内容,它直接进入退出代码0。第一个if工作得很好,但在第一个else之后,它会一直读取到color=input。我非常感谢你的帮助。

chooseS = input('If you need the scanning service type 1, if you need printing press 2. ')
pages = (int(input('How many pages do you need?')))
costT = 0
cost = 0
costS = 0
color = 0
if chooseS == str(1):
costS = 20
email = input("Type the email where you want to receive the scanned document.")
costT = costS*pages
print("That would be " + str(costT) + " colones. You will receive it at the following adress: " + email + ".")
else:
if chooseS == str(2):
color = input("If you need it printed in color type 1. If you need black and white type 2. ")
if color == 1:
paper = input("Regular paper: type 1. Film paper:  type 2. Sticker paper: type 3.")
if paper == 1:
cost = 25
costT = int(pages) * cost
print("That would be: " + str(+costT) + " colones.")
if paper == 2:
cost = 250
costT = int(pages) * cost
print("That would be: " + str(+costT) + " colones.")
if paper == 3:
costo = 300
costoT = int(pages) * cost
print("That would be: " + str(+costT) + " colones.")
if color == 2:
papel = input("Regular paper: type 1. Sticker paper: type 2. ")
if paper == 1:
cost = 15
cost = int(pages) * cost
print("That would be: " + str(+costT) + " colones.")
if paper == 2:
cost = 250
costT = int(pages) * cost
print ("That would be: " + str(+costT) + " colones.")

对代码的任何额外输入也将受到赞赏。提前谢谢。

颜色、纸张和字符串,如果将它们视为整数,则值永远不会匹配。还有当你打字时用纸糊代替纸张。以下是修复这些错误后代码的样子:

chooseS = input('If you need the scanning service type 1, if you need printing press 2. ')
pages = (int(input('How many pages do you need?')))
costT = 0
cost = 0
costS = 0
color = 0
if chooseS == str(1):
costS = 20
email = input("Type the email where you want to receive the scanned document.")
costT = costS*pages
print("That would be " + str(costT) + " colones. You will receive it at the following adress: " + email + ".")
else:
if chooseS == str(2):
color = input("If you need it printed in color type 1. If you need black and white type 2. ")
if color == str(1):
paper = input("Regular paper: type 1. Film paper:  type 2. Sticker paper: type 3.")
if paper == str(1):
cost = 25
costT = int(pages) * cost
print("That would be: " + str(+costT) + " colones.")
if paper == str(2):
cost = 250
costT = int(pages) * cost
print("That would be: " + str(+costT) + " colones.")
if paper == str(3):
costo = 300
costoT = int(pages) * cost
print("That would be: " + str(+costT) + " colones.")
if color == str(2):
paper = input("Regular paper: type 1. Sticker paper: type 2. ")
if paper == str(1):
cost = 15
cost = int(pages) * cost
print("That would be: " + str(+costT) + " colones.")
if paper == str(2):
cost = 250
costT = int(pages) * cost
print ("That would be: " + str(+costT) + " colones.")

最新更新