1 #猜数字--核心代码--猜测次数--随机函数和屏蔽错误代码 2 3 import random 4 secrst = random.randint(1,99) 5 6 number = secrst 7 8 amount = random.randint(3,8) 9 print(‘本次游戏次数为‘,amount,‘次‘) 10 11 count=0 12 while count<=amount: 13 try: 14 conversion=input(‘请猜数字‘) 15 guess=int(conversion) 16 17 if guess == number: 18 print(‘猜对了‘) 19 break 20 elif guess > number: 21 print(‘大了‘) 22 else: 23 print(‘小了‘) 24 25 count=count+1 26 27 if count==amount: 28 countine=input(‘任意键重新开始,“N”键退出游戏‘) 29 if countine !=‘n‘: 30 count=0 31 else: 32 exit() 33 except: 34 print(‘请输入数字,而不是其他‘)
猜数字--随机函数和屏蔽错误代码
import random
secrst = random.randint(1,99)
number = secrst
amount = random.randint(3,8)
print(‘本次游戏次数为‘,amount,‘次‘)
时间: 2024-10-12 08:16:20