Skip to content

Commit fdceb17

Browse files
author
irsol
committed
Updated files.
1 parent be6ea55 commit fdceb17

File tree

4 files changed

+59
-24
lines changed

4 files changed

+59
-24
lines changed

boolean_practice/boolean_exercises.py

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,67 @@
1-
#3.1. Expression that evaluates to True in both variables are True
1+
# 3.1. Expression that evaluates to True if both variables are True
22
# and that evaluates to False otherwise
3+
34
x = True
45
y = True
56
print(x and y)
67

7-
#3.2. Expression that evaluates to True if x is False and evaluates
8+
# 3.2. Expression that evaluates to True if x is False and evaluates
89
# to False otherwise
10+
911
x = False
1012
y = True
1113
print(not x)
1214

13-
#3.3. Expression that evaluates to True if at least one of the variables is True
15+
# 3.3. Expression that evaluates to True if at least one of the variables is True
1416
# and evaluates to False otherwise
17+
1518
x = True
1619
y = False
1720
print(x or y)
1821

19-
#4. Expression that evaluates to True if at most one of the variables is True
22+
# 4. Expression that evaluates to True if at most one of the variables is True
2023
# and evaluates to False otherwise
24+
2125
full = True
2226
empty = False
2327
print(not full or empty)
2428

25-
#5. True if the light level is less than 0.01 or if the temperature
29+
# 5. True if the light level is less than 0.01 or if the temperature
2630
# is above freezing, but not if both condition are true
2731

2832

2933
def automate_camera(light, temperature):
3034
return (light < 0.01) != (temperature > 0.0)
3135

36+
3237
automate_camera(0.01, -2)
3338

3439

3540
# exclusive or
41+
3642
def automate_camera(light, temperature):
3743
if (light < 0.01) != (temperature > 0.0):
3844
return True
3945
else:
4046
return False
47+
48+
4149
automate_camera(0.00, -2)
4250

43-
#6.
51+
# 6.
4452

4553

46-
#7. The function returns True if a and b refer to different values and
54+
# 7. The function returns True if a and b refer to different values and
4755
# returns False otherwise
56+
4857
def different(a, b):
4958
return a != b
5059

60+
5161
different(2, 2)
5262

5363

54-
#8. You are given two float variables, population and land_area.
64+
# 8. You are given two float variables, population and land_area.
5565
# a. Write an if statement that will print the population if it is less than
5666
# 10,000,000
5767

@@ -60,26 +70,23 @@ def different(a, b):
6070
land_area = 1222.33
6171

6272
if population < 10000000:
63-
print("{: f}".format(population))
73+
print(f"{population} million")
6474

6575

6676
# b. Write an if statement that will print the population if it is between
6777
# 10,000,000 and 35,000,000
6878

69-
population = 36.000000
79+
population = 33.000000
7080
land_area = 1222.33
7181

7282
if 10.000000 < population < 35.000000:
73-
print("{: f}".format(population))
74-
75-
else:
76-
print(None)
83+
print(f"{population} millions")
7784

7885

7986
# c. Write an if statement that will print "Densely populated" if the land
8087
# density(number of people per unit of area) is greater than 100.
8188
# d. Write an if statement that will print "Densely populated!" if the land
82-
# density print is greter than 100 and that will print "Sparsely populated"
89+
# density print is greater than 100 and that will print "Sparsely populated"
8390
# otherwise.
8491

8592
density = 90
@@ -90,19 +97,23 @@ def different(a, b):
9097
print("Sparsely populated")
9198

9299

93-
#9. Function convert_tempretures converts temperature t from source units
100+
# 9. Function convert_temperature converts temperature t from source units
94101
# to target units using. Function convert_to_celsius convert all source units
95102
# to celsius, than function convert_from_celsius converts celsius to target
96103
# units and returns result.
104+
97105
def convert_to_celsius(t, source):
98106
if source == "F":
99-
return t - 32 * 5.0/9.0
107+
return (t - 32 * 5.0/9.0).__round__(2)
100108
elif source == "K":
101-
return t - 273.15
109+
return (t - 273.15).__round__(2)
102110
elif source == 'C':
103111
return t
104112

105113

114+
convert_to_celsius(32, "K")
115+
116+
106117
def convert_from_celsius(t, target):
107118
if target == "F":
108119
return t + 32 * 9.0/5.0
@@ -112,6 +123,9 @@ def convert_from_celsius(t, target):
112123
return t
113124

114125

126+
convert_from_celsius(32, "F")
127+
128+
115129
def convert_temperatures(t, source, target):
116130
print('step 1', t, source, target)
117131
celsius = convert_to_celsius(t, source)
@@ -120,3 +134,19 @@ def convert_temperatures(t, source, target):
120134
print('step 3', result, celsius, t, source, target)
121135
return result
122136

137+
138+
# 10. If ph value is below 3.0 - very acidic, between 3 and 7 - acidic
139+
140+
user_input = input("Enter an acidity level: \n")
141+
142+
if len(user_input) > 0:
143+
ph = float(user_input)
144+
if 3.0 < ph < 7.0:
145+
print(f"{ph} is acidic.")
146+
elif ph < 3.0:
147+
print(f"{ph} is VERY acidic! Be careful!")
148+
else:
149+
print("No ph value was given!")
150+
151+
152+
# 11.
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
# For each of the expressions, what value will the expression give?
22

33

4-
1. True and not False
4+
True and not False
55
# True
66

77

8-
2. True or True and False
8+
True or True and False
99
# True
1010

1111

12-
3. not True or not False
12+
not True or not False
1313
# True
1414

1515

16-
4. True and not 0
16+
True and not 0
1717
# True
1818

1919

20-
5. 1 + 55 < 55.2
20+
1 + 55 < 55.2
2121
# False
2222

2323

24-
6. 4 != 4.0
24+
4 != 4.0
2525
# False

boolean_practice/boolean_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

boolean_practice/storing_conditionals.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ def heart_risk(age, bmi):
1515
elif not young and not slim:
1616
risk = 'high'
1717
return risk
18+
19+
1820
heart_risk(45, 15)
1921
heart_risk(42, 20)
2022
heart_risk(18, 23)
@@ -29,4 +31,6 @@ def calculate_heart_risk(age, bmi):
2931
heavy = bmi >= 22.0
3032
risk = table[young][heavy]
3133
return risk
34+
35+
3236
calculate_heart_risk(23, 32)

0 commit comments

Comments
 (0)