import random
number= random.randint(1,10)
count=0
guess=""
guess=int(input("please guess:")
while guess!= number:
if guess < number:
print("lower")
count++
elif guess > number:
print("higher")
count++
elif guess==number:
print("Good job, you got my number")
print("You got it in,",count,"tries")
当我尝试运行它时出于某种原因,它说我的语法无效。请帮忙。
答案 0 :(得分:3)
这是Python,而不是C或JS。这样:
count++
应写成:
count += 1
另外,请记住Python对缩进敏感。
while guess!= number:
if guess < number:
print("lower")
count++
elif guess > number:
print("higher")
count++
elif guess==number:
print("Good job, you got my number")
print("You got it in,",count,"tries")
最后,你错过了一个右括号:
guess=int(input("please guess:"))
嗯,祝你好运!
答案 1 :(得分:2)
你错过了一个结束括号
guess=int(input("please guess:")
应该是:
guess=int(input("please guess:"))
希望有所帮助
您还需要更改缩进:
elif guess==number:
print("Good job, you got my number")
print("You got it in,",count,"tries")
也正确递增