Issue
New to coding and cant figure out why continue wont work in my for loop. After the print statements, I want to start the loop over again from the top. If anyone could let me know what im doing wrong that would be great. I am not allowed to share the cse231_random file sorry if this makes it so you cant run it.
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
Solution
Should the whole body be in indented?
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
Answered By - belwood
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.