1-10猜数字作业疑问
import randomsecret = random.randint(1,10)
temp = input("猜数字:")
guess = int(temp)
if guess == secret:
print("你猜对了")
while guess != secret:
if guess > secret:
print("大了")
if guess < secret:
print("小了")
temp = input("再猜一次:")
guess = int(temp)
else:
print("你猜对了")
如果第一次就猜对了,会弹两句“猜对了”,应该怎么修改 本帖最后由 zltzlt 于 2020-2-10 17:07 编辑
下次提问发到 Python 交流板块 改成这样:
import random
secret = random.randint(1,10)
right = False
temp = input("猜数字:")
guess = int(temp)
if guess == secret:
print("你猜对了")
right = True
while guess != secret:
if guess > secret:
print("大了")
if guess < secret:
print("小了")
temp = input("再猜一次:")
guess = int(temp)
else:
if right == False:
print("你猜对了") 一个账号 发表于 2020-2-10 17:02
改成这样:
感谢大佬!
页:
[1]