问题是“请用户输入年龄,检查输入的年龄是否大于0。如果年龄小于12美元,票价为12美元,否则票价为18美元”
def main() :
n = int(input("Insert your age : ")) #asking for users age
while True : # checking if users age is more than 0
if n > 0 :
break
return n
if price_checker(n) :
print("Price is 12 dollars")
else :
print("Price is 18 dollars")
def price_checker(x) :
if x < 12 :
return True
else :
return False
main()当我打印它时,唯一执行的代码是“插入您的年龄:”我尝试了几种方法来修复它,但是它只会导致更多的混乱
发布于 2022-11-30 14:59:47
只需检查数字是否小于或等于0,而不是while循环。
def main() :
n = int(input("Insert your age : ")) #asking for users age
if n <= 0:
print("Please enter an age greater than 0")
elif price_checker(n) :
print("Price is 12 dollars")
else :
print("Price is 18 dollars")
def price_checker(x) :
if x < 12 :
return True
else :
return False
main()https://stackoverflow.com/questions/74629827
复制相似问题