[Tutor] Draw table and compare random input

Phaik Huen Tan ptan1 at capellauniversity.edu
Thu Jul 30 23:35:43 EDT 2020


Hi there,

I am supposed to draw a table for my random input (12 months of expenses)
and compared it against the monthly target. I am able to get input from
the user but I am not able to compare each input and display each input by
month individually. Can you please provide guidance on where I did wrong on
my code?

Thank you!
Phaik-Huen

Below is my code:

# This program calculates monthly expenses.
# Create a variable to control the loop.
keep_going = 'Y'
#Calculate monthly target for each of the 12 months using annual IT
expenses of $42500
monthly_target = 42500/12
print('Monthly target expenditure is $', format(monthly_target,'.2f'))



while keep_going == 'Y' or keep_going == 'y':
    # Initialize an accumulator for site expenditure
    total = 0
    # Get the site expenditure
    month_exp = int(input('Please enter month expenditure: '))
    if month_exp < 0:
        print('Value must be greater than 0')
        month_exp = int(input('Enter the correct site expenditure: '))
       # See if the user wants to do enter another one.
    keep_going = input('Do you want to enter another ' +
                'month expenditure (Enter Y or y for yes): ')
#Print the table headings
print()
print('Month\t|Expense\t|Over,Under or Exact')
print('-----------------------------------------------')

if month_exp >= monthly_target:
    print("Over")
elif month_exp <= monthly_target:
    print("Under")
else:
    print("Exact")


More information about the Tutor mailing list