首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python通灵猜谜游戏重复10次

Python通灵猜谜游戏重复10次
EN

Stack Overflow用户
提问于 2021-02-08 19:53:08
回答 1查看 21关注 0票数 1

我想要它,所以它将随机生成1-10之间的数字,用户将输入他们的猜测。然后它会输出它是对还是错,10轮后它会告诉他们他们是多么通灵。我已经完成了大部分工作,但我不能让它随机生成10个数字,而是生成1个数字,你可以只输入这个数字,如果你找到那个数字,每次都会正确

代码语言:javascript
复制
import random
score=0
random=(random.randint(1,10))

for index in range(10):
    guess=int(input("Choose a number between 1 and 10:"))
    if random==guess:
        score+=1
        print ("Correct, Next")
    else:
        print ("Incorrect, Next")
    
if score==10:
    print("Final score:Super mystic")
elif score>=7:
    print("Final score:Good")
elif score>=5:
    print ("Final score:You need more practice")
else:
    print ("Final score:Dont become a psychic")
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-08 20:03:04

您需要将random=(random.randint(1,10))放在for循环中,以便它在每次循环时都会发生变化:

代码语言:javascript
复制
for index in range(10):
    random=(random.randint(1,10))
    guess=int(input("Choose a number between 1 and 10:"))

然后剩下的代码

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66101120

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档