python零基础入门 p5改进我们的小游戏 问题2
import random
secret=random.randint(1,10)
time=1
print("········我爱了!········")
temp =input("猜一下我爱什么数字:")
guess =int(temp)
while guess!=secret and time >=1 and time <3:
temp =input("错了,请重新输入:")
guess =int(temp)
if guess==secret:
if time==1:
print("你第一次就答对了!")
break
print("卧槽,你竟然猜对了")
else:
if guess<secret:
print("小了小了!")
else:
print("大了大了!")
time+=1
print("游戏结束!")
我现在这个可以限制输入次数为3次,但是还没实现在第一次输入正确的情况下,输出答对的提示。请问要怎么弄?
import random
secret = random.randint(1, 10)
time = 1
print("········我爱了!········")
temp = input("猜一下我爱什么数字:")
guess = int(temp)
while time >= 1 and time < 4:
temp = input("错了,请重新输入:")
guess = int(temp)
if guess == secret:
if time == 1:
print("你第一次就答对了!")
break
else:
print("卧槽,你竟然猜对了")
else:
if guess < secret:
print("小了小了!")
else:
print("大了大了!")
time += 1
print("游戏结束!") 刚刚的错了,这个才是对的:
import random
secret = random.randint(1, 10)
time = 1
print("········我爱了!········")
temp = input("猜一下我爱什么数字:")
guess = int(temp)
while time >= 1 and time < 4:
if guess == secret:
if time == 1:
print("你第一次就答对了!")
break
else:
print("卧槽,你竟然猜对了")
break
else:
if guess < secret:
print("小了小了!")
else:
print("大了大了!")
temp = input("错了,请重新输入:")
guess = int(temp)
time += 1
print("游戏结束!") import random
secret=random.randint(1,10)
time=1
print("········我爱了!········")
temp =input("猜一下我爱的数字:")
guess =int(temp)
if guess<secret:
print("小了小了!")
else:
print("大了大了!")
while guess!=secret and time <3:
temp =input("错误,请重新输入:")
guess =int(temp)
if guess==secret:
print("卧槽,你竟然猜对了!")
else:
if guess<secret:
print("小了小了!")
else:
print("大了大了!")
time=time+1
if time==2:
print("你还有最后一次机会!")
if time==1:
print("你运气真好,第一次就猜对了!")
print("游戏结束!")
我琢磨了一下写出了这个,也能用! 上面的错了,应该是这样:
import random
secret = random.randint(1, 10)
time = 1
print("········我爱了!········")
temp = input("猜一下我爱什么数字:")
guess = int(temp)
while time >= 1 and time < 4:
if guess == secret:
if time == 1:
print("你第一次就答对了!")
break
else:
print("卧槽,你竟然猜对了")
break
else:
if guess < secret:
print("小了小了!")
else:
print("大了大了!")
temp = input("错了,请重新输入:")
guess = int(temp)
time += 1
print("游戏结束!")
页:
[1]