初学者,请多多指教!
主要是猜数字,大神们有什么改善的意见多提一提,谢谢大家!!!
该游戏猜1到10,然后只有三次机会。
import random
secrets = random.randint(1,10)
print('--------------------开始玩游戏吧--------------------')
count = 1
while count <= 3:
if count == 1:
temp = input('猜数字吧!只有三次机会哦:')
guess = int (temp)
if guess == secrets:
print('猜对了恭喜!')
break
elif guess < secrets:
print('猜小了!')
temp = input('再试一次吧:')
guess = int(temp)
else:
print('猜大了!')
temp = input('再试一次吧:')
guess = int(temp)
elif count == 2:
if guess == secrets:
print('猜对了恭喜!')
break
elif guess < secrets:
print('猜小了!')
temp = input('再试一次吧:')
guess = int(temp)
else:
print('猜大了!')
temp = input('再试一次吧:')
guess = int(temp)
elif count == 3:
if guess == secrets:
print('猜对了恭喜!')
break
elif guess < secrets:
print('猜小了!')
else:
print('猜大了!')
count = count + 1
if count == 4:
print('真可惜,次数用尽!')
print('游戏结束!')