Lab 1

Lab description: In this lab we used Python to assign values to certain aspects of our dinner cost such as the meal,tip and tax. The cost of the meal was $44.50. The tip that we gave for the service was 15%. Finally the tax for the meal was 6.75%. After being given all these values, I had to assign them to a variable. The variables were “meal”,”tip” and “tax”. Assigning the first variable “meal” was simple because all I had to do was input the value 44.50. The next two were more complicated because they were percentages and we wanted to multiply with floats. In order to change them we had to take the value and divide it by 100. For example the tip for the service was 15%, so I had to take 15 and divide it by 100 which gave me 0.15. After I got that value I simply set the variable “tip” to equal 0.15. The same process was done for the tax. The tax was 6.75%, so I took 6.75 and divided by 100. This equated to 0.0675. Just like with the tip I took the value of 0.0675 and made it equal the variable “tax”. After all the values were assigned I was then able to take the variable “meal” and reassign the value that it was equated to. I took the initial variable “meal”, and I made it equal to meal + meal * tip. These are some of the operations that I learned how to complete by doing this exercise. I learned how to convert percentages to floats so that the program can handle them as well as learning how to reassign values that had a value assigned to them  previously.

source code: 

1 # Assign the variable total on line 8!
2
3 meal = 44.50
4 tax = 0.0675
5 tip = 0.15
6
7 meal = meal + meal * tax
8 total = meal + meal * tip
9
10 print(“%.2f” % total)

Screen shots:

Script
Script

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *