因此,我试图建立一种方式,让某人可以按照以下规则进入他们想要的标志。
所有标志的收费至少为35.00美元。
前五个字母或数字包含在最低费用中;每增加一个角色需要支付4美元的费用。
如果标志是橡木制,请加20.00美元。松树不收费。
最低费用包括黑色或白色字符;金箔刻字需额外收费15美元。
因此,如果有人要使用橡木标志获得8个字符,并且金字母总数应该是82美元,但是我的代码似乎只处理我提出的第一个if语句,只需47美元,我唯一能解决这个问题的方法就是如果我改变使用数字而不是实际单词的颜色词。我想知道是否有办法仍然使用这些词而不是用数字替换它们
# Declare and initialize variables here.
Charge = 35.00
Black = 0.00
White = 0.00
Gold = 15.00
Pine = 0.00
Oak = 20.00
Characters = 0.00
Color = 0.00
Wood = 0.00
numChars = int(input("How many characters would you like on your sign? :"))
color = input("What color would you like your words on your sign to be? Black, White, or Gold :")
woodType = input("What type of wood would you like your sign to be? Pine or Oak :")
# Write assignment and if statements here as appropriate.
if numChars > 5:
Characters = (numChars - 5) * 4.00
if color == Gold:
Color = 15.00
if woodType == Oak:
Wood = 20.00
print("The charge for this sign is $" + str(Charge + Characters + Color + Wood))
# Declare and initialize variables here.
Charge = 35.00
Black = 0.00
White = 0.00
Gold = 15.00
Pine = 0.00
Oak = 20.00
Characters = 0.00
Color = 0.00
Wood = 0.00
numChars = int(input("How many characters would you like on your sign? :"))
color = int(input("What color would you like your words on your sign to be? Black(1), White(2), or Gold(3) :"))
woodType = int(input("What type of wood would you like your sign to be? Pine(1) or Oak(2) :"))
# Write assignment and if statements here as appropriate.
if numChars > 5:
Characters = (numChars - 5) * 4.00
if color == 3:
Color = 15.00
if woodType == 2:
Wood = 20.00
print("The charge for this sign is $" + str(Charge + Characters + Color + Wood))
在你的代码中,用Gold
替换"Gold"
和用Oak
替换"Oak"
。
你看,问题是你正在检查color
和woodType
是否等于Gold
和Oak
变量,但你想检查它们是否等于这些字符串,所以你需要将它们放在引号内。