python异常处理练习1

#test 猜数字
#电脑随机生成1~100随机数,用户输入一个数字,电脑提示用户大或者小,猜错,继续提示;猜对,则程序终止。

#coding:utf-8
import random
num = random.randint(0,100)
#print(num)
while True:
        try:
                guess = int(input("请输入一个1~100的随机数:"))
        except ValueError as err:
                print("Enter 1~100", err)
                continue
        if guess > num:
                print("%d greater random number"  %(guess))
        elif guess < num:
                print("%d smaller random number" %(guess))
        else:
                print("guess bingo,game over!")
                break
        print("\n")

转载于:https://blog.51cto.com/huwho/2167600

你可能感兴趣的:(python异常处理练习1)