您好我的代码需要帮助。在询问用户是否要开始之后,答案是应该开始5秒倒计时并提出第一个问题我该怎么做? 最后一件事就是当我运行程序时,即使我给出了正确的答案,这是肯定的,它会循环回到你准备好了吗。
import random
import sys
import os
print('What is your name?')
name = raw_input()
sys.stdin.readline()
print "Hello!",name
print('I will be asking a series of true of false uqestions, answer with
either true or false')
def introduction():
while True:
print('Shall we begin?')
ans = raw_input()
if ans == 'yes':
print('The questions will begin in 5 seconds')
else:
print('Please return when you are ready')
introduction()
答案 0 :(得分:0)
在python import time
中进行五秒倒计时,然后执行time.sleep(5)
要问一个问题question_answer = raw_input("Insert Question 1 here")
在你说"是"之后,代码将打印"问题将在五秒钟后开始。然后将恢复到无限循环,因为它是while True:
并且不会结束。如果您希望它结束x = True
然后while x:
,那意味着您可以稍后更改它。最后,我建议使用ans.lower()
以便输入"是"也会有用。
sys.stdin.readline()
也是冗余代码。
答案 1 :(得分:0)
我认为我的另一个答案非常明确,但这是您提出的部分问题中的代码 - 您要求添加的部分 - 享受:
import random
import time
print('What is your name?')
name = raw_input()
print("Hello!",name)
print('I will be asking a series of true of false questions, answer with
either true or false')
def introduction():
x = True
while x:
print('Shall we begin?')
ans = raw_input()
if ans.lower() == 'yes':
print('The questions will begin in 5 seconds')
time.sleep(5)
birthday = raw_input("When is your birthday?")
else:
print('Please return when you are ready')
introduction()