python之猜数字小游戏
import random#随机数函数
a = random.randint(0, 50)#随机0-50之内的整数
print('------------------SWS工作室------------------')
c = int(input("猜一下慢蜗牛心里的数字(0-50之间哦):"))
n = 1
while 1:
if c < 0 or c > 50:
c = int(input("输入错误,请重新输入:"))
n += 1
else:
if c == a:
print("答对啦,可是没有奖励呢")
print("游戏结束,共用了" + str(n) + "次")
break
else:
if c > a:
c = int(input("大了大了,再猜一次:"))
n += 1
else:
c = int(input("格局小啦,再猜一次:"))
n += 1