gpt4 book ai didi

python - Python 猜测列表

转载 作者:太空宇宙 更新时间:2023-11-04 09:17:29 26 4
gpt4 key购买 nike

我只是在学习 python 并且我写了这篇文章,但我想展示所有的猜测,也许它们是太高还是太低。 “responseList”部分是我需要帮助的地方。谢谢!

    import random, easygui

secret = random.randint (1, 100)
guess = 0
tries = 0

easygui.msgbox ("""Guess the secret number.
It is from 1 to 99. You have five tries. Get Guessin' !""")

while guess != secret and tries < 5:
user_response = guess = easygui.integerbox ("C'mon...GUESS!!! ")

if not guess: break
if guess <= (secret + 5) and guess > secret:
easygui.msgbox(str(guess) + " is too HIGH... but you're close!")
if guess >= (secret - 5) and guess < secret:
easygui.msgbox(str(guess) + " is too LOW... but you're close!")
if guess < (secret - 5):
easygui.msgbox(str(guess) + " is too LOW... Guess higher")
if guess > (secret + 5):
easygui.msgbox (str(guess) + " is too HIGH...Guess lower")

tries = tries + 1

responseList = [user_response]
easygui.msgbox (responseList)

if guess == secret:
easygui.msgbox ("Darn! You got it!")

else:
easygui.msgbox ("Ha, Ha, Ha! No more guesses! To the firin' squad with ya!")
easygui.msgbox (str(secret) + " was the secret number")

最佳答案

我猜您希望 responseList 包含所有用户响应的列表。你没有写它。 :)

您需要在开始时将 responseList 设置为空列表,然后将每个新响应append

responseList = [user_response] 每次都将其设置为单元素列表。显然,您最终会得到一个只有最后一个响应的单元素列表。

关于python - Python 猜测列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7264924/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com