-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeek 2 Activities.py
101 lines (63 loc) · 2.17 KB
/
Week 2 Activities.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 5 18:54:44 2018
@author: dstro
"""
#%%
"""ACTIVITY 1
Write a program that displays these numbers in a column
with decimal points aligned """
num1 = 127.899
num2 = 3465.148
num3 = 3.776
num4 = 264.821
num5 = 88.081
num6 = 799.999
print('The number is' , format(num1, '8,.2f'))
print('The number is' , format(num2, '8,.2f'))
print('The number is' , format(num3, '8,.2f'))
print('The number is' , format(num4, '8,.2f'))
print('The number is' , format(num5, '8,.2f'))
print('The number is' , format(num6, '8,.2f'))
#%%
"""ACTIVITY 2
Write a program that asks the user for number of miles driven and gallons used
Calculate the MPG and display the result.
"""
miles_driven = float(input('Enter Miles driven: '))
gas_used = float(input('How many Gallons of gas did you use?:\n '))
mpg = miles_driven // gas_used
print('Your MPG is' , format(mpg, '8,.2f'))
1
#%%
"""Activity 3
Write a program that calculates the total cost of meal at a resturant. Ask the user for input
on the cost of the meal. Calculate the tip and the tax. Print out the
tax, tip, and the total. You can ask the user for tax and tip or you can use
hard coded numbers.
"""
#%%
initial_cost = float(input('Enter the initial cost for your meal: '))
tip = initial_cost * 0.20
tax = initial_cost * 0.06
total_cost = initial_cost + tip + tax
print('Your tip due is ' , format(tip, '13,.2f'))
print('Your tax due is ' , format(tax, '13,.2f'))
print('Your total cost due is ' , format(total_cost, '2,.2f'))
#%%
"""
ACTIVITY
Create a function to solve this problem.
A car is traveling down down the interstate.
Ask the user for the speed of the car.
Using D = S * T,
calculate and give an output of the distance the car will travel in 5,
8, and 12 hours.
The output should look like:
The distance the car will travel in 5 hours is...
"""
#%%
speed = float(input('WHAT IS YOUR SPEED(MPH)? '))
time = float(input('How long have you been driving(hours)? '))
distance = speed * time
print('Your distance travelled is ' , format(distance, '2,.2f'), 'miles.')