尽管python中的表达式为false,但循环仍在运行

2024-09-26 22:43:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望循环询问名称和金额,根据用户的选择,如果他们想继续,如果用户输入“y”,循环应该继续,否则如果用户输入“n”,循环应该终止,但如果我输入“n”,循环不会停止

import os


bidders={}

to_countinue=True

while to_countinue:

    name=input("Enter your name:\t")
    amount=int(input("\nBidding Amount:\t"))

    bidders[name]=amount

    count=input("\nIs there any other bidders (y/n):\t").lower

    if count=="n":
        to_countinue=False

    os.system('cls')

max=0
won=""
for key in bidders:

    if bidders[key]>max:
        max=bidders[key]
        won=key

os.system('cls')

print(f"The biiding was won by{key} with {max} bidding amount")


1条回答
网友
1楼 · 发布于 2024-09-26 22:43:19

lower将简单地为您提供该函数的地址,非常不可能等于"n"

如果要调用它,则需要使用lower(),如中所示:

count = input("\nAre there any other bidders (y/n)?:\t").lower()

以下文字记录显示了不同之处:

>>> print("Hello".lower)
<built-in method lower of str object at 0x7f4e525fc6f0>
>>> print("Hello".lower())
hello

相关问题 更多 >

    热门问题