-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrol_flow.py
More file actions
71 lines (48 loc) · 1.71 KB
/
control_flow.py
File metadata and controls
71 lines (48 loc) · 1.71 KB
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
# What is control flow?
# conditional statements and loops
# if, elif, else, for loop, while loop
weather = "sunny"
if weather == "sunny":
print(" Lets go to the beach")
weather = "snow"
conditional_weather = "rainy"
# conditional block of code
if weather == "sunny" and conditional_weather == "rainy": # For this both conditions must be TRUE
print(" Lets go to the beach!")
else:
print(" Sorry better luck next time")
# We use AND when both conditions must be true
# Using OR operator
# We use OR when one of the conditions must be true
if weather == "sunny" or conditional_weather == "rainy": # For this both conditions must be TRUE
print(" Lets go to the beach!")
else:
print(" Sorry better luck next time")
if age == 18 or age > 18: # For this both conditions must be TRUE
print(" Please proceed to checkout")
else:
print(" SSorry you are to young to watch the movie")
# To simplify the code we can use just one operator as seen below:
age = 18
if age >= 18:
print(" Please proceed to checkout")
else:
print(" SSorry you are to young to watch the movie")
# What are sets - sets are very similar to Lists
# What is the difference between a set and a list? - sets are unordered
# Syntax for sets: We us {} brackets
# Lets create a set!
car_part = {"Wheels", "Windows", "Doors"}
print(car_part)
# What can we do with sets
# Add an item to the set
car_part.add("Seats") # Seats will be added into the 0 Index
print(car_part)
car_part.discard("Windows") # Used to remove an item from the set
print(car_part)
#Frozen set - it is immutable
#Syntax - We use () store them in a variable first
counting = frozenset([1, 2, 3, 4])
print(counting)
name = "daniel"
print("Hello {} how are you".format(name))