Arquivo calculator.py:
def prepare_input():
print('-- Tip Calculator --\n')
value_to_pay = input('Enter the bill amount: ')
tip_value = input('Enter the tip percentage: ')
items = [value_to_pay, tip_value]
for i, item in enumerate(items):
if ',' in item:
items[i] = float(item.replace(',','.'))
else:
items[i] = float(item)
return items
def calc_tip():
values = prepare_input()
value_to_pay, tip_value = values
tip = round(value_to_pay * (tip_value / 100), 2)
total_bill = value_to_pay + tip
return total_bill, tip
Arquivo main.py:
from calculating_tip import calculator
start = True
while start:
try:
result = calculator.calc_tip()
print(f'''
Tip amount: $ {result[1]:.2f}
Total: $ {result[0]:.2f}''')
except:
print("Error: Try again. Enter only numbers")
start = input("\nPress Enter to reload or any key to exit \n")
start = True if start == "" else start == False
Ambos estão num diretório: calculating_tip