あなたが学生か教員かを尋ねるコードを実行しようとしていて、あなたが居住者であり、回答に応じて証明書割引を適用していますが、何らかの理由で、食料コストの入力。私の投稿に間違いがあっても、これは初めてのことです。Python:文が繰り返され続ける文
このような(S)tudentまたは(F)aculty? S
寮生ですか? (Y/N)Y
食品費用:$ 4
食品費用:$ 4
食品費用:$ 4
等...
それは、このような
を行くべき(S)tudentまたは(F)教授? S
寮生ですか? (Y/N)Y
食品費用:$ 4
非食品コストの:$
総コスト$:
def calculate_food(user_type,gets_discount):
cost = raw_input("Food cost: $")
cost = float(cost)
if calculate_food('S',True):
return cost * .9
elif calculate_food('S',False):
return cost * .95
elif calculate_food('F',True):
return cost * .8
else:
return cost * .95
def calculate_other():
cost = raw_input("Non-food cost: $")
cost = float(cost)
return cost * 1.055
def calculate_total():
user_type = raw_input("(S)tudent or (F)aculty?")
if user_type == 'S':
gets_discount = raw_input("Dorm resident? (Y/N)")
if gets_discount == 'Y':
gets_discount == True
elif gets_discount == 'N':
gets_discount == False
else:
print("Invalid input, Y or N only.")
quit()
elif user_type == 'F':
gets_discount = raw_input("Meal plan? (Y/N)")
if gets_discount == 'Y':
gets_discount == True
elif gets_discount == 'N':
gets_discount == False
else:
print("Invalid input, Y or N only.")
quit()
else:
print("Invalid input, S or F only.")
quit()
calculate_food(user_type,gets_discount)
calculate_other()
totalCost = calculate_other() + calculate_food(user_type,gets_discount)
print"Total cost: $",totalCost
calculate_total()
'=='は比較です。 TrueまたはFalseに何も割り当てていない –
@ cricket_007他の問題の中でも... –