Lesson 18 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

Lesson 18

I am really stuck at lesson 18, PLS HELP!!

14th Feb 2022, 9:11 PM
Me’Lan Thomas
7 Answers
+ 2
Hi, can you post the code you tried or the question?
14th Feb 2022, 9:26 PM
Ferdaws Kukcha
Ferdaws Kukcha - avatar
+ 1
bill_amount = int(input()) tip = bill_amount * 20 / 100 Print(tip) The input function outputs always a string even if you type a number, thats why i used int() to convert string into an integer. The variable tip calculates 20% of the input and the result will be a float because we used this “/“
14th Feb 2022, 10:08 PM
Ferdaws Kukcha
Ferdaws Kukcha - avatar
0
Ferdaws Kukcha When you go out to eat, you always tip 20% of the bill amount. But who’s got the time to calculate the right tip amount every time? Not you that’s for sure! You’re making a program to calculate tips and save some time. Your program needs to take the bill amount as input and output the tip as a float. Sample Input 50 Sample Output 10.0
14th Feb 2022, 10:02 PM
Me’Lan Thomas
0
Thank you so much!! I think I added some code lol but i tried so many diff ways
14th Feb 2022, 10:10 PM
Me’Lan Thomas
0
This was the last code i tried bill = 1 bill = bill + 25 tip = int(bill) *20/100
14th Feb 2022, 10:11 PM
Me’Lan Thomas
0
You are welcome ! We learn programming languages when we play around with the code. If you have any questions about my solution pls ask.
14th Feb 2022, 10:12 PM
Ferdaws Kukcha
Ferdaws Kukcha - avatar
0
bill = 1 means you assign the value 1 to the variable bill ( the value of bill is from now on 1) Then you say bill = bill + 25 ( remember till now bill had the value 1 and now bill = 1 + 25 which is 26 and from now on bill has the value 26) Then you say tip = 26 * 20 / 100 But the question was that you take any number as input thats why you have to use the input function.
14th Feb 2022, 10:17 PM
Ferdaws Kukcha
Ferdaws Kukcha - avatar