|
|
发表于 2019-8-28 10:09:16
|
显示全部楼层
本帖最后由 xlxl 于 2019-8-28 10:12 编辑
通过input传入的是一个字符,这个时候 temp = "10" 是这样的格式,是无法与整形数字进行比较的,所以每次通过 input 获取到temp的值后,都要强制使用 int 做一次 类型转换;
这道题我自己写过一段代码,给你参考一下;
- import random
- print ('--------Guess the number i set--------')
- num = random.randint(1,10)
- for i in range (0,2 +1):
- print ('Please input the number:')
- tem = input()
- guess = int(tem)
- if guess != num:
- if guess < num:
- print('Input number is low,input again!')
- else:
- print('Input number is big,input again!')
- print('Input wrong,you got three chances totaly.')
- else:
- print ('You get the correct number\n')
- print ('no any award though you correct')
- break
- print ('Game over!^-^')
复制代码
|
|