- 主题:初学者参照小甲鱼编写的猜数字游戏
欢迎大家提意见。
#猜数字游戏
print("--猜数字--")
import random
secret = random.randint(1,20)
times = input("你觉得自己几次能猜中呢:")
times = int(times)-1
temp = input("猜猜我心中想的数字是:\n")
guess = int(temp)
round = 1
while round <= times:
if guess == secret:
print("我草,这都行!")
break
elif guess > secret:
print("太大了!")
else:
print("太小了!")
temp = input("第"+str(round)+"轮没猜中,请重新输入吧:")
guess = int(temp)
round +=1
if round > times:
if guess == secret:
print("我草,这都行!")
else:
print("太遗憾了,次数用完了也没猜对!")
print("我心中想的数字是:"+str(secret))
print("GAME OVER!")
--
FROM 111.203.202.*
times -= 1后,times有可能等于0,round是可能大于times的。不过这可能是我对times定义的问题,我还在摸索阶段。
while else 学到了,谢谢大佬。
【 在 ToSimplicity 的大作中提到: 】
: 可以用while ... else ...
: round > times 时,没有猜中可言
--
FROM 111.203.202.*
确实是我画蛇添足了,谢谢大佬。
#猜数字游戏
print("--猜数字--")
import random
secret = random.randint(1,20)
secret = 8
times = input("你觉得自己几次能猜中呢:")
times = int(times)
temp = input("猜猜我心中想的数字是:\n")
guess = int(temp)
round = 1
while round < times:
if guess == secret:
print("我草,这都行!")
break
elif guess > secret:
print("太大了!")
else:
print("太小了!")
temp = input("第"+str(round)+"轮没猜中,请重新输入吧:")
guess = int(temp)
round +=1
else:
if guess == secret:
print("我草,这都行!")
else:
print("太遗憾了,次数用完了也没猜对!")
print("我心中想的数字是:"+str(secret))
print("GAME OVER!")
【 在 ToSimplicity 的大作中提到: 】
: 可以用while ... else ...
: round > times 时,没有猜中可言
--
FROM 111.203.202.*
文明出行不好吗
【 在 Capvilla 的大作中提到: 】
: 欢迎大家提意见。
: #猜数字游戏
: print("--猜数字--")
: ...................
--
FROM 180.166.53.*
你想说啥?
【 在 iconquer 的大作中提到: 】
:文明出行不好吗
- 来自 水木社区APP v3.5.7
--
FROM 120.245.24.*