伙计们!我是新来的。很高兴认识你!我有以下问题。我的随机数生成器总是做完全相同的数字。我猜想为什么会这样,但我不确定。你能不能解释一下我做错了什么,只写一些关于我的代码的话?谢谢!import randomdef begin(): r_num = random.randint(1, 10) p_num = int(input('Enter your number: ')) ch = (r_num, p_num) if ch[0] == ch[1]: print(ch[0]) print("You've won! Excellent!") play_again = input("Do you want to play again? y/n") if play_again == 'y' or play_again == 'Y': begin() elif play_again == 'n' or play_again == 'N': print('Goodbye!') elif ch[1] < ch[0]: print(ch[0]) print("Your number is lower than it must be!") begin() elif ch[1] > ch[0]: print(ch[0]) print("Your number is higher than it must be!") begin()def start(): gen = input('Print generate to begin playing! \n') if gen == 'generate': print('Success!') begin() else: print('Fail!') start()print('Welcome to my first Python game! Guess random generated number from 1 to 10!')start()
1 回答
森栏
TA贡献1810条经验 获得超5个赞
代码运行得非常好,所以你真的必须有令人难以置信的好/坏运气(取决于你的想法)。尝试在不同的 IDE 中运行代码 - 这是我能想到的唯一可能导致问题的原因。再次尝试运行脚本?
添加回答
举报
0/150
提交
取消