Python programming: The ultimate guide to learn Python language fundamentals, tips, tricks, exercises in a simple crash course by Lutz Reilly

Python programming: The ultimate guide to learn Python language fundamentals, tips, tricks, exercises in a simple crash course by Lutz Reilly

Author:Lutz, Reilly [Lutz, Reilly]
Language: eng
Format: epub
Published: 2019-08-24T16:00:00+00:00


The code below uses a conditional if/elif/else statement to transform a numeric date in month/

day format to an expanded US English form and an international Spanish form; for example, 2/14 would be converted to ‘February 14’ (US English) and ‘14 febrero’ (Spanish).

Listing 4.19: datetransformer.py

month = int(input("Please enter the month as a number (1-12): "))

day = int(input("Please enter the day of the month: "))

# Translate month into English

if month == 1:

print("January ", end='')

elif month == 2:

print("February ", end='')

elif month == 3:

print("March ", end='')

elif month == 4:

print("April ", end='')

elif month == 5:

print("May ", end='')

elif month == 6:

print("June ", end='')

elif month == 7:

print("July ", end='')

elif month == 8:

print("August ", end='')

elif month == 9:

print("September ", end='')

elif month == 10:

print("October ", end='')

elif month == 11:

print("November ", end='')

else:

print("December ", end='')

# Add the day

print(day, 'or', day, end='')

# Translate month into Spanish

if month == 1:

print(" de enero")

elif month == 2:

print(" de febrero")

elif month == 3:

print(" de marzo")

elif month == 4:

print(" de abril")

elif month == 5:

print(" de mayo")

elif month == 6:

print(" de junio")

elif month == 7:

print(" de julio")

elif month == 8:

print(" de agosto")

elif month == 9:

print(" de septiembre")

elif month == 10:

print(" de octubre")

elif month == 11:

print(" de noviembre")

else:

print(" de diciembre")



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.