- 帖子
- 3
- 精华
- 0
- 积分
- 18
- 阅读权限
- 10
- 注册时间
- 2016-3-9
- 最后登录
- 2016-7-6
|
新人第一帖,用两种代码实现了,基础比较差,大家帮忙从复杂度和执行效率等方面评价一下,感谢啦~
#!/usr/bin/python
# -*- coding=utf-8 -*-
import random
tnum = random.randint(0,100) # generate a random int type number
print('Guess what number I\'m thinking' )
n = int(input('plz input your answer:')) # get input
while n != tnum:
if n > tnum:
print('too large')
else:
print('too small')
n = int(input('plz input your answer:'))
if n == tnum:
print('you get it,congratulations!')
#!/usr/bin/python
# -*- coding=utf-8 -*-
import random
tnum = random.randint(0,100) # generate a random int type number
print('Guess what number I\'m thinking' )
n = int(input('plz input your answer:')) # get input
while True:
if n > tnum:
print('too large')
n = int(input('plz input your answer:'))
elif n < tnum:
print('too small')
n = int(input('plz input your answer:'))
else:
print('you get it,congratulations!')
break
|
|