Continue无法与if语句一起在for循环中使用(“ continue”未正确循环)

时间:2019-01-24 01:11:05

标签: python spyder

编码新手,无法弄清楚为什么继续在我的for循环中不起作用。在打印语句之后,我想从顶部重新开始循环。如果有人能让我知道我做错了什么,那太好了。我不能共享cse231_random文件,抱歉,如果这样做,将使您无法运行它。

import string
import random
import time
from cse231_random import randint
ALPHABET_EASY = string.ascii_letters 
ALPHABET = string.ascii_letters + string.punctuation


easy_str = ""
length=random.randint(3, 5)
for i in range(length):
   index=randint(0, len(ALPHABET_EASY))
   easy_str += ALPHABET_EASY[index]
print(easy_str)
start= time.time()
easy_input=input("\nEnter this string:")
stop= time.time()
easy_input=easy_input.replace(" ", "")
easy_input=easy_input
if stop-start>10:
 print("Oops! Too much time.")
 continue
elif easy_input.lower()==easy_str.lower():
 print("Good job! You spent {} of 10 seconds entering string [{}][{}]".format(stop-start,easy_str,easy_input))
 continue
elif easy_input.lower()!=easy_str.lower():
 print("Incorrect.")
 continue

1 个答案:

答案 0 :(得分:2)

整个身体应该缩进吗?

myUSER /
$ cd c
myUSER c
$