def introduction(): print("") print("Thank you for using Postage Calculator!") print( "It is more important than ever to stay in touch with loved ones during shelter-in-place." ) print( "We're here to help you determine how much it will cost to mail your item domestically." ) exitable_input( 'Please follow these instructions, or type "exit" to leave at any time. (Hit enter to continue) ' )
def take_weight(): # prompt user for weight print("") str_weight = exitable_input( "Please input the weight of your envelope in ounces. " '(For example, if your envelope weighs 1.2 ounces, enter "1.2"): ') # this will try to convert the entered in weight into a float. try: flt_weight = float(str_weight) while flt_weight < 0: # if not a positive num, print message and ask for input again print("Sorry, input must be a positive number, try again.") # recursion return take_weight() # if it's a positive number, we can return the weight. return flt_weight # this produces a ValueError if user enters something that can't be converted to a float. except ValueError: print("") print("Sorry, that's not a valid answer. Try again.") # recursion to prompt user to enter a valid number. return take_weight()
def check_large_envelope(item): print("") print('Is your envelope smaller than a LARGE-SIZED envelope? 🗂') print('(A large-sized envelope is defined as 15" x 11.5".)') size = exitable_input('Please enter "yes" or "no": ') # this runs if it's small enough to be delivered as a large-envelope letter. if size.lower() == "yes": # set item type to 'large' item['type'] = "large" print("") print( 'Great! It looks like you can mail your letter as a LARGE SIZED ENVELOPE. 😀️' ) # this runs if it's too large to be delivered as a letter, and must be delivered as parcel. elif size.lower() == "no": # set item type to 'parcel' item['type'] = "parcel" print("") print('Sorry, your package is too large to be mailed as a letter. 😭') print( 'Please take it to your local USPS store and have it delivered as a parcel. 📦' ) # catches input errors elif not size.lower() == "yes" and not size.lower() == "no": print("") print("Sorry, that's not a valid answer. Try again.") return check_large_envelope(item)
def get_envelope_type(item): print("") print( "Is your envelope a STANDARD rectangle shape, or an IRREGULAR shape (for example, a square)?" ) envelope_type = exitable_input('Please enter "standard" or "irregular": ') if envelope_type.lower() == 'standard': # check if the regular rectangle envelope contains items. Regular envelopes containing items have a surcharge. items = has_items() # this code runs if the envelope contains items. We set the item type to 'irregular'. if items: item['type'] = 'irregular' print("") print("Alright! You can mail your letter as an IRREGULAR item. 😀") # otherwise, this code runs if there are no items and sets the item type as 'standard'. elif not items: item['type'] = 'standard' print("") print("Good news! You can mail your letter as a STANDARD item. 😀") elif envelope_type.lower() == 'irregular': # this sets item type as 'irregular'. item['type'] = 'irregular' print("") print("Good news! You can mail your letter as a IRREGULAR item. 😀") # catches input errors elif not envelope_type.lower() == "standard" and not envelope_type.lower( ) == "irregular": print("") print("Sorry, that's not a valid answer. Try again.") return get_envelope_type(item)
def check_postcard(item): # create key 'type' for item and set it to an empty string item['type'] = "" print("") print('Is your item a POSTCARD? 🗺') print('(Postcards cannot be more than 6" in length and 4.25" in width.)') size = exitable_input('Please enter "yes" or "no": ') # this runs if the item is a postcard. Print the cost, what kinds of stamps to use, and where to purchase stamps if size.lower() == "yes": # update item type to postcard item['type'] = "postcard" print("") print("The cost of mailing a postcard is $" + str(POSTCARD) + ".") print("You can use 1 POSTCARD STAMP to mail this item.") exitable_input( "Don't have stamps? Support USPS by buying stamps here: " "https://store.usps.com/store/results/stamps/postcard/_/N-9y93lvZ17vjvm6 (Hit enter to continue)" ) # catches input errors elif not size.lower() == "yes" and not size.lower() == "no": print("") print("Sorry, that's not a valid answer. Try again.") return check_postcard(item)
def has_items(): print("") print( "Does your item contain items such as pens, pencils, or keys that make it IRREGULARLY SHAPED? 🖋" ) answer = exitable_input('Please enter "yes" or "no": ') if answer.lower() == "yes": return True elif answer.lower() == "no": return False elif not answer.lower() == "yes" and not answer.lower() == "no": print("") # catches input errors print("Sorry, that's not a valid answer. Try again.") return has_items()
def check_standard_envelope(item): print("") print( 'Is your envelope the same size/smaller than a regular, standard-sized envelope? 📨️' ) print('(A regular, standard-sized envelope is defined as 11.5" x 6.125".)') size = exitable_input('Please enter "yes" or "no": ') # this runs if it's a regular sized envelope if size.lower() == "yes": # will set item type to "rectangle" or "irregular" get_envelope_type(item) # catches input errors elif not size.lower() == "yes" and not size.lower() == "no": print("") print("Sorry, that's not a valid answer. Try again.") return check_standard_envelope(item)