Questions Uploads

multiple lines of input.

I can no get this part 4) Using a loop, extend the program to handle multiple lines of input. Continue until the user enters q to quit.

here is my code

comma = ‘,’

no_string = ‘q’

user_input = 0

comma = ‘,’

while True:

   user_input = input(“Enter input string: “)

   if user_input == ‘q’:

      break

   if comma not in user_input:

       print(“nError: No comma in string.”)

   if not comma in user_input:

       continue

   else: 

       my_token = user_input.split(comma)

       first_word = my_token[0]

       first_word = first_word.strip()

       print(‘nFirst word: {0}’.format(first_word))

       second_word = my_token[1]

       second_word = second_word.strip()

       print(‘Second word: {0}’.format(second_word) + “nn”)

**** Problem *******

(1) Prompt the user for a string that contains two strings separated by a comma. (1 pt)

  • Examples of strings that can be accepted:
  • Jill, Allen
  • Jill , Allen
  • Jill,Allen

Ex:

Enter input string: Jill, Allen

(2) Report an error if the input string does not contain a comma. Continue to prompt until a valid string is entered. Note: If the input contains a comma, then assume that the input also contains two strings. (2 pts)

Ex:

Enter input string: Jill Allen
Error: No comma in string.
Enter input string: Jill, Allen

(3) Using string splitting, extract the two words from the input string and then remove any spaces. Output the two words. (2 pts)

Ex:

Enter input string: Jill, Allen
First word: Jill
Second word: Allen

(4) Using a loop, extend the program to handle multiple lines of input. Continue until the user enters q to quit. (2 pts)

Ex:

Enter input string: Jill, Allen
First word: Jill
Second word: Allen


Enter input string: Golden , Monkey
First word: Golden
Second word: Monkey


Enter input string: Washington,DC
First word: Washington
Second word: DC


Enter input string: q
 
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"

the dictionary’s elements with the jersey numbers in ascending order (i

I cannot get this code to even start correctly. I pasted the entire question i need the code for. Thank you

This program will store roster and rating information for a soccer team. Coaches rate players during tryouts to ensure a balanced team.

(1) Prompt the user to input five pairs of numbers: A player’s jersey number (0 – 99) and the player’s rating (1 – 9). Store the jersey numbers and the ratings in a dictionary. Output the dictionary’s elements with the jersey numbers in ascending order (i.e., output the roster from smallest to largest jersey number). Hint: Dictionary keys can be stored in a sorted list. (3 pts) 

Ex:

Enter player 1's jersey number: 84
Enter player 1's rating: 7

Enter player 2's jersey number: 23
Enter player 2's rating: 4

Enter player 3's jersey number: 4
Enter player 3's rating: 5

Enter player 4's jersey number: 30
Enter player 4's rating: 2

Enter player 5's jersey number: 66
Enter player 5's rating: 9


ROSTER
Jersey number: 4, Rating: 5
Jersey number: 23, Rating: 4
Jersey number 30, Rating: 2
...

(2) Implement a menu of options for a user to modify the roster. Each option is represented by a single character. The program initially outputs the menu, and outputs the menu after a user chooses an option. The program ends when the user chooses the option to Quit. For this step, the other options do nothing. (2 pts) 

Ex:

MENU
a - Add player
d - Remove player
u - Update player rating
r - Output players above a rating
o - Output roster
q - Quit

Choose an option: 

(3) Implement the “Output roster” menu option. (1 pt) 

Ex:

ROSTER
Jersey number: 4, Rating: 5
Jersey number: 23, Rating: 4
Jersey number 30, Rating: 2
...

(4) Implement the “Add player” menu option. Prompt the user for a new player’s jersey number and rating. Append the values to the two vectors. (1 pt) 

Ex:

Enter a new player's jersey number: 49
Enter the player's rating: 8

(5) Implement the “Delete player” menu option. Prompt the user for a player’s jersey number. Remove the player from the roster (delete the jersey number and rating). (1 pt) 

Ex:

Enter a jersey number: 4

(6) Implement the “Update player rating” menu option. Prompt the user for a player’s jersey number. Prompt again for a new rating for the player, and then change that player’s rating. (1 pt) 

Ex:

Enter a jersey number: 23
Enter a new rating for player: 6

(7) Implement the “Output players above a rating” menu option. Prompt the user for a rating. Print the jersey number and rating for all players with ratings above the entered value. (2 pts) 

Ex:

Enter a rating: 5

ABOVE 5
Jersey number: 66, Rating: 9
Jersey number: 84, Rating: 7
...
 
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"

7.15 Ch 8 Custom lab for SNHU Online – Program: Sorting movies (Lists and Dictionaries) (Python 3)

I almost have this code right, i cannot figure out why i am getting this error. Its a long problem. I pasted that and my current code with the output and error..7.15 Ch 8 Custom lab for SNHU Online – Program: Sorting movies (Lists and Dictionaries) (Python 3)

(1) Build a dictionary that contains the movie collection below. Hint: Combine movie title and director into a list. 

Year          Title                       Director

2005          Munich                      Steven Spielberg
2006          The Prestige                Christopher Nolan
2006          The Departed                Martin Scorsese
2007          Into the Wild               Sean Penn
2008          The Dark Knight             Christopher Nolan
2009          Mary and Max                Adam Elliot
2010          The King's Speech           Tom Hooper
2011          The Artist                  Michel Hazanavicius
2011          The Help                    Tate Taylor
2012          Argo                        Ben Affleck
2013          12 Years a Slave            Steve McQueen
2014          Birdman                     Alejandro G. Inarritu
2015          Spotlight                   Tom McCarthy
2016          The BFG                     Steven Spielberg

(2) Prompt the user for a single year and output the movie title(s) and director(s) from that year. Output N/A if the year is invalid. (4 pts) 

Ex:

Enter a year between 2005 and 2016:
2011
The Artist, Michel Hazanavicius
The Help, Tate Taylor

(3) After prompting the user for a year and displaying the title(s) and directors(s) from that year, display a menu. The menu enables a user to display the movies sorted by year, director, or movie title. Each option is represented by a single character.

The program initially outputs the menu, and outputs the menu after a user chooses an option. If an invalid character is entered, continue to prompt for a valid choice. The program ends when the user chooses the option to Quit. Hint: Implement Quit before implementing other options. For this step, the other options do nothing. (1 pt) 

Ex:

Enter a year between 2005 and 2016:
2011
The Artist, Michel Hazanavicius
The Help, Tate Taylor

MENU
Sort by:
y - Year
d - Director
t - Movie title
q - Quit

Choose an option:

(4) Implement the sort by year menu option. Note: There is a newline and a tab between the year and the movie title/director. (2 pts) 

Ex:

...
Choose an option:
y
2005:
    Munich, Steven Spielberg

2006:
    The Prestige, Christopher Nolan
    The Departed, Martin Scorsese

2007:
    Into the Wild, Sean Penn

2008:
    The Dark Knight, Christopher Nolan

...

(5) Implement the sort by director menu option. For directors with multiple films on the list, order their films by year. Note: There is a newline and a tab between the director’s name and the movie title/year. (3 pts) 

Ex:

...
Choose an option:
d
Adam Elliot:
    Mary and Max, 2009

Alejandro G. Inarritu:
    Birdman, 2014

Ben Affleck:
    Argo, 2012

Christopher Nolan:
    The Dark Knight, 2008
    The Prestige, 2006

...

(6) Implement the sort by movie title menu option. Note: There is a newline and a tab between the movie title and the movie director/year. (2 pts) 

Ex:

...
Choose an option:
t
12 Years a Slave:
    Steve McQueen, 2013

Argo:
    Ben Affleck, 2012

Birdman:
    Alejandro G. Inarritu, 2014

Into the Wild:
    Sean Penn, 2007

...

moviesDict = {2005: [[‘Munich’,’Steven Spielberg’]],

2006: [[‘The Prestige’,’Christopher Nolan’],[‘The Departed’,’Martin Scorsese’]],

2007: [[‘Into the Wild’, ‘Sean Penn’]],

2008: [[‘The Dark Knight’, ‘Christopher Nolan’]],

2009: [[‘Mary and Max’, ‘Adam Elliot’]],

2010: [[“The King’s Speech”,’Tom Hooper’]],

2011: [[‘The Artist’, ‘Michel Hazanavicius’],[‘The Help’, ‘Tate Taylor’]],

2012: [[‘Argo’, ‘Ben Affleck’]],

2013: [[’12 Years a Slave’, ‘Steve McQueen’]],

2014: [[‘Birdman’, ‘Alejandro G. Inarritu’]],

2015: [[‘Spotlight’, ‘Tom McCarthy’]],

2016: [[‘The BFG’, ‘Steven Spielberg’]]}

year = int(input(“Enter a year between 2005 and 2016:n”))

if(year<2005 or year>2016):

print(“N/A”)

else:

movies = moviesDict[year]

for movie in movies:

print(movie[0]+”, “+movie[1])

var = 1

print(“”)

while var==1:

print(“MENU”)

print(“Sort by:”)

print(“y – Year”)

print(“d – Director”)

print(“t – Movie title”)

print(“q – Quit”)

print(“”)

option = input(“Choose an option:n”)

if(option == ‘y’):

for key in sorted(moviesDict.keys()):

print(key,end=’:’)

print(“”)

for movie in moviesDict[key]:

print(“t”+movie[0]+”, “+movie[1])

print(“”)

elif(option == ‘d’):

dirDict = {}

for key in sorted(moviesDict.keys()):

for movie in moviesDict[key]:

dire = movie[1]

if dire in dirDict:

dirDict[dire].append([movie[0],key])

else:

dirDict[dire] = [[movie[0],key]]

for key in sorted(dirDict.keys()):

print(key,end=’:’)

print(“”)

for dire in dirDict[key]:

print(“t”+ str(dire[0])+ “, “+str(dire[1]))

print(“”)

elif(option == ‘t’):

titleDict = {}

for key in sorted(moviesDict.keys()):

for movie in moviesDict[key]:

title = movie[0]

if title in titleDict:

titleDict[title].append([movie[1],key])

else:

titleDict[title] = [[movie[1],key]]

for key in sorted(titleDict.keys()):

print(key,end=’:’)

print(“”)

for title in titleDict[key]:

print(“t”+str(title[0])+”, “+str(title[1]))

print(“”)

elif(option == ‘q’):

break;

else:

print(“Invalid option”)

Enter a year between 2005 and 2016:

The Artist, Michel Hazanavicius

The Help, Tate Taylor

MENU

Sort by:

y – Year

d – Director

t – Movie title

q – Quit

Choose an option:

Traceback (most recent call last):

File “main.py”, line 33, in <module>

option = input(“Choose an option:n”)

EOFError: EOF when reading a line

 
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"

movie collection

Build a dictionary that contains the movie collection below. Hint: Combine movie title and director into a list.

Year          Title                       Director

2005          Munich                      Steven Spielberg
2006          The Prestige                Christopher Nolan
2006          The Departed                Martin Scorsese
2007          Into the Wild               Sean Penn
2008          The Dark Knight             Christopher Nolan
2009          Mary and Max                Adam Elliot
2010          The King's Speech           Tom Hooper
2011          The Artist                  Michel Hazanavicius
2011          The Help                    Tate Taylor
2012          Argo                        Ben Affleck
2013          12 Years a Slave            Steve McQueen
2014          Birdman                     Alejandro G. Inarritu
2015          Spotlight                   Tom McCarthy
2016          The BFG                     Steven Spielberg

(2) Prompt the user for a single year and output the movie title(s) and director(s) from that year. Output N/A if the year is invalid. (4 pts)

Ex:

Enter a year between 2005 and 2016:
2011
The Artist, Michel Hazanavicius
The Help, Tate Taylor

(3) After prompting the user for a year and displaying the title(s) and directors(s) from that year, display a menu. The menu enables a user to display the movies sorted by year, director, or movie title. Each option is represented by a single character.

The program initially outputs the menu, and outputs the menu after a user chooses an option. If an invalid character is entered, continue to prompt for a valid choice. The program ends when the user chooses the option to Quit. Hint: Implement Quit before implementing other options. For this step, the other options do nothing. (1 pt)

Ex:

Enter a year between 2005 and 2016:
2011
The Artist, Michel Hazanavicius
The Help, Tate Taylor

MENU
Sort by:
y - Year
d - Director
t - Movie title
q - Quit

Choose an option:

(4) Implement the sort by year menu option. Note: There is a newline and a tab between the year and the movie title/director. (2 pts)

Ex:

...
Choose an option:
y
2005:
    Munich, Steven Spielberg

2006:
    The Prestige, Christopher Nolan
    The Departed, Martin Scorsese

2007:
    Into the Wild, Sean Penn

2008:
    The Dark Knight, Christopher Nolan

...

(5) Implement the sort by director menu option. For directors with multiple films on the list, order their films by year. Note: There is a newline and a tab between the director’s name and the movie title/year. (3 pts)

Ex:

...
Choose an option:
d
Adam Elliot:
    Mary and Max, 2009

Alejandro G. Inarritu:
    Birdman, 2014

Ben Affleck:
    Argo, 2012

Christopher Nolan:
    The Dark Knight, 2008
    The Prestige, 2006

...

(6) Implement the sort by movie title menu option. Note: There is a newline and a tab between the movie title and the movie director/year. (2 pts)

Ex:

...
Choose an option:
t
12 Years a Slave:
    Steve McQueen, 2013

Argo:
    Ben Affleck, 2012

Birdman:
    Alejandro G. Inarritu, 2014
Build a dictionary that contains the movie collection below. Hint: Combine movie title and director into a list. 
Year          Title                       Director

2005          Munich                      Steven Spielberg
2006          The Prestige                Christopher Nolan
2006          The Departed                Martin Scorsese
2007          Into the Wild               Sean Penn
2008          The Dark Knight             Christopher Nolan
2009          Mary and Max                Adam Elliot
2010          The King's Speech           Tom Hooper
2011          The Artist                  Michel Hazanavicius
2011          The Help                    Tate Taylor
2012          Argo                        Ben Affleck
2013          12 Years a Slave            Steve McQueen
2014          Birdman                     Alejandro G. Inarritu
2015          Spotlight                   Tom McCarthy
2016          The BFG                     Steven Spielberg
(2) Prompt the user for a single year and output the movie title(s) and director(s) from that year. Output N/A if the year is invalid. (4 pts) 

Ex:
Enter a year between 2005 and 2016:
2011
The Artist, Michel Hazanavicius
The Help, Tate Taylor
(3) After prompting the user for a year and displaying the title(s) and directors(s) from that year, display a menu. The menu enables a user to display the movies sorted by year, director, or movie title. Each option is represented by a single character.
The program initially outputs the menu, and outputs the menu after a user chooses an option. If an invalid character is entered, continue to prompt for a valid choice. The program ends when the user chooses the option to Quit. Hint: Implement Quit before implementing other options. For this step, the other options do nothing. (1 pt) 

Ex:
Enter a year between 2005 and 2016:
2011
The Artist, Michel Hazanavicius
The Help, Tate Taylor

MENU
Sort by:
y - Year
d - Director
t - Movie title
q - Quit

Choose an option:
(4) Implement the sort by year menu option. Note: There is a newline and a tab between the year and the movie title/director. (2 pts) 

Ex:
...
Choose an option:
y
2005:
    Munich, Steven Spielberg

2006:
    The Prestige, Christopher Nolan
    The Departed, Martin Scorsese

2007:
    Into the Wild, Sean Penn

2008:
    The Dark Knight, Christopher Nolan

...
(5) Implement the sort by director menu option. For directors with multiple films on the list, order their films by year. Note: There is a newline and a tab between the director's name and the movie title/year. (3 pts) 

Ex:
...
Choose an option:
d
Adam Elliot:
    Mary and Max, 2009

Alejandro G. Inarritu:
    Birdman, 2014

Ben Affleck:
    Argo, 2012

Christopher Nolan:
    The Dark Knight, 2008
    The Prestige, 2006

...
(6) Implement the sort by movie title menu option. Note: There is a newline and a tab between the movie title and the movie director/year. (2 pts) 

Ex:
...
Choose an option:
t
12 Years a Slave:
    Steve McQueen, 2013

Argo:
    Ben Affleck, 2012

Birdman:
    Alejandro G. Inarritu, 2014

Into the Wild:
    Sean Penn, 2007
Into the Wild:
    Sean Penn, 2007 pts)
 

 How do you first Prompt the user for a single year and output the movie title(s) and director(s) from that year. Output N/A if the year is invalid.  I am having a hardtime trying to understand this. Can you explain and break dumb it done.  Here is my code
# Build a dictionary containing the specified movie collection
dict ={           'Munich':[2005,'Steven Spielberg'],  'The Prestige':[2006,'Christopher Nolan'],'The Departed':[2006,'Into the Wild'],
           'Into the Wild':[2007,'Sean Penn'],      'The Dark Knight':[2008,'Christopher Nolan'],'Mary and Max':[2009,'Adam Elliot'],
       "The King's Speech":[2010,'Tom Hooper'],          'The Artist':[2011,'Michel Hazanavicius'],
                'The Help':[2011,'Tate Taylor'],               'Argo':[2012,'Ben Affleck'],  '12 Years a Slave':[2013,'Steve McQueen'],
                 'Birdman':[2014,'Alejandro G. Inarritu'],'Spotlight':[2015,'Tom McCarthy'],          'The BFG':[2016,'Steven Spielberg']}
                 

userinput = int(input('Enter a year between 2005 and 2016:n'))
prompt = True
if (prompt > 2005) or (prompt <2016):
    print ('N/A')
else:
    dict.list



Thank you for help and time. 
 
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"