This is my version of speed typing test in Python. I am getting the following errors and I can't seem to understand them.
Shadows name 'random_sentence' from outer scope
Local variable 'user_input' value is not used
Shadows name 'user_input' from outer scope
Local variable 'i' value is not used
This is my python script
from sentence_list import sentences
import random
import time
global user_input, random_sentence
def time_block():
random_sentence = random.choice(sentences)
print(random_sentence)
print("\n")
start_time = time.time()
user_input = input()
end_time = time.time()
time_difference = end_time - start_time
print("Total time taken: ", round(time_difference, 2))
def error_block():
error_count = 0
for i in user_input.split(" "):
if i not in random_sentence.split(" "):
error_count += 1
print("Total number of errors made: ", error_count)
def words_per_minute():
word_count = 0
for i in user_input.split(""):
word_count += 1
wpm = word_count / 5
print("Words Per Minute (WPM): ", wpm)
time_block()
error_block()
words_per_minute()
I can't post the sentences file because it is too big. Please be free to use your own sentences and help me sort out this problem
Aucun commentaire:
Enregistrer un commentaire