提示用户输入年龄如果大于等于18则告知用户可以查看;如果小于10岁则告知不允许查看;如果大于等于10岁则提示用户是否继续查看 1、0。如果输入 的是1则提示用户可以查看否则提示不可以查看。请用三种方法完成
方法一:
age = int(input("请输入您的年龄:")) if age >= 18: print("您可以查看") elif age < 10: print("您不允许查看") else: choice = int(input("您是否继续查看?(1是,0否)")) if choice == 1: print("您可以查看") else: print("您不允许查看")
方法二:
age = int(input("请输入您的年龄:")) if age >= 18: print("您可以查看") elif age < 10: print("您不允许查看") else: choice = input("您是否继续查看?(1是,0否)") if choice == "1": print("您可以查看") else: print("您不允许查看")
方法三:
def check_age(age): if age >= 18: print("您可以查看") elif age < 10: print("您不允许查看") else: choice = int(input("您是否继续查看?(1是,0否)")) if choice == 1: print("您可以查看") else: print("您不允许查看")
age = int(input("请输入您的年龄:")) check_age(age
原文地址: https://www.cveoy.top/t/topic/eCNz 著作权归作者所有。请勿转载和采集!