python判断大小

电脑随机一个范围内的数,用户输入数据判断, 如果数大了,提供”数大了“ 以此类推

import random
ran = int(random.randint(1,100))
print(ran)
while True:
num = int(input(“请输入0-100间的数字:”))
if num < 0 or num > 100:
input(“对不起,输入有误”)
else:
if num > ran:
print(“大了”)
elif num < ran:
print(“小了”)
elif num == ran:
print(“猜对了!”)
break

import random
suijishu = random.randint(1,10)
print(" 猜数字 ")
while True:
guess = int(input(“请输入一个1~10的数字:”))
if guess >10 or guess <0:
print(“输入有误,请重新输入”)
elif guess > suijishu:
print(“猜大了”)
elif guess < suijishu:
print(“猜小了”)
elif guess == suijishu:
print(“恭喜你,猜对了”)
break
print(“游戏结束”)

你可能感兴趣的:(python)