Loading

猜数字

1-实例代码

'''---------------------------------
# @Date:   2023-06-04 15:10:24
# @Author: Devin
# @Last Modified: 2023-06-04 15:18:55
------------------------------------'''

'''
程序说明:
	电脑给出一个范围内的随机数,用户尝试根据反馈猜测,直至猜对为止。
VERSION:1
'''

import random
# 电脑给出1—10范围内的随机整数
number=random.randint(1,10)

while True:
	# 用户尝试猜测数字
	guess=int(input("猜数字:"))
	if guess<number:
		print("猜小了...,请继续")
	elif guess>number:
		print("猜大了...,请继续")
	else:
		print("真棒,你猜对了!")
		break

2-运行截图

posted @ 2023-06-04 15:28  Devinwon  阅读(45)  评论(0)    收藏  举报