Skip to content

Commit ca773b7

Browse files
committed
update
1 parent 15c5f6e commit ca773b7

File tree

21 files changed

+177
-3595
lines changed

21 files changed

+177
-3595
lines changed

01_Our_First_Python_Program/helloworld.py

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
2+
# https://youtube.com/@codewithmuh
3+
# https://github.com/rashiddaha
4+
15
# Python Tutorial
26

7+
38
# Print Hello World
49
print("Hello Wold")
510

@@ -24,3 +29,9 @@
2429
# print(type({'name':'Asabeneh'})) # Dictionary
2530
# print(type({9.8, 3.14, 2.7})) # Set
2631
# print(type((9.8, 3.14, 2.7))) # Tuple
32+
33+
34+
35+
# https://youtube.com/@codewithmuh
36+
# https://github.com/rashiddaha
37+

03_data_types/datatypes.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,10 @@
3636
x = b"Hello" #bytes
3737
x = bytearray(5) #bytearray
3838
x = memoryview(bytes(5)) #memoryview
39-
x = None #NoneType
39+
x = None #NoneType
40+
41+
42+
43+
# https://youtube.com/@codewithmuh
44+
# https://github.com/rashiddaha
45+

04_numbers/numbers.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,9 @@
6868
z = x + y # z is (5+7j)
6969

7070
# Subtraction
71-
z = x
71+
z = x
72+
73+
74+
# https://youtube.com/@codewithmuh
75+
# https://github.com/rashiddaha
76+

12_For_Loops/For_loops.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Here are some exercises you can try to practice using for loops in Python:
2+
3+
# Print the numbers from 1 to 10:
4+
5+
6+
for num in range(1, 11):
7+
print(num)
8+
#Print the sum of the numbers from 1 to 100:
9+
10+
11+
sum = 0
12+
for num in range(1, 101):
13+
sum += num
14+
print(sum)
15+
#Print the multiplication table for a given number:
16+
17+
18+
num = 5
19+
for i in range(1, 11):
20+
print(num, "x", i, "=", num*i)
21+
#Print the elements of a list in reverse order:
22+
23+
24+
fruits = ['apple', 'banana', 'cherry']
25+
for fruit in reversed(fruits):
26+
print(fruit)
27+
#Check if a number is prime:
28+
29+
30+
num = 17
31+
is_prime = True
32+
for i in range(2, num):
33+
if num % i == 0:
34+
is_prime = False
35+
break
36+
if is_prime:
37+
print(num, "is a prime number")
38+
else:
39+
print(num, "is not a prime number")
40+
#These exercises should help you get a better understanding of how for loops work in Python.

13_Functions/functions.py

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
3+
# Functions are blocks of reusable code in Python that can be called with specified inputs (arguments). Functions allow you to encapsulate and organize your code, making it easier to read, debug, and maintain.
4+
5+
# Here's the basic syntax for defining a function in Python:
6+
7+
8+
# def function_name(arg1, arg2, ...):
9+
# # code to be executed
10+
# return value
11+
12+
# def is the keyword used to define a function.
13+
# function_name is the name of the function. It should follow the same rules as variable names in Python.
14+
# arg1, arg2, ... are the arguments (inputs) that the function takes. They are optional, and you can define as many or as few arguments as you need.
15+
# The code inside the function is indented and is executed whenever the function is called.
16+
# The return statement is used to return a value from the function. The function execution stops when a return statement is encountered.
17+
# Here's an example of a function in Python:
18+
19+
20+
def greet(name):
21+
message = "Hello, " + name + "!"
22+
return message
23+
24+
greeting = greet("John")
25+
print(greeting)
26+
# This code defines a function greet that takes a single argument name and returns a message that greets the person. The function is then called and the returned value is assigned to a variable greeting which is then printed. The output of the code will be:
27+
28+
# Hello, John!
29+
# You can also define functions that take multiple arguments, like this:
30+
31+
32+
33+
def add(a, b):
34+
return a + b
35+
36+
sum = add(2, 3)
37+
print(sum)
38+
# This code defines a function add that takes two arguments a and b and returns the sum of the two numbers. The function is then called and the returned value is assigned to a variable sum which is then printed. The output of the code will be:
39+
# 5
40+
41+
42+
# https://youtube.com/@codewithmuh
43+
# https://github.com/rashiddaha
44+
+5-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11

22
from mymodule import generate_full_name as fullname, sum_two_nums as total, person as p, gravity as g
3-
print(fullname('Asabneh','Yetayeh'))
3+
print(fullname('Code With','Muh'))
44
print(total(1, 9))
55
mass = 100;
66
weight = mass * g
77
print(weight)
88
print(p)
9-
print(p['firstname'])
9+
print(p['firstname'])
10+
11+
# https://youtube.com/@codewithmuh
12+
# https://github.com/rashiddaha

15_Modules/mymodule.py 14_Modules/mymodule.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ def generate_full_name(firstname, lastname):
55

66
def sum_two_nums (num1, num2):
77
return num1 + num2
8-
gravity = 9.81
8+
gravity = 10.21
99
person = {
10-
"firstname": "Asabeneh",
11-
"age": 250,
12-
"country": "Finland",
13-
"city":'Helsinki'
10+
"firstname": "Code With",
11+
"age": 25,
12+
"country": "US",
13+
"city":'Los Angeles'
1414
}
1515

1616

17+
# https://youtube.com/@codewithmuh
18+
# https://github.com/rashiddaha
19+

15_Exception_handling/exception.py

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Exception handling in Python allows you to handle errors that may occur during the execution of your code. By using exception handling, you can ensure that your code continues to run even if an error occurs.
2+
3+
# Here's the basic syntax for exception handling in Python:
4+
5+
6+
# try:
7+
# # code that may raise an exception
8+
# except ExceptionType as variable:
9+
# # code to handle the exception
10+
11+
12+
# The try block contains the code that may raise an exception.
13+
# The except block contains the code to handle the exception if it occurs. ExceptionType is the type of exception you want to catch, such as ValueError, TypeError, etc. variable is a variable that will contain the exception object if an exception occurs.
14+
# You can have multiple except blocks to handle different types of exceptions.
15+
16+
# For example:
17+
18+
try:
19+
num = int(input("Enter a number: "))
20+
except ValueError:
21+
print("Invalid input. Not a number.")
22+
# This code tries to convert the input from the user to an integer.
23+
# If the input is not a valid number, a ValueError exception will be raised,
24+
# and the code in the except block will be executed to handle the exception.
25+
26+
# You can also use the finally block to specify code that must be executed
27+
# whether an exception occurs or not. The syntax for using a finally block is:
28+
29+
# try:
30+
# # code that may raise an exception
31+
# except ExceptionType as variable:
32+
# # code to handle the exception
33+
# finally:
34+
# code to be executed regardless of whether an exception occurred
35+
36+
# For example:
37+
38+
try:
39+
num = int(input("Enter a number: "))
40+
except ValueError:
41+
print("Invalid input. Not a number.")
42+
finally:
43+
print("This code will always be executed.")
44+
# In this code, the finally block will always be executed, even if an exception
45+
# occurs in the try block.
46+
47+
48+
49+
50+
# https://youtube.com/@codewithmuh
51+
# https://github.com/rashiddaha
52+
53+
54+
55+
56+

0 commit comments

Comments
 (0)