module_2_lab_3 python 3rd lab

preview_player
Показать описание
LAB
Estimated time
10 minutes
Level of difficulty
Easy
Objectives
• becoming familiar with the concept of storing and working with different data types in Python;
• experimenting with Python code.
Scenario
Here is a short story:
Once upon a time in Appleland, John had three apples, Mary had five apples, and Adam had six apples. They were all very happy and lived for a long time. End of story.
Your task is to:
• create the variables: john, mary, and adam;
• assign values to the variables. The values must be equal to the numbers of fruit possessed by John, Mary, and Adam respectively;
• having stored the numbers in the variables, print the variables on one line, and separate each of them with a comma;
• now create a new variable named totalApples equal to addition of the three former variables.
• print the value stored in totalApples to the console;
experiment with your code: create new variables, assign different values to them, and perform various arithmetic operations on them (e.g., +, -, *, /, //, etc.). Try to print a string and an integer together on one line, e.g., "Total number of apples:" and totalApples

john=3
mary=5
adam=6
print(john,",", mary,",", adam)
totalApples =john+mary+adam
print(totalApples)

LAB
Estimated time
10 minutes
Level of difficulty
Easy
Objectives
• becoming familiar with the concept of, and working with, variables;
• performing basic computations and conversions;
• experimenting with Python code.
Scenario
Miles and kilometers are units of length or distance.
Bearing in mind that 1 mile is equal to approximately 1.61 kilometers, complete the program in the editor so that it converts:
• miles to kilometers;
• kilometers to miles.
kilometers = 12.25
miles = 7.38
miles_to_kilometers = ###
kilometers_to_miles = ###
print(miles, "miles is", round(miles_to_kilometers, 2), "kilometers")
print(kilometers, "kilometers is", round(kilometers_to_miles, 2), "miles")

Do not change anything in the existing code. Write your code in the places indicated by ###. Test your program with the data we've provided in the source code.

kilometers = 12.25
miles = 7.38
miles_to_kilometers = miles*1.61
kilometers_to_miles = kilometers * (1/1.61)
print(miles, "miles is", round(miles_to_kilometers, 2), "kilometers")
print(miles, "miles is", (miles_to_kilometers), "kilometers")

print(kilometers, "kilometers is", round(kilometers_to_miles, 2), "miles")
print(kilometers, "kilometers is", (kilometers_to_miles), "miles")
Рекомендации по теме
join shbcf.ru