【问题标题】:I am extremely new to python and I am making a random number guessing game我对 python 非常陌生,我正在制作一个随机数猜谜游戏
【发布时间】:2023-01-22 11:13:38
【问题描述】:

现在,我有它,所以它会打印它选择的随机数。但是,无论我是错还是对,它总是说我错了。

这是我的代码:

import random

amount_right = 0
number = random.randint(1, 2)
guess = input
print(number)

print(
    "welcome to this number guessing game!! I am going to think of a number from 1-10 and you have to guess it! Good luck!")

input("enter your guess here! ")

if guess != number:
    print("Not quite!")
    amount_right -= 1
    print("you have a score of ", amount_right)

else:
    print("good Job!!")
    amount_right += 1
    print("you have a score of ",amount_right,"!")

我做错什么了?如果有任何帮助,我正在使用 Pycharm。

我尝试检查我的缩进,我尝试切换哪些行是 if 和 else 语句(第 13 - 21 行),我尝试将第 18 - 21 行更改为 elif: 语句

【问题讨论】:

  • guess = input 不要求任何输入,而是将输入函数分配给猜测哪个不是您想要的。
  • 输入在错误的行,你必须接受输入并直接存储它
  • 你要guess = int(input("enter your guess here! "))

标签: python pycharm numbers


【解决方案1】:
guess = int(input())

您需要将您的猜测转换为int,并且输入中应该有()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-29
    • 2019-06-02
    • 1970-01-01
    相关资源
    最近更新 更多