[英]What am i doing wrong? (Python)
I'm trying to make a basic number guessing game as I've just started coding.我正在尝试制作一个基本的猜数字游戏,因为我刚刚开始编码。 I don't understand what I am doing wrong.
我不明白我做错了什么。 I tried looking on the forums here but I failed to find an answer.
我尝试在这里查看论坛,但没有找到答案。 If anyone could tell me what I'm doing wrong I`d greatly appreciate it!
如果有人能告诉我我做错了什么,我将不胜感激!
import random
num = random.randint(1, 10)
while true:
guess = int(input("Guess a number between 1 and 10: "))
if guess is == num
print("you got it!")
break
else:
print("try again!")
ERROR:错误:
break
^
IndentationError: unexpected indent
It should be if guess == num:
.应该是
if guess == num:
。 You don't need the is
and you need to put :
on the if.你不需要
is
而你需要把:
放在 if 上。 Also, the true
should be True
and break
has to have the correct ident.此外,
true
应该是True
并且break
必须具有正确的标识。
import random
num = random.randint(1, 10)
while True:
guess = int(input("Guess a number between 1 and 10: "))
if guess == num:
print("you got it!")
break
else:
print("try again!")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.