if 语句中无法识别输入

时间:2021-03-18 04:23:49

标签: python python-3.x

choice = input('Are you ready to start the test (Y/N): ')
print (choice)
while choice not in ['Y','N',]:
    choice = input('Invalid choice. Are you ready to start the test (Y/N): ')
    print(choice)
    if choice  == 'N':
        sys.exit
    if choice == 'Y':
        print('Test starts in 3...')
        time.sleep(1)
        print('2...')
        time.sleep(1)
        print('1...')
        time.sleep(1)
        countdown(t)6
        print('BEGIN')

输出:

Welcome to type test
You will be given sixty seconds to type as many correct words as possible!
Are you ready to start the test (Y/N): Y
Y

1 个答案:

答案 0 :(得分:1)

我在本地使用了您的代码,缩进如下,并且运行良好:

import time
import sys

choice = input('Are you ready to start the test (Y/N): ')
print (choice)
while choice not in ['Y','N',]:
    choice = input('Invalid choice. Are you ready to start the test (Y/N): ')
print(choice)
if choice  == 'N':
    sys.exit
if choice == 'Y':
    print('Test starts in 3...')
    time.sleep(1)
    print('2...')
    time.sleep(1)
    print('1...')
    time.sleep(1)
    #countdown(t)
    print('BEGIN')