Python Program Help

MRAB python at mrabarnett.plus.com
Tue Jul 21 11:08:41 EDT 2020


On 2020-07-21 14:38, ksikor14--- via Python-list wrote:
> I can't seem to figure out what I am doing wrong.  I have tried everything.  This is what it is supposed to do:
> 
> (1) Prompt the user for a title for data. Output the title. (1 pt)
> 
> Ex:
> 
> Enter a title for the data:
> Number of Novels Authored
> You entered: Number of Novels Authored
> 
[snip]
> 
> Here is my code:
> 
> data_title = input("Enter a title for the data:\n")
> print("You entered:", data_title)
> h1 = input("\nEnter the column 1 header:\n")
> print("You entered:", h1)
> h2 = input("\nEnter the column 2 header:\n")
> print("You entered:", h2)
> point = input("\nEnter a data point (-1 to stop input):\n")
> 
> data = []
> while point != "-1":
>      words = point.split(",")
>      if len(words) == 1:
>          print("Error: No comma in string.")
>      elif len(words) > 2:
>          print("Error: Too many commas in input. ")
>      else:
>          try:
>              author = words[0]
>              num_novels = int(words[1])
>              print("Author:", author)
>              print("Number of Novel(s):", num_novels)
>              data.append((author, num_novels))
>          except ValueError:
>              print("Error: Comma not followed by an integer.")
>      point = input("\nEnter a data point (-1 to stop input):\n")
> 
> print("%33s" % data_title)
> print("%-20s|%23s" % (h1, h2))
> print("-" * 44)
> for item in data:
>      print("%-20s|%23d" % (item[0], item[1]))
> for item in data:
>      print("%20s %s" % (item[0], '*' * item[1]))
> 
> I get this error:
> 
> Traceback (most recent call last):
>    File "main.py", line 1, in <module>
>      data_title = input("Enter a title for the data:\n")
> EOFError: EOF when reading a line
> 
> And can't seem to figure out how to correct it any help would be greatly appreciated.
> 
How are you running it? At a system prompt with:

py main.py

or similar?


More information about the Python-list mailing list