#!/usr/bin/env python oldboy_age = 56
#while True 是个死循环,需要用break来退出
while True: get_num = int(input("Pls guess oldboy\'s age:")) if get_num == oldboy_age: print("Oldboy is {age} years old.".format(age=get_num)) break elif get_num > oldboy_age: print("Your input is larger than his age.") else: print("Your input is smaller than his age.")
运行结果:
D:\Python\Python36\python.exe "E:/python 14/day0101.py" Pls guess oldboy's age:99 Your input is larger than his age. Pls guess oldboy's age:22 Your input is smaller than his age. Pls guess oldboy's age:56 Oldboy is 56 years old. Process finished with exit code 0
本文介绍了一个使用Python编写的简单猜年龄游戏程序。通过一个死循环,程序不断请求用户猜测一个预设的年龄,直到猜中为止。每次猜测后,程序会给出提示,告诉用户输入的数字是太大还是太小。当用户猜中年龄时,程序会显示正确的年龄并结束。
1962

被折叠的 条评论
为什么被折叠?



