#! /usr/bin/python3
# ===================================================================
# Convert Temperatures
# ===================================================================
import sys
import random
import user_interface as ui
# ---- display the game description
def game_description():
ui.clear_screen()
print('---------------- Convert Temperatures ----------------')
print(f'Convert Celsius to Fahrenheit or Fahrenheit to Celsius.')
print('The user enters a temperature (integer). The then')
print('select conversion to Celsius or Fahrenheit.The')
print('program then displays the converted value. Enter')
print('nothing at a prompt will exit the program. The')
print('calculated results is a rounded integer.')
# ---- play the game
game_description()
while(True):
# ---- ask the user for a temperature
while(True):
print()
s = ui.get_user_input('Enter a temperature: ')
if not s: # empty string?
print()
sys.exit()
x,temp1 = ui.is_int(s) # user's input an integer?
if x:
break
print()
print('input was not an integer, try again')
# ---- ask the user for a conversion
while(True):
print()
s = ui.get_user_input('Convert to [Cc] or [Ff]: ')
if not s: # empty string?
print()
sys.exit()
if s[0] == 'F' or s[0] == 'f':
conv = 'f'
break
if s[0] == 'C' or s[0] == 'c':
conv = 'c'
break
print()
print(f'Illegal conversion ({s}) entered - try again')
print()
if conv == 'f':
print('Convert to Fahrenheit')
temp2 = round(((9/5) * temp1) + 32)
else:
print('Convert to Celsius')
temp2 = round((5/9)*(temp1 - 32))
print()
print(f' {temp1} --> {temp2}')