From 60796beed3ffc954a5e14285b0370126854613dd Mon Sep 17 00:00:00 2001 From: Mustafa Gundogdu <103361276+mustafagundogdu80@users.noreply.github.com> Date: Tue, 24 Dec 2024 05:37:58 +0100 Subject: [PATCH 1/5] Solutions of week 1 Solutions of week 1 --- Week1.py | 158 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 Week1.py diff --git a/Week1.py b/Week1.py new file mode 100644 index 0000000..9e0f6f4 --- /dev/null +++ b/Week1.py @@ -0,0 +1,158 @@ +""" +Week 1 +""" + +# Question 1: Write a Python code that prints numbers from 1 to 10 on the screen. + +# for i in range(1,11): +# print(i) + +"""---------------------------------------------------""" +# Question 2: Take a number input from the user and write a Python program that prints even numbers up to this number on the screen. Do this first with 'for' and then with 'while' loops. + +# user_number = int(input("Please enter a number: ")) +# for i in range(1,user_number+1): +# if i % 2 == 0 : +# print(i) +# counter = 1 +# +# while counter <= user_number: +# if counter % 2 == 0: +# print(counter) +# counter +=1 + +"""---------------------------------------------------""" +# Question 3: Write a Python code that receives a start and end value from the user and prints all the numbers between these values (including the end value) on the screen. + +# start_value = int(input("Please enter a starting value: ")) +# end_value = int(input("Please enter a ending value: ")) +# +# for i in range(start_value,end_value+1): +# print(i) + +"""---------------------------------------------------""" +# Question 4: Get a number from the user and write a Python code that prints whether this number is odd or even. + +# nummer = int(input("Please enter a number: ")) +# if nummer % 2 == 0: +# print("The number you enter is an even number.") +# else: +# print("This number you entry is an odd number.") + +"""---------------------------------------------------""" +# Question 5: Write a Python program that takes a positive integer input from the user and calculates its factorial. +# Factorial is the product of all positive integers between a number itself and 1. +# For example: if the user entered 5, the program should give the following output: Enter a number from the user: 5 Factorial: 120 + +# factorial_user_input = int(input("Please enter the number to calculate the factorial: ")) +# while factorial_user_input <= 0: +# factorial_user_input = int(input("You have entered an incorrect entry! Please re-enter the number to calculate the factorial: ")) +# factorial_result = 1 +# #Calculating factorial +# for i in range(1,factorial_user_input+1): +# factorial_result *= i +# print("Factorial:",factorial_result) + +"""---------------------------------------------------""" +# Question 6: Write a Python code that receives a number from the user and checks whether this number is prime. +# user_number = int(input("Please enter a number: ")) +# prime_control = True +# if user_number >= 3 : +# for i in range(3,int(user_number ** 0.5)): +# if user_number % i == 0: +# prime_control = False +# break +# if prime_control : +# print(f"The number you entered, {user_number}, is a prime number.") +# else: +# print(f"The number you entered, {user_number}, is not a prime number.") + +"""---------------------------------------------------""" +# Question 7: How to create a loop that calculates the Fibonacci sequence and returns the result as a list containing numbers up to a certain limit? +# +# list_fibonacci =[1,1] +# index_fibonacci = 2 +# digit_number = 0 +# while len(str(digit_number))!= 100: +# list_fibonacci.append(list_fibonacci[index_fibonacci-2]+list_fibonacci[index_fibonacci-1]) +# digit_number = list_fibonacci[index_fibonacci-2]+list_fibonacci[index_fibonacci-1] +# index_fibonacci += 1 +# # print(list_fibonacci) +# print(index_fibonacci) +# print(digit_number) + +"""---------------------------------------------------""" +# Question 8: Write a Python code that takes a word from the user and prints the reverse of this word on the screen. + +# user_string = input("Please enter a word: ") +# reserve_string = "" +# for i in user_string: +# reserve_string = i + reserve_string +# print(reserve_string) + +"""---------------------------------------------------""" +# Question 9: How to create a combination of loop and conditional statement that takes a word input from the user and checks whether that word is a palindrome (the same when read backwards)? + +# paindrome_str = input("Please enter a word: ") +# paindrome_control = True +# for i in range(int(len(paindrome_str)/2)): +# if (paindrome_str[i] != paindrome_str[-1-i]) : +# paindrome_control= False +# break +# if paindrome_control : +# # if paindrome_str == paindrome_str[::-1]: +# print("The word you entered is a paindrome.") +# else: +# print("The word you entered is a not paindrome.") + +"""---------------------------------------------------""" +# Question 10: Write the code that calculates the person's weight index and returns the result as underweight, overweight or overweight according to the index value. +# (You can look on the internet for the weight index calculation) +# To do this, ask the user for their weight and height measurements. +# weight index If it is below 25, it is weak, Between 25-30 is normal, If you are over 30-40, you are overweight. If you are over 40, you are overweight. + +# user_weight = int(input("Please enter your weight: ")) +# user_height = float(input("Please enter your height(cm): "))/100 +# user_weight_index = user_weight / (user_height ** 2) +# if user_weight_index <25 : +# print("You are weak") +# elif (user_weight_index >= 25) and (user_weight_index <= 30) : +# print("You are normal") +# elif (user_weight_index > 30) and (user_weight_index < 40) : +# print("You are overweight") +# else: +# print("You have danger of obesity!!!") +# print(user_weight_index) + +"""---------------------------------------------------""" +# Question 11: How to write a Python program that finds the largest of three numbers entered by a user? + +# user_number1,user_number2,user_number3 = int(input("Please enter first number: ")), int(input("Please enter second number: ")),int(input("Please enter third number: ")) +# largest_number = user_number1 +# if largest_number < user_number2: +# largest_number =user_number2 +# if largest_number < user_number3: +# largest_number = user_number3 +# print("The largest number you enter:",largest_number) + +"""---------------------------------------------------""" +# Question 12: Get Midterm and Final grades from a student for any course. The sum of 40% of the midterm exam grade and 60% of the final grade will give the year-end average. +# If the average is below 50, "FAILED" will appear on the screen, and if it is 50 or above, "SUCCESSFUL" will be displayed on the screen. +# This printing process is 4 lessons. and the lessons will be written one after the other. + +# courses = list() +# for i in range(4): +# course ={} +# course["id"] = i+1 +# course["name"] = input("Please enter course name: ") +# course["midterm"]= int(input("Please enter midterm exame grade: ")) +# course["final"] = int(input("Please enter final exame grade: ")) +# course["average"] = ((course["midterm"] * 0.4) + (course["final"] * 0.6)) +# if course["average"] < 50: +# course["result"]="FAILED" +# else: +# course["result"] = "SUCCESSFUL" +# courses.append(course) +# +# for i in courses: +# print(f"Student in {i["name"]} course: ",i["result"]," Avarage:",i["average"]) \ No newline at end of file From 9b6e99b81c9aef4e21de578f0526b51ad47d48c3 Mon Sep 17 00:00:00 2001 From: Mustafa Gundogdu <103361276+mustafagundogdu80@users.noreply.github.com> Date: Tue, 24 Dec 2024 05:40:48 +0100 Subject: [PATCH 2/5] Solutions of week 1 Hacker Rank Solutions of week 1 Hacker Rank --- Week1hackerrank.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Week1hackerrank.py diff --git a/Week1hackerrank.py b/Week1hackerrank.py new file mode 100644 index 0000000..7d4519d --- /dev/null +++ b/Week1hackerrank.py @@ -0,0 +1,64 @@ +# # Hackerrank 1 +# +# if __name__ == '__main__': +# a = int(input()) +# b = int(input()) +# print(a+b) +# print(a-b) +# print(a*b) +"""---------------------------------------------------""" +# # Hackerrank 2 +# +# if __name__ == '__main__': +# n = int(input()) +# arr = map(int, input().split()) +# max_score = second_score = 0 +# for i in arr: +# if i > max_score : +# second_score = max_score +# max_score = i +# elif i > second_score and i < max_score : +# second_score = i +# print(second_score) +"""---------------------------------------------------""" +# # Hackerrank 3 +# +# if __name__ == '__main__': +# n = int(input()) +# str_list = "" +# for i in range(1,n+1): +# str_list += str(i) +# print(str_list) +"""---------------------------------------------------""" +# # Hackerrank4 +# +# if __name__ == '__main__': +# n = int(input()) +# student_marks = {} +# for _ in range(n): +# name, *line = input().split() +# scores = list(map(float, line)) +# student_marks[name] = scores +# query_name = input() +# not_toplam = 0 +# for i in student_marks[query_name]: +# not_toplam += i +# ortalama = f"{(not_toplam/len(student_marks[query_name])):.2f}" +# print(ortalama) +"""---------------------------------------------------""" +regex_integer_in_range = r"_________" # Do not delete 'r'. +regex_alternating_repetitive_digit_pair = r"_________" # Do not delete 'r'. + +import re + +P = input() + +print(bool(re.match(regex_integer_in_range, P)) + and len(re.findall(regex_alternating_repetitive_digit_pair, P)) < 2) + +number_examined_list = list() +for i in range(len(regex_alternating_repetitive_digit_pair) - 2): + if (regex_alternating_repetitive_digit_pair[i] == regex_alternating_repetitive_digit_pair[i + 2] and + regex_alternating_repetitive_digit_pair[i] != regex_alternating_repetitive_digit_pair[i + 1]): + number_examined_list.append[regex_alternating_repetitive_digit_pair[i]] +print(len(number_examined_list) > 0) \ No newline at end of file From 315dd0e8099f8535d32e7fad31cd868ee83cda94 Mon Sep 17 00:00:00 2001 From: Mustafa Gundogdu <103361276+mustafagundogdu80@users.noreply.github.com> Date: Sat, 28 Dec 2024 02:03:54 +0100 Subject: [PATCH 3/5] Week1hackerrank.py --- Week1hackerrank.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/Week1hackerrank.py b/Week1hackerrank.py index 7d4519d..f51bf55 100644 --- a/Week1hackerrank.py +++ b/Week1hackerrank.py @@ -46,19 +46,3 @@ # ortalama = f"{(not_toplam/len(student_marks[query_name])):.2f}" # print(ortalama) """---------------------------------------------------""" -regex_integer_in_range = r"_________" # Do not delete 'r'. -regex_alternating_repetitive_digit_pair = r"_________" # Do not delete 'r'. - -import re - -P = input() - -print(bool(re.match(regex_integer_in_range, P)) - and len(re.findall(regex_alternating_repetitive_digit_pair, P)) < 2) - -number_examined_list = list() -for i in range(len(regex_alternating_repetitive_digit_pair) - 2): - if (regex_alternating_repetitive_digit_pair[i] == regex_alternating_repetitive_digit_pair[i + 2] and - regex_alternating_repetitive_digit_pair[i] != regex_alternating_repetitive_digit_pair[i + 1]): - number_examined_list.append[regex_alternating_repetitive_digit_pair[i]] -print(len(number_examined_list) > 0) \ No newline at end of file From 49f2f1af30842cc97e12badef477c9ab9d3e49cd Mon Sep 17 00:00:00 2001 From: Mustafa Gundogdu <103361276+mustafagundogdu80@users.noreply.github.com> Date: Sat, 28 Dec 2024 02:06:19 +0100 Subject: [PATCH 4/5] Week1hackerrank.py --- Week1hackerrank.py | 92 ++++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 44 deletions(-) diff --git a/Week1hackerrank.py b/Week1hackerrank.py index f51bf55..3caac86 100644 --- a/Week1hackerrank.py +++ b/Week1hackerrank.py @@ -1,48 +1,52 @@ -# # Hackerrank 1 -# -# if __name__ == '__main__': -# a = int(input()) -# b = int(input()) -# print(a+b) -# print(a-b) -# print(a*b) +# Hackerrank 1 + +if __name__ == '__main__': + a = int(input()) + b = int(input()) + print(a+b) + print(a-b) + print(a*b) """---------------------------------------------------""" -# # Hackerrank 2 -# -# if __name__ == '__main__': -# n = int(input()) -# arr = map(int, input().split()) -# max_score = second_score = 0 -# for i in arr: -# if i > max_score : -# second_score = max_score -# max_score = i -# elif i > second_score and i < max_score : -# second_score = i -# print(second_score) +# Hackerrank 2 + +if __name__ == '__main__': + n = int(input()) + arr = map(int, input().split()) + max_score = second_score = -101 + for i in arr: + if i > max_score : + second_score = max_score + max_score = i + elif i > second_score and i < max_score : + second_score = i + print(second_score) """---------------------------------------------------""" -# # Hackerrank 3 -# -# if __name__ == '__main__': -# n = int(input()) -# str_list = "" -# for i in range(1,n+1): -# str_list += str(i) -# print(str_list) +# Hackerrank 3 + +if __name__ == '__main__': + n = int(input()) + str_list = "" + for i in range(1,n+1): + str_list += str(i) + print(str_list) """---------------------------------------------------""" -# # Hackerrank4 -# -# if __name__ == '__main__': -# n = int(input()) -# student_marks = {} -# for _ in range(n): -# name, *line = input().split() -# scores = list(map(float, line)) -# student_marks[name] = scores -# query_name = input() -# not_toplam = 0 -# for i in student_marks[query_name]: -# not_toplam += i -# ortalama = f"{(not_toplam/len(student_marks[query_name])):.2f}" -# print(ortalama) +# Hackerrank4 + +if __name__ == '__main__': + n = int(input()) + student_marks = {} + for _ in range(n): + name, *line = input().split() + scores = list(map(float, line)) + student_marks[name] = scores + query_name = input() + + # The variable in which the sum of the notes is kept + scores_sum = 0 + + for i in student_marks[query_name]: + scores_sum += i + # Variable whose average values will be printed + avarage_str = f"Avarage = {(scores_sum/len(student_marks[query_name])):.2f}" + print(avarage_str) """---------------------------------------------------""" From b7b738c00c4868a645ec6137c5fb4583b426f9af Mon Sep 17 00:00:00 2001 From: Mustafa Gundogdu <103361276+mustafagundogdu80@users.noreply.github.com> Date: Sat, 28 Dec 2024 02:07:56 +0100 Subject: [PATCH 5/5] Week1.py --- Week1.py | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/Week1.py b/Week1.py index 9e0f6f4..1e62f5f 100644 --- a/Week1.py +++ b/Week1.py @@ -1,5 +1,5 @@ """ -Week 1 +Week 1 Homework """ # Question 1: Write a Python code that prints numbers from 1 to 10 on the screen. @@ -82,9 +82,10 @@ # print(digit_number) """---------------------------------------------------""" -# Question 8: Write a Python code that takes a word from the user and prints the reverse of this word on the screen. +# # Question 8: Write a Python code that takes a word from the user and prints the reverse of this word on the screen. # user_string = input("Please enter a word: ") +# # Variable to create the reverse of the string # reserve_string = "" # for i in user_string: # reserve_string = i + reserve_string @@ -136,23 +137,26 @@ # print("The largest number you enter:",largest_number) """---------------------------------------------------""" -# Question 12: Get Midterm and Final grades from a student for any course. The sum of 40% of the midterm exam grade and 60% of the final grade will give the year-end average. -# If the average is below 50, "FAILED" will appear on the screen, and if it is 50 or above, "SUCCESSFUL" will be displayed on the screen. -# This printing process is 4 lessons. and the lessons will be written one after the other. - -# courses = list() -# for i in range(4): -# course ={} -# course["id"] = i+1 -# course["name"] = input("Please enter course name: ") -# course["midterm"]= int(input("Please enter midterm exame grade: ")) -# course["final"] = int(input("Please enter final exame grade: ")) -# course["average"] = ((course["midterm"] * 0.4) + (course["final"] * 0.6)) -# if course["average"] < 50: -# course["result"]="FAILED" -# else: -# course["result"] = "SUCCESSFUL" -# courses.append(course) -# -# for i in courses: -# print(f"Student in {i["name"]} course: ",i["result"]," Avarage:",i["average"]) \ No newline at end of file +# # Question 12: Get Midterm and Final grades from a student for any course. The sum of 40% of the midterm exam grade and 60% of the final grade will give the year-end average. +# # If the average is below 50, "FAILED" will appear on the screen, and if it is 50 or above, "SUCCESSFUL" will be displayed on the screen. +# # This printing process is 4 lessons. and the lessons will be written one after the other. + +# List where courses information will be kept +courses = list() +for i in range(4): + course ={} + course["id"] = i+1 + course["name"] = input("Please enter course name: ") + course["midterm"]= int(input("Please enter midterm exame grade: ")) + course["final"] = int(input("Please enter final exame grade: ")) + course["average"] = ((course["midterm"] * 0.4) + (course["final"] * 0.6)) + if course["average"] < 50: + course["result"]="FAILED" + else: + course["result"] = "SUCCESSFUL" + courses.append(course) + +for i in courses: + print(f"Student in {i["name"]} course: ",i["result"]," Avarage:",i["average"]) + +print(courses)