solution_012.py

#! /usr/bin/python3
# ===================================================================
# Age on Another Planet
# ===================================================================

import user_interface as ui

# ---- display the game description

def program_description():
    ui.clear_screen()
    print('------------- Age on Another Planet ------------')
    print('Given your age (in years) on the Earth, How old')
    print('are you in other planet\'s years.')

# -------------------------------------------------------------------
# ---- main
# -------------------------------------------------------------------

program_description()

while(True):

    # ---- ask the user for year

    print()
    s = ui.get_user_input('Enter your age in earth years: ')

    # ---- empty string?

    if not s:
        break

    # ---- verify input

    x,n = ui.is_int(s)

    if not x:
        print()
        print(f'Illegal value entered - try again')
        continue

    if n < 1:
        print()
        print(f'Illegal value entered - try again')
        continue

    if n > 130:
        print()
        print(f'No one lives that long - try again')
        continue

    # ---- calculate ages

    print()
    
    # ---- Mercury

    a = int((n * 365.26) // 87.97)

    print(f'Age on Mercury  {a}')

    # ---- Venus

    a = int((n * 365.26) // 224.7)

    print(f'Age on Venus    {a}')

    # ---- Mars

    a = n / 1.88

    print(f'Age on Mars     {a:<10.3}')

    # ---- Jupiter

    a = n / 11.86

    print(f'Age on Jupiter  {a:<10.3}')

    # ---- Saturn

    a = n / 29.46

    print(f'Age on Saturn   {a:<10.3}')

    # ---- Uranus

    a = n / 80.01

    print(f'Age on Uranus   {a:<10.3}')

    # ---- Neptune

    a = n / 164.79

    print(f'Age on Neptune  {a:<10.3}')

    # ---- Pluto

    a = n / 248.59

    print(f'Age on Pluto    {a:<10.3}')

print()