def 选择():
print('1.数字游戏:'.center(50))
user=input('请选择:')
return user
def 数字游戏():
count=5
y=0
j=0
while count:
x = input('\n\n你的数字:')
import random
r=str(random.randrange(1,20))
count -= 1
if x > r:
y=y+1
print('你赢了','他的数字是:',(r),'比分是:',y,j)
print('还有{}次机会'.format(count))
if y == 3:
print('游戏结束,你赢了','他的数字是:',(r),'比分是:',y,j)
break
elif x < r:
j=j+1
print('ta赢了','他的数字是:',(r),'比分是:',y,j)
print('还有{}次机会'.format(count))
if j == 3:
print('游戏结束,ta赢了','他的数字是:',(r),'比分是:',y,j)
break
else :
print('平局','他的数字是:',(r),'比分是:',y,j)
print('还有{}次机会'.format(count))
if j == y ==2:
print('游戏结束,平局','他的数字是:',(r),'比分是:',y,j)
break
while True:
user = 选择()
if user == '1':
数字游戏()
第一个写的小代码,后续根据学到的,加入进去