Question

How can I get this section of my program to round with two decimal places, like...

How can I get this section of my program to round with two decimal places, like currency i.e., instead of $4500.0 it should read $4,500.00. In Python.

Office Rent: $4500.0
Electric: $126.45
Vehicles: $986.45
Cable TV: $125.32
Telephone: $119.44
Internet: $85.55
Payroll: $8641.33
Marketing: $1000.0
Production: $3547.99
Shipping: $65.44

Here is my code: https://repl.it/repls/EarnestCumbersomePredictions

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is code:

# Programing Challeng 3 - David Smith

def totalExpense(expense):

    total = 0

    for price in expense:

        total = total + price

    return total


def averageExpense(expense):

    total = 0

    for price in expense:

        total = total + price

    avg = total / len(expense)

    return avg


def main():

    expense = []

    items = ["Office Rent:", "Electric:", "Vehicles:", "Cable TV:", "Telephone:",

             "Internet:", "Payroll:", "Marketing:", "Production:", "Shipping:"]

    print("Mountain Steelworks, Inc.")

    print("710 Alton Way")

    print("Denver, CO 80230")

    print("Phone: (303) 340-7093\n______________")

    month = input("Enter the Month of the Expenses: ")

    year = input("Enter the Year of the Expenses: ")

    for item in items:

        temp = float(input("Enter the Amount for " + item+" "))

        expense.append(temp)

        temp = 0

    i = 0

    print('\n')

    print("Expense Report \n______________")

    print("Expense Month: ", month)

    print("Expense Year: ", year)

    print('\n')

    for item in items:

        print(item, end='')

        print(" ${:,.2f}".format(expense[i], 2))

        i = i + 1

    total = totalExpense(expense)

    avg = averageExpense(expense)

    maximum = max(expense)

    minimum = min(expense)

    print("\nTotal Expense is:    ${:,.2f}".format(round(total, 2)))

    print("Average Expense is:  ${:,.2f}".format(round(avg, 2)))

    print("Lowest Expense is:   ${:,.2f}".format(round(minimum, 2)))

    print("Highest Expense is:  ${:,.2f}".format(round(maximum, 2)))


if __name__ == '__main__':

    main()

Output:

Add a comment
Know the answer?
Add Answer to:
How can I get this section of my program to round with two decimal places, like...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT