【发布时间】:2019-10-06 17:30:03
【问题描述】:
print("10 apples on a tree")
userChoice = input("Would you like to change the amount on apples ([Y]/[N]): ")
if userChoice == 'Y':
appleAmount = input("Please enter the amount of apples: ")
if appleAmount == 1:
print("1 apple on a tree")
else:
print(appleAmount, "apples on a tree")
if userChoice == 'N':
print("Okay.")
每当我运行我的代码并输入“1”时。它打印出“树上的 1 个苹果”,而不是我写的“树上的 1 个苹果”。努力找出问题所在。
我的目标是,允许用户修改苹果的数量。如果他们决定输入“1”,则“apples”一词需要更改为“apple”。
我用谷歌搜索了一下,每个人都是这样做 if 语句的,但肯定有什么地方出了问题,或者我错过了什么。
【问题讨论】:
-
input()返回一个字符串值。字符串"1"与整数1不同。
标签: python if-statement printing