0

I'm trying to create a program, where the user types a word 5 times and then I plot the results. But I can't get past the first input statement.

import matplotlib.pyplot as plt
import time as t

times = []
mistakes = 0

print("This is a program to help you type faster. You will have to type the word 'programming' as fast as you can 5 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"):
        mistakes += 1

print("You made " + str(mistakes) + " mistake(s).")
print("Now let's see your evolution.")
t.sleep(3)

x = [1,2,3,4,5]
y = times
plt.plot(x,y)
plt.show()

The error message is:

Traceback (most recent call last):
  File "C:\Python27\time.py", line 8, in <module>
    input("Press Enter to continue.")
  File "<string>", line 0

    ^
SyntaxError: unexpected EOF while parsing

I'm new and have no clue what I did wrong
MojoMike
  • 33
  • 5
  • 5
    you are using python2 ... use python3 instead (or change to `raw_input`) – Joran Beasley Mar 10 '20 at 01:58
  • 2
    Does this answer your question? [My IDLE script is returning a weird error](https://stackoverflow.com/questions/20080386/my-idle-script-is-returning-a-weird-error) – Brian61354270 Mar 10 '20 at 01:59
  • 2
    Note that [Python 2 is dead](https://pythonclock.org/). – Amadan Mar 10 '20 at 02:04
  • @Amadan it's not dead, it's just pining for the fjords! But I agree, unless you have legacy code you should be on 3, and even with legacy code you can include various libraries to make it look like 3. – Ken Y-N Mar 10 '20 at 23:51

1 Answers1

1

This program runs fine on python 3. to make it work in python2 your would need to change input for raw_input:

import matplotlib.pyplot as plt
import time as t

times = []
mistakes = 0

print("This is a program to help you type faster. You will have to type the word 'programming' as fast as you can 5 times")
raw_input("Press Enter to continue.")

while len(times) < 5:
    start = t.time()
    word = raw_input("Type the word: ")
    end = t.time()
    time_elapsed = end - start

    times.append(time_elapsed)

    if (word.lower() != "programming"):
        mistakes += 1

print("You made " + str(mistakes) + " mistake(s).")
print("Now let's see your evolution.")
t.sleep(3)

x = [1,2,3,4,5]
y = times
plt.plot(x,y)
plt.show()
Gorlomi
  • 515
  • 2
  • 11