20行python代码的入门级小游戏--源码:猜大小
源码:
1 import random 2 rang1 = int(input("请设置本局游戏的最小值:")) 3 rang2 = int(input("请设置本局游戏的最大值:")) 4 num = random.randint(rang1,rang2) 5 guess = "guess" 6 print("数字猜谜游戏!") 7 i = 0 8 while guess != num: 9 i += 1 10 guess = int(input("请输入你猜的数字:")) 11 12 if guess == num: 13 print("恭喜,你猜对了!") 14 elif guess < num: 15 print("你猜的数小了...") 16 else: 17 print("你猜的数大了...") 18 19 print("你总共猜了%d" %i + "次",end = '') 20 print(",快和你朋友较量一下...")
玩儿一下: