+ 1
How to calculate a tip?
Hello, I am new and getting a little confused with Python. I was asked to find a tip, and I did find it but I don't think it was the most efficient way to do it. Got any pointers I could use?
7 Answers
+ 8
Your solution needs to get input from the user.
We have to use int() function to declare an integer as an input like this
X = int(input)
print(X)
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/4434/
+ 5
The shortest way to write this is
print(50 * .2)
If you want the user to supply the amount and the percent, you could do something like
bill = float(input("Enter bill amount."))
percent = float(input("Enter tip percent."))
print("Tip =", bill * percent / 100)
In SoloLearn, the user will have to enter the bill amount and tip percentage on separate lines of a single input.
Using float() instead of int() allows the user to enter decimals, not just whole numbers.
+ 2
Share your code link for a review https://www.sololearn.com/post/75089/?ref=app
Without a code to look at, it's hard to tell about efficiency.
+ 1
bill = float(input("Enter your bill:"))
tip = float(input("Enter your tip %: "))
tip_amount = bill * 20 / 100
print(f"Your bill was {bill} and your tip will be {tip_amount}")
+ 1
Hello
0
Hi