Skip to content

Commit f7c44a4

Browse files
committed
guess number
1 parent 8dec512 commit f7c44a4

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

newcodes/answers/q43.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python
2+
# coding=utf-8
3+
4+
#!/usr/bin/env python
5+
#coding:utf-8
6+
7+
import random
8+
9+
number = random.randint(1,100)
10+
guess = 0
11+
12+
while True:
13+
num_input = input("please input one integer that is in 1 to 100:")
14+
guess += 1
15+
16+
if not num_input.isdigit():
17+
print("Please input interger.")
18+
elif int(num_input) < 0 or int(num_input) >= 100:
19+
print("The number should be in 1 to 100.")
20+
else:
21+
if number == int(num_input):
22+
print("OK, you are good.It is only {0}, then you successed.".format(guess))
23+
break
24+
elif number > int(num_input):
25+
print("your number is smaller.")
26+
elif number < int(num_input):
27+
print("your number is bigger.")

0 commit comments

Comments
 (0)