Solution to CS50p - Bank


In season 7, episode 24 of Seinfeld, Kramer visits a bank that promises to give $100 to anyone who isn’t greeted with a “hello.” Kramer is instead greeted with a “hey,” which he insists isn’t a “hello,” and so he asks for $100. The bank’s manager proposes a compromise: “You got a greeting that starts with an ‘h,’ how does $20 sound?” Kramer accepts.

Instructions
  • In a file called bank.py, implement a program that prompts the user for a greeting.
  • If the greeting starts with “hello”, output $0.
  • If the greeting starts with an “h” (but not “hello”), output $20.
  • The first number used cannot be a ‘0’.”
  • Otherwise, output $100.
  • Ignore any leading whitespace in the user’s greeting, and treat the user’s greeting case-insensitively.
                                             
#Prompt user for a Greeting. Convert it to lowercase & Strip any leading spaces
                                    
greeting = input("Greeting: ").lower().lstrip() #Assign the input to a variable "greeting" if greeting[0:5] == "hello": #Check if greeting is "hello" print("$0") elif greeting[0] == "h": #If not then check if first letter is h" print("$20") else: print("$100") #Otherwise default to Else Statement"