本文共 608 字,大约阅读时间需要 2 分钟。
#test 猜数字
#电脑随机生成1~100随机数,用户输入一个数字,电脑提示用户大或者小,猜错,继续提示;猜对,则程序终止。#coding:utf-8import randomnum = 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