Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Please can you help
#1
TOPİC WAS CLOSEd
Reply
#2
"2-If the play name that the user gave as input is not inside the dictionary as a key then print out "Sorry. We don't have that theater play..."

I think the program is supposed to ask for the name of a play, not a theater. This may just be a matter of semantics since there is probably only one play per theater.

Requirement 2 says that you should print a message if the play name entered is not in the play dictionary. This should not happen:
plays = {
    'Hamilton'          : [18,5],
    'West Side Story'   : [13,7],
    'The Book of Mormon': [13,4]}

play = input('What play do you want to see? ')
seating = plays[play]
Output:
What play do you want to see? cats Traceback (most recent call last): File "...", line 7, in <module> seating = plays[play] KeyError: 'cats'
If the user enters the name of a play that is not showing, your program should print a nice message instead of crashing. There are ways to ask a dictionary if it contains a key. You should read about that.

"1-Try to find a way of warning users to write names exactly as they are written in the dictionary (Check strip().title() command)."

Users make mistakes. Instead of just replying "We don't have that show" if they ask to see "hamilton" or "Hamilton " instead of "Hamilton", you should try to correct the input. To better understand the requirement read up about str.strip() and str.title(). How could those be used to fix simple typing errors?
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020