|
- import random
- a = random.randint(1,10)
- guess = 0
- x = 3
- print('猜猜我现在想的数字:',end='')
- while guess != a and x > 0:
- while True:
- temp = input()
- if temp.isdigit():
- break
- else:
- print('请输入数字:',end='')
- guess = int(temp)
- x -= 1
- if guess == a:
- print('猜对了,你真聪明!')
- else:
- if guess > a:
- print('大了!大了!')
- else:
- print('小了!小了!')
- if x > 0:
- print('再试试吧!')
- if x == 1:
- print('最后一次机会了!')
- else:
- print('机会用光咯!')
- print('游戏结束了!')
复制代码
另外,你前面用的isinstance函数第一个参数是对象,第二个才是判断的类型,写反了。
望采纳! |
|