Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions 01_Day_Introduction/helloworld.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
# Introduction
# Day 1 - 30DaysOfPython Challenge
# =====================================
# Day 1 - 30 Days of Python Challenge
# Introduction to Python
# =====================================

print("Hello World!") # print hello world
# Printing a simple message
print("Hello, World!")

print(2 + 3) # addition(+)
print(3 - 1) # subtraction(-)
print(2 * 3) # multiplication(*)
print(3 + 2) # addition(+)
print(3 - 2) # subtraction(-)
print(3 * 2) # multiplication(*)
print(3 / 2) # division(/)
print(3 ** 2) # exponential(**)
print(3 % 2) # modulus(%)
print(3 // 2) # Floor division operator(//)
print("\n--- Basic Arithmetic Operations ---")

# Checking data types
a = 3
b = 2

print(type(10)) # Int
print(type(3.14)) # Float
print(type(1 + 3j)) # Complex
print(type('Asabeneh')) # String
print(type([1, 2, 3])) # List
print(type({'name': 'Asabeneh'})) # Dictionary
print(type({9.8, 3.14, 2.7})) # Tuple
print(f"Addition: {a} + {b} = {a + b}")
print(f"Subtraction: {a} - {b} = {a - b}")
print(f"Multiplication: {a} * {b} = {a * b}")
print(f"Division: {a} / {b} = {a / b}")
print(f"Exponentiation: {a} ** {b} = {a ** b}")
print(f"Modulus: {a} % {b} = {a % b}")
print(f"Floor Division: {a} // {b} = {a // b}")

print("\n--- Checking Data Types ---")

print(type(10)) # Integer
print(type(3.14)) # Float
print(type(1 + 3j)) # Complex
print(type("Asabeneh")) # String
print(type([1, 2, 3])) # List
print(type({"name": "Asabeneh"})) # Dictionary
print(type((9.8, 3.14, 2.7))) # Tuple
32 changes: 19 additions & 13 deletions 02_Day_Variables_builtin_functions/variables.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@

# Variables in Python

first_name = 'Asabeneh'
last_name = 'Yetayeh'
country = 'Finland'
city = 'Helsinki'
age = 250
is_married = True
skills = ['HTML', 'CSS', 'JS', 'React', 'Python']
first_name = 'MAX' #string
last_name = 'VERSTAPPEN' #string
continent = 'Europe' #string
country = 'Netherlands' #string
city = 'Amsterdam' #string

age = 69 #integer

is_married = True #bool

skills = ['HTML', 'CSS', 'JS', 'React', 'Python','Rust'] #list of string

person_info = {
'firstname': 'Asabeneh',
'lastname': 'Yetayeh',
'country': 'Finland',
'city': 'Helsinki'
}
'firstname': 'MAX',
'lastname': 'VERSTAPPEN',
'country': 'Netherlands',
'city': 'Amsterdam'
} #dictionary

# Printing the values stored in the variables

print('First name:', first_name)
print('First name length:', len(first_name))
print('Last name: ', last_name)
print('Last name length: ', len(last_name))
print('Continent: ', cotinent)
print('Country: ', country)
print('City: ', city)
print('Age: ', age)
Expand All @@ -30,7 +36,7 @@

# Declaring multiple variables in one line

first_name, last_name, country, age, is_married = 'Asabeneh', 'Yetayeh', 'Helsink', 250, True
first_name, last_name, country, age, is_married = 'MAX', 'VERSTAPPEN', 'Netherlands', 69, True

print(first_name, last_name, country, age, is_married)
print('First name:', first_name)
Expand Down
20 changes: 11 additions & 9 deletions 05_Day_Lists/day_5.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
print(len(empty_list)) # 0

# list of fruits
fruits = ['banana', 'orange', 'mango', 'lemon']
fruits = ['banana', 'orange', 'mango', 'lemon'] #list of fruits
vegetables = ['Tomato', 'Potato', 'Cabbage',
'Onion', 'Carrot'] # list of vegetables
animal_products = ['milk', 'meat', 'butter',
'yoghurt'] # list of animal products
web_techs = ['HTML', 'CSS', 'JS', 'React', 'Redux',
'Node', 'MongDB'] # list of web technologies
countries = ['Finland', 'Estonia', 'Denmark', 'Sweden', 'Norway']
countries = ['Finland', 'Estonia', 'Denmark', 'Sweden', 'Norway'] #list of countries
liquors = ['Whiskey' , 'Beer' , 'Cognac' , 'Gin' , 'Scotch' , 'Vodka' , 'Rum'] #list of liquors

# Print the lists and it length
print('Fruits:', fruits)
Expand All @@ -23,7 +24,6 @@
print('Number of countries:', len(countries))

# Modifying list

fruits = ['banana', 'orange', 'mango', 'lemon']
first_fruit = fruits[0] # we are accessing the first item using its index
print(first_fruit) # banana
Expand Down Expand Up @@ -75,19 +75,20 @@

# Append
fruits = ['banana', 'orange', 'mango', 'lemon']
fruits.append('apple')
fruits.append('apple') #adding apple in the end of the list
print(fruits) # ['banana', 'orange', 'mango', 'lemon', 'apple']
# ['banana', 'orange', 'mango', 'lemon', 'apple', 'lime]
fruits.append('lime')
print(fruits)
print(fruits) # ['banana', 'orange', 'mango', 'lemon', 'apple', 'lime']



# insert
fruits = ['banana', 'orange', 'mango', 'lemon']
fruits.insert(2, 'apple') # insert apple between orange and mango
print(fruits) # ['banana', 'orange', 'apple', 'mango', 'lemon']
# ['banana', 'orange', 'apple', 'mango', 'lime','lemon',]
print(fruits) # ['banana', 'orange', 'apple', 'mango', 'lemon']
fruits.list(3, 'lime')
print(fruits)
print(fruits) # ['banana', 'orange', 'apple', 'mango', 'lime','lemon',]


# remove
fruits = ['banana', 'orange', 'mango', 'lemon']
Expand Down Expand Up @@ -164,6 +165,7 @@
print(fruits.index('orange')) # 1
ages = [22, 19, 24, 25, 26, 24, 25, 24]
print(ages.index(24))

# Reverse
fruits = ['banana', 'orange', 'mango', 'lemon']
fruits.reverse()
Expand Down
201 changes: 201 additions & 0 deletions 06_Day_Tuples/day_06.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
# =====================================================
# 30 Days Of Python - Day 6: Tuples (Full Practice Code)
# =====================================================

print("===== DAY 6: TUPLES =====\n")

# -----------------------------------------------------
# 1. Creating Tuples
# -----------------------------------------------------

# Empty tuple
empty_tuple_1 = ()
empty_tuple_2 = tuple()

print("Empty tuples:")
print(empty_tuple_1)
print(empty_tuple_2)
print()

# Tuple with initial values
fruits = ('banana', 'orange', 'mango', 'lemon')
print("Fruits tuple:", fruits)
print()

# -----------------------------------------------------
# 2. Tuple Length
# -----------------------------------------------------

print("Length of fruits tuple:", len(fruits))
print()

# -----------------------------------------------------
# 3. Accessing Tuple Items
# -----------------------------------------------------

# Positive indexing
first_fruit = fruits[0]
second_fruit = fruits[1]
last_fruit = fruits[len(fruits) - 1]

print("Positive indexing:")
print("First fruit:", first_fruit)
print("Second fruit:", second_fruit)
print("Last fruit:", last_fruit)
print()

# Negative indexing
print("Negative indexing:")
print("First fruit:", fruits[-4])
print("Second fruit:", fruits[-3])
print("Last fruit:", fruits[-1])
print()

# -----------------------------------------------------
# 4. Slicing Tuples
# -----------------------------------------------------

# Positive slicing
print("Positive slicing:")
print("All fruits:", fruits[0:])
print("Middle fruits:", fruits[1:3])
print("From index 1 to end:", fruits[1:])
print()

# Negative slicing
print("Negative slicing:")
print("All fruits:", fruits[-4:])
print("Middle fruits:", fruits[-3:-1])
print("From -3 to end:", fruits[-3:])
print()

# -----------------------------------------------------
# 5. Changing Tuples to Lists
# -----------------------------------------------------

print("Changing tuple to list to modify it:")

fruits_list = list(fruits)
fruits_list[0] = 'apple'
print("Modified list:", fruits_list)

fruits = tuple(fruits_list)
print("Converted back to tuple:", fruits)
print()

# -----------------------------------------------------
# 6. Checking an Item in a Tuple
# -----------------------------------------------------

print("Checking items in tuple:")
print("'orange' in fruits:", 'orange' in fruits)
print("'banana' in fruits:", 'banana' in fruits)
print("'grape' in fruits:", 'grape' in fruits)
print()

# -----------------------------------------------------
# 7. Joining Tuples
# -----------------------------------------------------

vegetables = ('Tomato', 'Potato', 'Cabbage', 'Onion', 'Carrot')
fruits_and_vegetables = fruits + vegetables

print("Joined tuples:")
print(fruits_and_vegetables)
print()

# -----------------------------------------------------
# 8. Deleting Tuples
# -----------------------------------------------------

temp_tuple = ('item1', 'item2', 'item3')
del temp_tuple
print("Tuple deleted successfully\n")

# =====================================================
# EXERCISES - LEVEL 1
# =====================================================

print("===== EXERCISES: LEVEL 1 =====\n")

# 1. Create an empty tuple
empty_tuple = ()
print("1. Empty tuple:", empty_tuple)

# 2. Create sisters and brothers tuples
sisters = ('Anna', 'Beth')
brothers = ('John', 'Mike')

print("2. Sisters:", sisters)
print(" Brothers:", brothers)

# 3. Join siblings
siblings = sisters + brothers
print("3. Siblings:", siblings)

# 4. Number of siblings
print("4. Number of siblings:", len(siblings))

# 5. Add parents to family_members
family_members = siblings + ('Father', 'Mother')
print("5. Family members:", family_members)
print()

# =====================================================
# EXERCISES - LEVEL 2
# =====================================================

print("===== EXERCISES: LEVEL 2 =====\n")

# 1. Unpack siblings and parents
*siblings_only, father, mother = family_members

print("1. Unpacked:")
print(" Siblings:", siblings_only)
print(" Father:", father)
print(" Mother:", mother)
print()

# 2. Create food tuples
fruits_tp = ('banana', 'orange', 'mango')
vegetables_tp = ('carrot', 'potato', 'onion')
animal_products_tp = ('milk', 'meat', 'butter')

food_stuff_tp = fruits_tp + vegetables_tp + animal_products_tp
print("2. Food stuff tuple:", food_stuff_tp)
print()

# 3. Convert tuple to list
food_stuff_lt = list(food_stuff_tp)
print("3. Food stuff list:", food_stuff_lt)
print()

# 4. Slice middle item(s)
middle_index = len(food_stuff_lt) // 2

if len(food_stuff_lt) % 2 == 0:
middle_items = food_stuff_lt[middle_index - 1: middle_index + 1]
else:
middle_items = food_stuff_lt[middle_index]

print("4. Middle item(s):", middle_items)
print()

# 5. Slice first three and last three items
print("5. First three items:", food_stuff_lt[:3])
print(" Last three items:", food_stuff_lt[-3:])
print()

# 6. Delete food_stuff_tp
del food_stuff_tp
print("6. food_stuff_tp tuple deleted")
print()

# 7. Check nordic countries
nordic_countries = ('Denmark', 'Finland', 'Iceland', 'Norway', 'Sweden')

print("7. Nordic country checks:")
print(" Is 'Estonia' a nordic country?", 'Estonia' in nordic_countries)
print(" Is 'Iceland' a nordic country?", 'Iceland' in nordic_countries)

print("\n===== END OF DAY 6 =====")
Loading