Jeannette is getting married, and is getting ready to print out the envelopes fo
ID: 3903961 • Letter: J
Question
Jeannette is getting married, and is getting ready to print out the envelopes for her wedding invitations. She has decided that it would be more elegant to display each house address in full text, rather than using numerical house numbers. For example, if the recipients address is 13 Main Street, she would like the address to be printed as Thirteen Main Street.
Jeanette has asked you to a Python program which converts an address number to it’s textual representation. She will then be able to incorporate your program into her process for printing envelopes. You program is to do the following:
* prompt the user for the house numeral, to be stored as a string
* prompt the user for the street name
* convert the house number to it’s textual equivalent
Hint: first check if the length of the number. If it is one, you know that the number is between 1 and 9, otherwise you will need to examine both
digits to determine the output
* print out the full street address
Explanation / Answer
Screenshot
---------------------------------
Program
#function to convert numeral to textual
def number(sNumber):
#dictionary to extract textual value from 1 t0 19
lessThanTwenty= {1: 'One', 2: 'Two', 3: 'Three', 4: 'Four', 5: 'Five',6: 'Six', 7: 'Seven', 8: 'Eight', 9: 'Nine', 10: 'Ten',11: 'Eleven', 12: 'Twelve', 13: 'Thirteen', 14: 'Fourteen',15: 'Fifteen', 16: 'Sixteen', 17: 'Seventeen', 18: 'Eighteen', 19: 'Nineteen'}
#list to display greater than 19 to add prefix
greaterThanTwenty = ['Twenty', 'Thirty', 'Forty', 'Fifty', 'Sixty', 'Seventy', 'Eighty', 'Ninety']
#conditions to check numer range
if 1 <= sNumber < 19:
return(lessThanTwenty[sNumber])
#if number greater than 19 then use division to split quotient and remainder
elif 20 <= sNumber <= 99:
tens, below_ten = divmod(sNumber, 10)
return (greaterThanTwenty[tens - 2] + ' ' + lessThanTwenty[below_ten])
else:
print("Number out of range")
#main program
def main():
#user prompt to enter street name and address
sNumber=input("Please enter house numeral:")
sAddress=input("Please enter street name:")
#call function to get textual form
text=number(int(sNumber))
#print the complete adress
print("Complete address:"+text+" "+sAddress)
if __name__== "__main__":
main()
-------------------------------------------------
Output
Please enter house numeral:13
Please enter street name:Main Street
Complete address:Thirteen Main Street
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.