任务要求:编写一个函数,判断从键盘输入的字符串是否为python,是python,等待3秒程序退出;不是python,重新输入再次判断,当判断次数超过3次,等待3秒,程序退出,效果图如下
知识点:import语句、while循环、time.sleep()
参考答案:
# coding=utf-8
"""
Author: 笨笨
Date: 2020-12-26
"""
import time
def is_python():
count = 1
while(True):
str_1 = input("请输入字符串:")
count += 1
if str_1 == "python":
print("输入正确,程序即将退出")
time.sleep(3)
break
if count > 3:
print("错误次数超过3次,程序即将退出")
time.sleep(3)
break
is_python()