CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
jackfrued

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: jackfrued/Python-100-Days
Path: blob/master/Day01-15/code/Day05/guess.py
Views: 729
1
"""
2
猜数字游戏
3
计算机出一个1~100之间的随机数由人来猜
4
计算机根据人猜的数字分别给出提示大一点/小一点/猜对了
5
6
Version: 0.1
7
Author: 骆昊
8
Date: 2018-03-02
9
"""
10
import random
11
12
answer = random.randint(1, 100)
13
counter = 0
14
while True:
15
counter += 1
16
number = int(input('请输入: '))
17
if number < answer:
18
print('大一点')
19
elif number > answer:
20
print('小一点')
21
else:
22
print('恭喜你猜对了!')
23
break
24
print('你总共猜了%d次' % counter)
25
if counter > 7:
26
print('你的智商余额明显不足')
27
28