+ 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?

12th Feb 2021, 3:55 AM
Grace
Grace - avatar
7 odpowiedzi
+ 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/
12th Feb 2021, 4:20 AM
Simba
Simba - avatar
+ 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.
12th Feb 2021, 4:38 AM
David Ashton
David Ashton - avatar
+ 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.
12th Feb 2021, 4:04 AM
Ipang
+ 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}")
19th Feb 2021, 4:12 PM
George_Vrettos
George_Vrettos - avatar
+ 1
Hello
22nd Feb 2021, 11:05 PM
Mary Alex Alex
0
Hi
24th Feb 2021, 12:49 AM
Mary Alex Alex