Please help problems, in Python. Submit a screenshot showing the solved problem,
ID: 3878766 • Letter: P
Question
Please help problems, in Python. Submit a screenshot showing the solved problem, for each of the below.
Thank you!
1. We've seen that n = 42 is legal. What about 42 = n? • How about x = y = 1?
2. In some languages every statement ends with a semi-colon. What happens if you put a semi-colon at the end of a Python statement? What if you put a period at the end of a Python statement?
3. In math notation you can multiply x and y like this: xy. What happens if you try that in Python?
using the Python interpreter as a calculator:
4. Suppose the cover price of a book is $24.95, but bookstores get a 40% discount. Shipping costs $3 for the first copy and 75 cents for each additional copy. What is the total wholesale cost for 60 copies?
5. If I leave my house at 6:52 am and run 1 mile at an easy pace (8:15 per mile), then 3 miles at tempo (7:12 per mile) and 1 mile at easy pace again, what time do I get home for breakfast?
Explanation / Answer
Hi,
Ans 1- 42=n is illegal as we cannot assign a variable to a constant. We can assign a constant value to variable though.
x=y=1 is legal and it is allowed in python. This will assign value 1 to both x and y
Ans 2- Python code will throw an error if we put a semi colon at the end of the line. This is because python does not support semi-column and it is not a part of python syntax. We can just write the code without worrying about the semicolon.
For Period, it depends on the type of statement in which period is added. If we add period at the end of the assignment statement, it will work. Ex- y = 1.
For all the other statement types, we must not use periods otherwise python code will throw error.
Ans 3- Python will not be able to interpret "xy" as it will consider it as sigle variable and if xy is not defined in the program it will throw an error. If we write "x*y", the python code will undertstand and gives the multiplied result.
Ans 4-
24.95*60+3+((75*59)/100)-((0.40*24.95)*60)
Ans 5-
(8*60+15 + (7*60+12)*3 + 8*60+15 )/60 = 38.1 minutes
This time wil be added to the actual start time
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.