Skip to content

Commit 8608d48

Browse files
committed
Initial Commint
1 parent ce5fe31 commit 8608d48

File tree

8 files changed

+221
-0
lines changed

8 files changed

+221
-0
lines changed

src/22_Aug_Loops/1 for Loops.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Loops - To repeat a block of code multiple times
2+
3+
# Python has 2 loops
4+
# for loop
5+
# While loop
6+
7+
# No Do while loop in case of Python
8+
9+
# keywords
10+
# break
11+
# Continue
12+
13+
# Print hello word 10 time
14+
15+
# for loop
16+
# Syntax: Structure
17+
# for variable name in the range of (Start, Stop, Step):
18+
19+
# Range (Start, Stop, Step)
20+
# Range (0, 10. 1)
21+
# Range (0, 10)
22+
# Range ( 10 ) # by default start will be taken as 0
23+
# by default it will take difference between start no. and next no. is 1
24+
25+
# Range is in-built class and function and Utility.
26+
27+
for i in range(1,10): # output = 1 to 9 # i = variable name
28+
print (i) # why new line = by default end of the line is end="\n"
29+
30+
print("\n")
31+
32+
for j in range(3, 5): # output = 3 and 4
33+
print(j)
34+
35+
print("\n")
36+
37+
for l in range(1, 10, 2): # output = 1, 3, 5, 7, 9 0
38+
print(l)
39+
40+
print("\n")
41+
42+
for i in range(1, 11): # output = hello -> 1 to 10
43+
print("hello ->", i)
44+
45+
print("\n")
46+
47+
for number in range(10, 0, -2): # output = 10, 8, 6, 4, 2
48+
print(number)
49+
50+
print("\n")
51+
52+
for test in range(0, 10, -2): # output = nothing will be going to print
53+
print(test)
54+
55+
print("\n")
56+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#break - based on the condition, exit the loop
2+
3+
for i in range(0, 10): # output = 0 1 2 3 4 5
4+
if i == 5:
5+
break
6+
print(i)
7+
# Logic |i| |Condition| O/P
8+
# |0| 0 == 5 --> False | O/P = 0
9+
# |1| 1 == 5 --> False | O/P = 1
10+
# |2| 2 == 5 --> False | O/P = 2
11+
# |3| 3 == 5 --> False | O/P = 3
12+
# |4| 4 == 5 --> False | O/P = 4
13+
# |5| 5 == 5 --> True -> break | O/P = 0
14+
15+
print("\n")
16+
17+
for i in range(0, 10, 1):
18+
if i == 6:
19+
print(i)
20+
else:
21+
print("No O/P")
22+
23+
# |0| 0 == 6 --> False | O/P = No O/P
24+
# |1| 1 == 6 --> False | O/P = No O/P
25+
# |2| 2 == 6 --> False | O/P = No O/P
26+
# |3| 3 == 6 --> False | O/P = No O/P
27+
# |4| 4 == 6 --> False | O/P = No O/P
28+
# |5| 5 == 6 --> False | O/P = No O/P
29+
# |6| 6 == 6 --> True | O/P = 6
30+
# |7| 7 == 6 --> False | O/P = No O/P
31+
# |8| 8 == 6 --> False | O/P = No O/P
32+
# |9| 9 == 6 --> False | O/P = No O/P
33+
34+
print("\n")
35+
36+
# Pass Condition = Nothing, Ignore, Go Above dont do anything.
37+
38+
for k in range(0, 10, 1):
39+
if k == 6 or k == 5:
40+
print(k)
41+
else:
42+
pass
43+
44+
print("\n")
45+
46+
for i in range(0, 10, 1):
47+
if i == 6:
48+
print(i)
49+
else:
50+
pass # Pass its used to "Pass"

src/22_Aug_Loops/2 While Loop.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# While loop
2+
3+
# Syntax:
4+
5+
#variable_name = 0
6+
#while condition:
7+
#execute this code
8+
#variable_name increment
9+
10+
i = 0
11+
while i < 10:
12+
print(i, end = "") # output = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
13+
i = i + 1
14+
15+
# logic
16+
# i = 10 , 10 < 10 -> Out of the loop
17+
18+
#we don't have increment operator i++ or i-- in case of python
19+

src/22_Aug_Loops/4 Example.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
for i in range(0, 10): # Output = 0 2 4 6 8
2+
if i % 2 == 0:
3+
print(i, end=" ")
4+
else:
5+
pass
6+
7+
# Logic
8+
9+
# |i| |Condition| O/P
10+
# |0| 0 % 2 --> True | O/P = 0
11+
# |1| 1 % 2 --> False | O/P = No Output
12+
# |2| 2 % 2 --> False | O/P = 1
13+
# |3| 3 % 2 --> False | O/P = No Output
14+
# |4| 4 % 2 --> False | O/P = 2
15+
# |5| 5 % 2 --> False | O/P = No Output
16+
# |6| 6 % 2 --> False | O/P = 3
17+
# |7| 7 % 2 --> False | O/P = No Output
18+
# |8| 8 % 2 --> False | O/P = 4
19+
# |9| 9 % 2 --> False | O/P = No Output
20+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Continue Statement
2+
# Continue Statement skips the current iteration of loop and
3+
# Move to the next iteration.
4+
from idlelib.sidebar import EndLineDelegator
5+
6+
for number in range(10):
7+
if number % 2 == 0:
8+
continue
9+
print(number)
10+
11+
# Logic
12+
13+
# |i| |Condition| O/P
14+
# |0| 0 % 2 == 0--> True | Continue O/P = Skip No O/P
15+
# |1| 1 % 2 == 0--> False | O/P = 1
16+
# |2| 2 % 2 == 0--> True | Continue O/P = Skip No O/P
17+
# |3| 3 % 2 == 0--> False | O/P = 1
18+
# |4| 4 % 2 == 0--> True | Continue O/P = Skip No O/P
19+
# |5| 5 % 2 == 0--> False | O/P = 1
20+
# |6| 6 % 2 == 0--> True | Continue O/P = Skip No O/P
21+
# |7| 7 % 2 == 0--> False | O/P = 1
22+
# |8| 8 % 2 == 0--> True | Continue O/P = Skip No O/P
23+
# |9| 9 % 2 == 0--> False | O/P = 1
24+
25+
# Pass - Can be used in the statement, functions , class and Objects
26+
27+
print("\n")
28+
29+
for number in range(10):
30+
if number % 2 == 0:
31+
continue
32+
else:
33+
print(number)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Match Statement
2+
# Switch in JAVA
3+
# Match the O/P and Execute
4+
# This concept will work Version > 3.10
5+
6+
7+
# Syntax:
8+
# Match Variable:
9+
# case pattern1:
10+
#code block
11+
# case pattern2:
12+
#code block
13+
# case _: # _ is the default if no other case matches
14+
#code block
15+
16+
17+
# Write a program to ask the user which browser he want to run automation
18+
browser_name = input("Enter the name of the browser \n")
19+
browser_name = browser_name.lower()
20+
match browser_name:
21+
case "firefox":
22+
print("Execute the firefox Code")
23+
case "chrome":
24+
print("Execute the chrome Code")
25+
case "edge":
26+
print("Execute the edge Code")
27+
case "safari":
28+
print("Execute the safari Code")
29+
case _:
30+
print("Browser not found")
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
user_type = input("Enter the user type, admin, manager, guest\n")
2+
user_type = user_type.lower()
3+
match user_type:
4+
case "admin" | "manager":
5+
print("Hello Sir")
6+
case "guest":
7+
print("Hello, guest")
8+
case _:
9+
print("Hello, There!")
10+

src/Ex01092024/Lab008.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@
1919
print(f"Can go club -> {age}")
2020
else:
2121
print(f"Cant go with this age -> {age}")
22+
23+
24+

0 commit comments

Comments
 (0)