新手Python入门题,不知道哪里不对,求各位帮忙

循环无法进行......

#p3_1.py
import random

secret = random.randint(1,10)

temp = input ("猜猜我现在在想哪个数字?")

guess = int(temp)

while guess != secret:
    temp = intput("猜错啦,重新输入吧")
    guess = int(temp)
    if guess > secret:
        print("大了大了")
    else:
        print("再大点试试")

if guess == secret:
    pirntf("猜对啦")

print("结束啦,不玩啦!")

3个回答

是因为代码拼写错误了2个地方,temp = intput("猜错啦,重新输入吧"),不是 intput,是input, pirntf("猜对啦") 不是pirntf是print

import random
secret = random.randint(1,10)

temp = input ("猜猜我现在在想哪个数字?")

guess = int(temp)

while guess != secret:
    ##temp = intput ("猜错啦,重新输入吧")
    temp = input("猜错啦,重新输入吧")
    guess = int(temp)
    if guess > secret:
        print("大了大了")
    else:
        print("再大点试试")

if guess == secret:
    ##pirntf("猜对啦")
    print("猜对啦")
print("结束啦,不玩啦!")
else:
    print("再大点试试")

这里不对,如果猜对了,也会走这个分支,导致输出再大点。将else换成if (guess < secret): 看看

temp = intput("猜错啦,重新输入吧")
更改
temp = input("猜错啦,重新输入吧")

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问