Nathan Carnahan
Nathan Carnahan

Reputation: 21

Rounding function issue

I am learning Python currently and working on writing a little program given as a task from the book I am working through. I am working with the round() function and for the most part it is working. One line isn't though and I can't for the life of me figure it out. Any help is appreciated. The portion that isn't working is:

billtip1 = bill + tip1
round(billtip1, 2)

Towards the end of this section of code:

bill = input("\nEnter in the bill total: $ ")
bill = float(bill)

tip1 = bill * .15
tip2 = bill * .20

tip1 = round(tip1, 2)
tip2 = round(tip2, 2)

print("\nA 15% tip would be: ", tip1)
print("\nA 20% tip would be: ", tip2)

billtip1 = bill + tip1
round(billtip1, 2)

billtip2 = bill + tip2
round(billtip2, 2)

print("\nTotal bill with 15% tip:$ ", billtip1)
print("\nTotal bill with 20% tip:$ ", billtip2)

Upvotes: 2

Views: 52

Answers (2)

Paradox
Paradox

Reputation: 4566

The round builtin function returns a value. Therefore, you have to assign the result to a variable.

For example, variable = round(number[, ndigits])

In your case:

billtip1 = round(bill + tip1, 2)
billtip2 = round(bill + tip2, 2)

To view more about round, see here

Upvotes: 3

Kevin
Kevin

Reputation: 76194

round doesn't do anything unless you assign the result to something. Try:

billtip1 = bill + tip1
billtip1 = round(billtip1, 2)

billtip2 = bill + tip2
billtip2 = round(billtip2, 2)

Upvotes: 1

Related Questions