制作此示例代码:
a = input("Insert day: ")
a
if a == "saturday":
print("Good Saturday!")
elif a == "sunday":
print("Good Sunday!")
else:
print("hi")
我的目标是完成后重新做整个事情,因此要求输入,等待输入,输入后再打印,然后再次要求输入,依此类推。 所以我添加了一些东西来循环它:
a = input("Insert day: ")
count = 0
while (count < 1):
a
if a == "saturday":
print("Good Saturday!")
elif a == "sunday":
print("Good Sunday!")
else:
print("hi")
问题在于此新代码循环/发送了打印答案,我以前从未真正使用过循环,因为我说过我想让它在打印答案后询问“插入日期”,依此类推,从打印到询问输入有1或2秒的延迟,我该怎么办?
答案 0 :(得分:1)
要再次请求用户输入,只需将第一行也放入循环中即可:
while True:
a = input("Insert day: ")
if a == "saturday":
print("Good Saturday!")
elif a == "sunday":
print("Good Sunday!")
else:
print("hi")
答案 1 :(得分:1)
count = 0
while (count < 1):
a = input("Insert day: ")
if a == "saturday":
print("Good Saturday!")
elif a == "sunday":
print("Good Sunday!")
else:
print("hi")
因为要在循环外定义变量,所以变量变为无限大。