Skip to content

Commit f23bb99

Browse files
committed
Advanced Python Module
1 parent f14d0ec commit f23bb99

18 files changed

+218
-0
lines changed

advancedpython1/01_problem.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
try:
2+
with (
3+
open("1.txt") as f1,
4+
open("2.txt") as f2,
5+
open("3.txt") as f3
6+
):
7+
f1.read()
8+
f2.read()
9+
f3.read()
10+
11+
except FileNotFoundError as e:
12+
print(e)
13+
print("File Cannot be found, kindly create them")
14+
15+
finally:
16+
print("File Cannot be found, kindly create them")

advancedpython1/01_warlaus.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from typing import List, Tuple, Dict, Union
2+
3+
n: int = 5
4+
name: str = " Sarthak"
5+
6+
7+
def sum(a: int, b: int) -> int:
8+
return a + b
9+
10+
11+
print(sum(5, 6))
12+
13+
num: List[int] = [5, 10, 15, 20, 25]
14+
numb: Dict[str, int] = {"Sarthak": 152006, "Unknown": 2006}
15+
numb1: Dict[str, str] = {"Sarthak": "Patil", "Unknown": "2006"}
16+
numbe: Tuple[str, int] = ("Sarthak", 15)
17+
numbe1: Tuple[str, bool] = ("Sarthak", True)
18+
19+
print(num)
20+
print(numb)
21+
print(numb1)
22+
print(numbe)
23+
print(numbe1)
24+

advancedpython1/02_matchCase.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def httpStatus(t):
2+
match t:
3+
case 200: return "Ok"
4+
case 404: return "Not Found"
5+
case 500: return "Internal Server Error"
6+
case _: return "Unknown Status"
7+
8+
9+
print(httpStatus(400))
10+
print(httpStatus(500))
11+
print(httpStatus(404))
12+
print(httpStatus(200))
13+
print(httpStatus(254))

advancedpython1/02_problem.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ls = [3, 44, 53, 43, 43, 43, 43, 433]
2+
3+
for index, item in enumerate(ls):
4+
if index == 3 - 1 or index == 5 - 1 or index == 7 - 1:
5+
print(f"Element at index {index} is {item}")

advancedpython1/03_dictionary.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
x = {"Sarthak": 5000000, "Ramlal": 32000}
2+
y = {"Ramlal": 5000000, "Oggy": 3200}
3+
4+
z = x | y
5+
# union of both dictionaries meanwhile secondictionary is taken as update if key matches but value doesnt
6+
7+
print(z)
8+
9+
10+
with (
11+
open("maxVerstappen.txt", "w") as f1,
12+
open("charlesLeclerc.txt", "w") as f16
13+
):
14+
f1.write("Here Goes the Max Verstappen\n")
15+
f1.write("Max Emilian Verstappen is a Dutch and Belgian racing driver, who competes under the Dutch flag in Formula One for Red Bull Racing. Verstappen has won four Formula One World Drivers' Championship titles, which he won consecutively from 2021 to 2024 with Red Bull, and has won 63 Grands Prix across 10 seasons. \n")
16+
f16.write("Here Goes the Charles Leclerc\n")
17+
f16.write("Charles Marc Hervé Perceval Leclerc is a Monégasque racing driver, who competes in Formula One for Ferrari. Leclerc was runner-up in the Formula One World Drivers' Championship in 2022 with Ferrari, and has won eight Grands Prix across seven seasons.\n")

advancedpython1/03_problem.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
while True:
2+
n = input("Enter the Number: ")
3+
if n > '0' and n.isnumeric():
4+
break
5+
else:
6+
print("provide positive integer")
7+
8+
table = [f"{int(n)} x {i} = {int(n) * i}" for i in range(11)]
9+
10+
for index, item in enumerate(table):
11+
print(table[index])

advancedpython1/04_exception.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
try:
2+
a = int(input("Hey, provide the number: "))
3+
print(a, "is a Integer")
4+
except ValueError as v:
5+
print(v)
6+
except Exception as e:
7+
# print(e) print the error
8+
print("Provide Valid Input")
9+
10+
print("Thank You")
11+
12+
13+
a = int(input("Enter 1st Number: "))
14+
b = int(input("Enter 2nd Number: "))
15+
16+
if (b == 0):
17+
raise ZeroDivisionError("Program not meant to divide by zero")
18+
# crash the program main stuff while buildig a python module
19+
else:
20+
print("The Division a/b is", a/b)
21+
22+
try:
23+
a = int(input("Hey, provide the number: "))
24+
print(a, "is a Integer")
25+
26+
# if try successfully runs -> else will execute
27+
# try fails then respective exception occurs
28+
29+
except Exception as e:
30+
# print(e) print the error
31+
print("Provide Valid Input")
32+
else:
33+
print("Thank You")

advancedpython1/04_problem.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
try:
2+
a = input("Enter the Number: ")
3+
n = input("Enter the Number: ")
4+
print(int(a) / int(n))
5+
except ZeroDivisionError as e:
6+
print("Infinite")

advancedpython1/05_finally.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
def main():
3+
try:
4+
a = int(input("Hey, provide the number: "))
5+
print(a, "is a Integer")
6+
return a
7+
8+
except Exception as e:
9+
print("Provide Valid Input")
10+
11+
finally:
12+
print("Thank You, Finally is here")
13+
14+
print("This will work hopefully")
15+
16+
17+
main()

advancedpython1/05_problem.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
while True:
2+
n = input("Enter the Number: ")
3+
if n > '0' and n.isnumeric():
4+
break
5+
else:
6+
print("provide positive integer")
7+
8+
table = [int(n) * (i + 1) for i in range(10)]
9+
10+
with open("Tables.txt", "a") as f:
11+
f.write(str(table) + "\n")

0 commit comments

Comments
 (0)