You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: basics/conditionals.py
-8Lines changed: 0 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,8 @@
1
1
"""----------Conditionals with Python---------
2
2
3
3
# What are conditionals?
4
-
5
4
# Conditionals in Python are statements that allow a program to make decisions and execute different blocks of code based on whether a specified condition is True or False.
6
5
# They are fundamental for controlling the flow of a program and enabling it to respond dynamically to various inputs or situations.
7
-
8
-
# Conditionals:
9
-
10
6
# if
11
7
# elif
12
8
# else
@@ -32,7 +28,6 @@
32
28
print("You are allowed to vote")
33
29
else:
34
30
print("Please come back when you are 18 or over")
35
-
36
31
"""
37
32
---------------------------
38
33
elif : if else
@@ -70,7 +65,6 @@
70
65
print(f"You have Access {m}") # We will print you have Access Mary
71
66
else:
72
67
print("Access Denied") # If none of the names match the names shown above we will then print out Access Denied
73
-
74
68
"""
75
69
---------------------------
76
70
Example using Boolean
@@ -82,14 +76,12 @@
82
76
print(True)
83
77
eliflight_on=="off": # if the user types "off" meaning the light is off we will print the Bool False
84
78
print(False)
85
-
86
79
"""
87
80
---------------------------
88
81
Nested if statement Example
89
82
---------------------------
90
83
Nested if statements are Conditional statements can be nested within other conditional statements to handle more complex logic
91
84
"""
92
-
93
85
age=25# This is the age that we gave ourself or it can be the age of the user
94
86
has_license=True# The user has a license therefore we put the Bool True. If the user has no license we can change this to the Bool False
95
87
ifage>=18: # If the user age is greater than or equals to 18
0 commit comments