我做了一个快速预算程序来确定买一件东西需要多长时间,但我遇到了一个问题。每当我尝试运行它时,一次性销售项目都不会添加到余额中。我的代码如下:
graphicsCard = 50
amdCpu = 80
itelCpu = 99
ram = 140
guitar = 199
case = 99
balance = 21
if (input('Has the graphics card been sold yet?').lower == "yes"):
balance += graphicsCard
if (input('Has the AMD cpu been sold yet?').lower == "yes"):
balance += amdCpu
if (input('Has the intel CPU been sold yet?').lower == "yes"):
balance += intelCpu
if (input('Has the RAM been sold yet?').lower == "yes"):
balance += ram
if (input('Has the Guitar been sold yet?').lower == "yes"):
balance += guitar
if (input('Has the Case been sold yet?').lower == "yes"):
balance += case
我在第一个if之后添加了一个else语句,以检测它是否正确地读取了我的“yes”答案,但它没有。
发布于 2018-06-18 04:31:22
您应该尝试使用.lower()
>>> myinput = input('Enter something: ')
Enter something: yes
>>> myinput.lower
<built-in method lower of str object at 0x7f79b2391068>
>>> myinput.lower()
'yes'
https://stackoverflow.com/questions/50900186
复制相似问题