Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ea01216
Week 2 Question 2 is done.
mithat720 Apr 21, 2025
7167461
Week 2 Question 2 is updated.
mithat720 Apr 21, 2025
062e734
FIle name has changed as w2-q1
mithat720 Apr 21, 2025
1c35989
w2-q1 is updated.
mithat720 Apr 21, 2025
fd4d5ce
w2 -q1 is updated.
mithat720 Apr 21, 2025
4273cb2
Question1 is done
Bestfullmoon Apr 22, 2025
18afb1b
Merge branch 'main' of https://github.com/mithat720/Python_Modul_Week_2
Bestfullmoon Apr 22, 2025
e975a9b
week 2 - q2, q3
mithat720 Apr 23, 2025
1ab0653
Merge branch 'main' of https://github.com/mithat720/Python_Modul_Week_2
mithat720 Apr 23, 2025
de50881
updated.Question1
Bestfullmoon Apr 23, 2025
b947e3e
Create week2_cs_qs_1.py
cafersonmez Apr 23, 2025
1ba3979
Create ic_week_2_1.py
icubuk Apr 23, 2025
8f4e347
Update w2-q1.py
icubuk Apr 24, 2025
ac507a4
Update Question1.py
mithat720 Apr 24, 2025
559082f
Update w2-q1.py
mithat720 Apr 24, 2025
56d75e9
Create week_2_cs_List_Comprehensions.py
cafersonmez Apr 24, 2025
9e0043c
Create week_2_cs_nested.py
cafersonmez Apr 24, 2025
267684c
Create week_2_cs_Tuples.py
cafersonmez Apr 24, 2025
fad302e
Create week_2_cs_qs_3.py
cafersonmez Apr 24, 2025
300b671
Create week_2_cs_qs_2.py
cafersonmez Apr 24, 2025
ab07720
Create week_2_cs_qs_1.py
cafersonmez Apr 24, 2025
87b6683
Merge branch 'main' of https://github.com/mithat720/Python_Modul_Week_2
mithat720 Apr 25, 2025
60fa050
w2-HackerRank1
mithat720 Apr 25, 2025
eac5c1c
Merge branch 'main' of https://github.com/mithat720/Python_Modul_Week_2
mithat720 Apr 25, 2025
a77bf92
Create ic_week_2_2.py
icubuk Apr 25, 2025
4cd3f38
Create filmler.json
icubuk Apr 25, 2025
af6bc94
Merge branch 'main' of https://github.com/mithat720/Python_Modul_Week_2
icubuk Apr 25, 2025
83fa502
Create ic_week_2_3.py
icubuk Apr 25, 2025
b9caddf
Create musteriler.json
icubuk Apr 25, 2025
7478a34
Question2 is done
Bestfullmoon Apr 25, 2025
82d63aa
w2-HackerRank3
mithat720 Apr 25, 2025
cd6b4b4
Merge branch 'main' of https://github.com/mithat720/Python_Modul_Week_2
mithat720 Apr 25, 2025
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: 47 additions & 0 deletions Question1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#We already have this in a dictionary called students
students = {
'Ahmet Yilmaz': [85, 90, 78], #Each student has 3 grades: Midterm, Final, and Oral
'Mehmet Demir': [92, 88, 76],
'Ayse Kaya': [78, 89, 95],
'Zeynep Celik': [65, 70, 80],
'Ali Kara': [50, 60, 55],
'Fatma Yildiz': [88, 85, 90],
'Murat Aydin': [72, 68, 74],
'Elif Aksoy': [95, 90, 88],
'Hakan Ozturk': [45, 50, 55],
'Canan Tas': [80, 75, 82]
}

# 1. Calculate GPA and add to dictionary
for name, grades, in students.items(): #We loop through the dictionary and add GPA to each student's info ....
midterm, final, oral = grades
print(grades)
print(type(grades))
gpa = (midterm * 0.3) + (final * 0.5) + (oral * 0.2)
students[name].append(round(gpa, 2)) #students[name]- gets the list of grades
print(students) #.append(...)- adds something to the end of the list.So it's the 4th value in position, but index 3 in code
#round(gpa, 2)- rounds the GPA to 2 decimal places

# 2. Find student with highest GPA
highest_gpa = 0 #for now 0 , We'll update it later
top_student = "" #empty string, we dont know the best student yet
for name, grades in students.items(): #loop through the dictionary
if grades[3] > highest_gpa: #check if the student's GPA (grades[3]) higher than the current highest
highest_gpa = grades[3] #update highest_gpa to this student’s GPA
top_student = name #save the top_student name
print(f"Top student: {top_student} with GPA {highest_gpa}")

# 3. Separate names and surnames into a tuple list
name_tuples = [] #create an empty list
for full_name in students: #loop through the dictionary . students is a dictionary
first, last = full_name.split()
name_tuples.append((first, last)) #create a tuple first , last. add it to the list name_tuples
print(name_tuples)

# 4. Sort names alphabetically and print
sorted_names = sorted([first for first, last in name_tuples]) #sorted() function :sorts the lists in alphabetical order
print("Sorted first names:", sorted_names) #prints the list of names in order

# 5. Students with GPA < 70 in a set #{name for ... if ...} create a set
low_gpa_students = {name for name, grades in students.items() if grades[3] < 70} #check their GPA, which is the 4th value in the list (index 3)
print("Students with GPA < 70:", low_gpa_students) #if GPA is less than 70 , the student is added to the group
109 changes: 109 additions & 0 deletions Question2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#1)Create a movie
def create_movie():
name = input("Enter movie name: ")
director = input("Enter director: ")
year = input("Enter release year: ")
genre = input("Enter genre: ")

movie = { #create a dictionary
"name": name, #"name" is the key, and the movie name is its value
"director": director,
"year": year,
"genre": genre
}
return movie

#2)Edit or delete a movie
def edit_movie(movie):
print("Editing movie:", movie["name"])
fields = {"1":"name", "2":"director", "3": "year", "4": "genre"} #fields is a dictionary that maps user choices (like "1") to the keys in the movie dictionary (like "name")

print("1. Name\n2. Director\n3. Year\n4. Genre") #print("1. Name")
#print("2. Director")
#print("3. Year")
#print("4. Genre")
choice = input("What do you want to edit? (1-4): ")

if choice in fields:
new_value = input(f"Enter new {fields[choice]}: ")
movie[fields[choice]] = new_value
else:
print("Invalid choice.")

return movie

def delete_movie(collection, name):
for movie in collection: #goes through the list of movies
if movie ["name"].lower() == name.lower(): #if the name matches, it removes the movie from the list
collection.remove(movie) #use .lower() to make sure it matches even if the user uses different capital letters
print("Movie deleted.")
return
print("Movie not found")

#3)Allow the user to view their collection. List all movies or filter by criteria such as genre or year of release.
def view_movies(collection):
print("1. View all\n2. Filter by genre\n3. Filter by year" )
choice = input("Choose an option: ")

if choice == '1':
for movie in collection:
print(movie)
elif choice == '2':
genre = input("Enter genre: ")
for movie in collection:
if movie["genre"].lower() == genre.lower():
print(movie)
elif choice == '3':
year = input("Enter year: ")
for movie in collection:
if movie["year"] == year:
print(movie)
else:
print("Invalid option.")

#4-Save the movie data in a file and restore this data when you start the program.
import json

def save_to_file(collection, filename="movies.json"):
with open(filename, "w") as f:
json.dump(collection, f)

def load_from_file(filename="movies.json"):
try:
with open(filename, "r") as f:
return json.load(f)
except FileNotFoundError:
return []


def main():
movies = load_from_file()

while True:
print("\n1. Add movie\n2. Edit movie\n3. Delete movie\n4. View collection\n5. Save and Exit")
choice = input("Enter your choice: ")

if choice == '1':
movie = create_movie()
movies.append(movie)
elif choice == '2':
name = input("Enter the movie name to edit: ")
for m in movies:
if m["name"].lower() == name.lower():
edit_movie(m)
break
else:
print("Movie not found.")
elif choice == '3':
name = input("Enter the movie name to delete: ")
delete_movie(movies, name)
elif choice == '4':
view_movies(movies)
elif choice == '5':
save_to_file(movies)
print("Collection saved. Goodbye!")
break
else:
print("Invalid choice. Try again.")

main()
103 changes: 103 additions & 0 deletions Question3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#Question 3: Customer Management System
#1)Use a dictionary structure to store customer information.
# Assign a unique customer identification (ID) for each customer and associate customer information with this ID.
# You can use a dictionary containing information such as name, surname, e-mail, phone number for each customer.
customers = {} #empty dictionary to hold all customers record
#the key will be the Customer ID
#the value will be another dictionary with customer details

#2)Provide a menu where the user can choose the following actions:
#3)Add New Customer
def add_customer(customers):
cid = input("Enter customer ID: ")

if cid in customers:
print("Customer ID already exists.")
return

name = input("Enter name: ")
surname = input("Enter surname: ")
email = input("Enter email: ")
phone = input("Enter phone number: ")

customers[cid] = {
"name": name,
"surname": surname,
"email": email,
"phone": phone
}

print("Customer added successfully.")

#4)Update Customer Info
def update_customer(customers):
cid = input("Enter customer ID to update: ")

if cid not in customers: # check if the ID exists
print("Customer not found.")
return

print("Current info:", customers[cid])
#get new info from the user
name = input("Enter new name: ")
surname = input("Enter new surname: ")
email = input("Enter new email: ")
phone = input("Enter new phone number: ")

customers[cid] = { #update the customer details
"name": name,
"surname": surname,
"email": email,
"phone": phone
}

print("Customer updated.")

#5)Delete a Customer
def delete_customer(customers):
cid = input("Enter customer ID to delete: ")

if cid in customers: #check if the ID exists
del customers[cid] #del removes an item from a dictionary
print("Customer deleted.")
else:
print("Customer not found.")

#6)List All Customers
def list_customers(customers):
if not customers:
print("No customers in the system.")
return
#Loop through all customers and print their details
for cid, info in customers.items(): #.items() lets us loop through the key and value in the dictionary
print(f"ID: {cid}, Name: {info['name']} {info['surname']}, Email: {info['email']}, Phone: {info['phone']}")

#7)Menu System (Loop until logout)
def main():
customers = {} # main dictionary to store customer data.start with an empty dictionary for customers

while True: #display the menu
print("\nCustomer Management System")
print("1. Add Customer")
print("2. Update Customer")
print("3. Delete Customer")
print("4. List All Customers")
print("5. Exit")

choice = input("Choose an option (1-5): ")

if choice == "1":
add_customer(customers)
elif choice == "2":
update_customer(customers)
elif choice == "3":
delete_customer(customers)
elif choice == "4":
list_customers(customers)
elif choice == "5":
print("Goodbye!")
break
else:
print("Invalid choice. Please try again.")

main()
4 changes: 4 additions & 0 deletions arch.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
saban|ertem|1973|komedi
hababam|ertem egilmez|1982|komedi
sut|nuri bilge ceylan|2012|dram
seker|nuri bilge ceylan|2014|dram
12 changes: 12 additions & 0 deletions filmler.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"sefiller": {
"yil": "2001",
"yonetmen": "ahmet ss",
"tur": "dram"
},
"yeni sefiller": {
"yil": "2005",
"yonetmen": "yeni ahmet",
"tur": "yeni dram"
}
}
90 changes: 90 additions & 0 deletions ic_week_2_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Öğrenci isimlerini ve notlarının girişi ve oratlama hesabı


# i=1
# ogrenciler = {}
# while i<=10:

# adi=str(input("Öğrenci adını giriniz:"))
# final = float(input("Öğrenci final notunu giriniz:"))
# vize = float(input("Öğrenci vize notunu giriniz:"))
# notlar=[final, vize, (final + vize) / 2]
# ogrenciler[adi]= [notlar]

# i += 1
# print(ogrenciler)

students = {
'Ahmet Yılmaz': [85, 90, 78], # Midterm: 85, Final: 90, Oral: 78
'Mehmet Demir': [92, 88, 76], # Midterm: 92, Final: 88, Oral: 76
'Ayşe Kaya': [78, 89, 95], # Midterm: 78, Final: 89, Oral: 95
'Zeynep Çelik': [65, 70, 80], # Midterm: 65, Final: 70, Oral: 80
'Ali Kara': [50, 60, 55], # Midterm: 50, Final: 60, Oral: 55
'Fatma Yıldız': [88, 85, 90], # Midterm: 88, Final: 85, Oral: 90
'Murat Aydın': [72, 68, 74], # Midterm: 72, Final: 68, Oral: 74
'Elif Aksoy': [95, 90, 88], # Midterm: 95, Final: 90, Oral: 88
'Hakan Öztürk': [45, 50, 55], # Midterm: 45, Final: 50, Oral: 55
'Canan Taş': [80, 75, 82] # Midterm: 80, Final: 75, Oral: 82
}
en_yuksek_ort = max(students.items(), key=lambda x: x[1][2])
print(f"En yüksek ortalamaya sahip öğrenci: {en_yuksek_ort[0]} Ortalama: {en_yuksek_ort[1][2]}")

# Ad ve Soyad bilgilerini ayırma

students = {
'Ahmet Yılmaz': [85, 90, 78], # Midterm: 85, Final: 90, Oral: 78
'Mehmet Demir': [92, 88, 76], # Midterm: 92, Final: 88, Oral: 76
'Ayşe Kaya': [78, 89, 95], # Midterm: 78, Final: 89, Oral: 95
'Zeynep Çelik': [65, 70, 80], # Midterm: 65, Final: 70, Oral: 80
'Ali Kara': [50, 60, 55], # Midterm: 50, Final: 60, Oral: 55
'Fatma Yıldız': [88, 85, 90], # Midterm: 88, Final: 85, Oral: 90
'Murat Aydın': [72, 68, 74], # Midterm: 72, Final: 68, Oral: 74
'Elif Aksoy': [95, 90, 88], # Midterm: 95, Final: 90, Oral: 88
'Hakan Öztürk': [45, 50, 55], # Midterm: 45, Final: 50, Oral: 55
'Canan Taş': [80, 75, 82] # Midterm: 80, Final: 75, Oral: 82
}

ad_soyad_tuple = []
ad_soyad_tuple = tuple((ad_soyad.split()[0], ad_soyad.split()[1]) for ad_soyad in students.keys())
print(ad_soyad_tuple)
print(type(ad_soyad_tuple))
# İsme göre sıralama

students = {
'Ahmet Yılmaz': [85, 90, 78], # Midterm: 85, Final: 90, Oral: 78
'Mehmet Demir': [92, 88, 76], # Midterm: 92, Final: 88, Oral: 76
'Ayşe Kaya': [78, 89, 95], # Midterm: 78, Final: 89, Oral: 95
'Zeynep Çelik': [65, 70, 80], # Midterm: 65, Final: 70, Oral: 80
'Ali Kara': [50, 60, 55], # Midterm: 50, Final: 60, Oral: 55
'Fatma Yıldız': [88, 85, 90], # Midterm: 88, Final: 85, Oral: 90
'Murat Aydın': [72, 68, 74], # Midterm: 72, Final: 68, Oral: 74
'Elif Aksoy': [95, 90, 88], # Midterm: 95, Final: 90, Oral: 88
'Hakan Öztürk': [45, 50, 55], # Midterm: 45, Final: 50, Oral: 55
'Canan Taş': [80, 75, 82] # Midterm: 80, Final: 75, Oral: 82
}

ad_soyad_tuple = []
ad_soyad_tuple = tuple((ad_soyad.split()[0], ad_soyad.split()[1]) for ad_soyad in students.keys())
ad_soyad_sort = sorted(ad_soyad_tuple)
print(ad_soyad_sort)
# GNO ortalaması 70 altında olan öğrencileri bir listede toplama

students = {
'Ahmet Yılmaz': [85, 90, 78], # Midterm: 85, Final: 90, Oral: 78
'Mehmet Demir': [92, 88, 76], # Midterm: 92, Final: 88, Oral: 76
'Ayşe Kaya': [78, 89, 95], # Midterm: 78, Final: 89, Oral: 95
'Zeynep Çelik': [65, 70, 80], # Midterm: 65, Final: 70, Oral: 80
'Ali Kara': [50, 60, 55], # Midterm: 50, Final: 60, Oral: 55
'Fatma Yıldız': [88, 85, 90], # Midterm: 88, Final: 85, Oral: 90
'Murat Aydın': [72, 68, 74], # Midterm: 72, Final: 68, Oral: 74
'Elif Aksoy': [95, 90, 88], # Midterm: 95, Final: 90, Oral: 88
'Hakan Öztürk': [45, 50, 55], # Midterm: 45, Final: 50, Oral: 55
'Canan Taş': [80, 75, 82] # Midterm: 80, Final: 75, Oral: 82
}

gno_70 = []
for adsoyad, notlar in students.items():
if notlar[2] < 70:
gno_70.append((adsoyad, notlar[2]))
print(gno_70)

Loading