Я пишу код и получаю ошибку при использовании matplotlib в редакторе. Я получаю неверную синтаксическую ошибку, кто-нибудь знает почему? - PullRequest
0 голосов
/ 13 апреля 2020

импорт matplotlib.pyplot как plt

время импорта как t

times = [] ошибка = 0

print («вам нужно будет ввести слово« программирования » «так быстро, как вы можете пять раз»)

input («Нажмите Enter, чтобы продолжить.»)

, а len (times) <5 </p>

start = t.time()

word = input("Type the Word: ")

end = t.time()

time_elapsed = end - start

times.append(time_elapsed)

if(word.lower()! = "programming"):

   mistake += 1

print («Вы сделали» + str (ошибка) + «ошибки»)

print («Теперь давайте посмотрим на вашу эволюцию»)

t.sleep (3)

x = [1,2,3,4,5]

y = раз

plt.plot (x, y)

legend = ["1", " 2 "," 3 "," 4 "," 5 "]

plt.xticks (x, легенда)

plt.ylabel (" Время в секундах ")

plt.xlabel ("Попытки")

plt.title ("Ваша эволюция печати")

plt.show ()

1 Ответ

0 голосов
/ 13 апреля 2020

Единственная проблема была с отступом и синтаксисом. После удаления этих ошибок ваш код работает нормально. Код без ошибок:

import matplotlib.pyplot as plt
import time as t

times = []
mistake = 0
print("you will have to type the word 'programming' as fast as you can for five times")
input("Press Enter to Continue.")

while len(times) < 5:
    start = t.time()
    word = input("Type the Word: ")
    end = t.time()
    time_elapsed = end - start
    times.append(time_elapsed)
    if word.lower() != "programming":
        mistake += 1

print("You made" + str(mistake) + "mistakes.")
print("Now let's See your evolution")
t.sleep(3)
x = [1,2,3,4,5]
y = times
plt.plot(x,y)
legend = ["1","2","3","4","5"]
plt.xticks(x,legend)
plt.ylabel("Time in Seconds")
plt.xlabel("Attempts")
plt.title("Your Typing Evolution")
plt.show()

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...