diff --git a/Asem_Answers_Week1_in_team.py b/Asem_Answers_Week1_in_team.py new file mode 100644 index 0000000..41d7b4b --- /dev/null +++ b/Asem_Answers_Week1_in_team.py @@ -0,0 +1,222 @@ +# Q1: Write a Python code that prints numbers from 1 to 10 on the screen. + +for i in range(1, 11): + print(i) + +# Q2: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_input = input('Please Enter Number') +i=0 +for i in range(i,int(user_input)): + if i%2 == 0: + print(i) + +i = 0 +user_input = input('Please Enter Number') +while i <= int(user_input): + if i == 0 : + print(i) + i += 1 + if i%2 == 0 : + if i > int (user_input): + break + print(i) + +# Q3: 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 = input('Enter a start Number ') +End_Value = input('Enter an End Number') +if int(Start_Value) > int(End_Value): + print("End Number Should be Biger Than Start Number ") + Start_Value = input('Enter a start Number ') + End_Value = input('Enter an End Number') + x = range(int(Start_Value), int(End_Value) + 1) + for n in x: + print(n) +else: + x = range(int(Start_Value), int(End_Value) + 1) + for n in x: + print(n) + +# Q4: Get a number from the user and write a Python code that prints whether this number is odd or even +user_input = int(input('Inter integer number')) +if user_input % 2 == 0 : + print("This Number is Even") +else: + print('This Number is Odd') + +# Q5: 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 +number = int(input("Enter a positive integer to calculate its factorial: ")) +factorial = 1 +i = 1 +while i <= number: + factorial *= i + i += 1 +print("The factorial of", number , " is:", factorial) + +# Q6: Write a Python code that receives a number from the user and checks whether this number is prime. +num = int (input("Insert Positive integer Number")) +if num < 0: + print("The Number in negative , inter a positive Number " ) +elif num == 0 or num == 1 : + print(num, "is not a prime number") +elif num > 1: + # check for factors + for i in range(2, num): + if (num % i) == 0: + print(num, "is not a prime number") + + break + else: + print(num, "is a prime number") + +# Q7: How to create a loop that calculates the Fibonacci sequence +# and returns the result as a list containing numbers up to a certain limit? +Num_terms = int(input("How many terms? ")) + +# first two terms +x = 0 +y = 1 + +num_list =[x] +# check if the number of terms is valid +if Num_terms <= 0: + print("Please enter a positive integer") +# if there is only one term, return n1 +elif Num_terms == 1: + print("Fibonacci sequence upto",Num_terms,":",num_list) + +# generate fibonacci sequence +else: + num_list = [x,y] + count=2 + while count < Num_terms: + z = x + y + num_list.append(z) + # update values + x = y + y = z + count +=1 + print("Fibonacci sequence upto",Num_terms,":",num_list) + +# Q8: Write a Python code that takes a word from the user and prints the reverse of this word on the screen. +word = input("Input a word to reverse: ") +for char in range(len(word) - 1, -1, -1): + # Print each character from the word in reverse order without a new line (end="") + print(word[char], end="") + +# Q9: 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)? +word = input("Inter a word to check if it is palindrome ") +first = 0 +length = len(word) +last = length +half = int(length/ 2) + +while half > 0 : + if word[first] != word[last-1]: + print("This word is not palindrome") + + break + first += 1 + last -= 1 + half -= 1 +if half <= 1: + print("This word is a palindrome") + + #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. + +kg = float(input("Please enter your weight in Kg and more than zero ")) +while kg <= 0 : + kg = float(input("Please re-enter your weight in Kg and more than zero")) + +le = float(input('Please enter your height in M and more than zero')) +while le <= 0 : + le = float(input('Please re-enter your height in M and more than zero ')) + +bmi = le / (kg *kg) +if bmi > 40 :(print("You are Highly overweight.")) +elif bmi > 30 : + print('You are Overweight.') +elif bmi >= 25 : + print('Your Weight is Normal ') +else: print(' You are underweight ') + +# Q 11: How to write a Python program that finds the largest of three numbers +# entered by a user? +x = float(input("put the first num" )) +y = float(input("put the second num" )) +z= float(input("put the third num" )) +largest = x +if y >= x : + largest = y + if y <= z : + largest = z +elif x<= z: + largest = z +print("The largest Num is :", largest) + +# Q12: 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, "CSUCESSFUL" will be displayed on the screen. +# This printing process is 4 lessons. +# and the lessons will be written one after the other. + +eng_res = "" +math_res = "" +his_res = "" +geo_res = "" +md_E = -1 +while md_E not in range (0,100): + md_E = float(input('Enter the student Midterm English grades')) +fl_E = -1 +while fl_E not in range (0,101): + fl_E = float(input('Enter the student English Final grades')) +if (md_E * 0.4 + fl_E *0.6) >= 50 : + eng_res= "Passed" +else: + eng_res= 'Failed' +md_E = -1 +while md_E not in range (0,100): + md_E = float(input('Enter the student Midterm Math grades')) +fl_E = -1 +while fl_E not in range (0,101): + fl_E = float(input('Enter the student Math Final grades')) +if (md_E * 0.4 + fl_E *0.6) >= 50 : + math_res= "Passed" +else: + math_res= 'Failed' +md_E = -1 +while md_E not in range (0,100): + md_E = float(input('Enter the student Midterm History grades')) +fl_E = -1 +while fl_E not in range (0,101): + fl_E = float(input('Enter the student Final History grades')) +if (md_E * 0.4 + fl_E *0.6) >= 50 : + his_res= "Passed" +else: + his_res= 'Failed' +md_E = -1 +while md_E not in range (0,100): + md_E = float(input('Enter the student Midterm Geography grades')) +fl_E = -1 +while fl_E not in range (0,101): + fl_E = float(input('Enter the student Final Geography grades')) +if (md_E * 0.4 + fl_E *0.6) >= 50 : + geo_res= "Passed" +else: + geo_res= 'Failed' +print("English Result is:",eng_res,"\nMath Result is:",math_res,"\nHistory result is:",his_res,"\nGeography Result is:",geo_res) + diff --git a/Week_1_Answers.py b/Week_1_Answers.py new file mode 100644 index 0000000..009fa21 --- /dev/null +++ b/Week_1_Answers.py @@ -0,0 +1,3 @@ +# Write a Python code that prints numbers from 1 to 10 on the screen. +for i in range(1, 11): + print(i) \ No newline at end of file diff --git a/Welcome_to_Colab.ipynb b/Welcome_to_Colab.ipynb new file mode 100644 index 0000000..a39f54a --- /dev/null +++ b/Welcome_to_Colab.ipynb @@ -0,0 +1,37 @@ +#The list: +students=[{'name':'Ahmet','sname':'yilmaz','mid':85,'final':90,'oral':75,'GPA':0}, + {'name':'Mehmit','sname':'Dimer','mid':92,'final':88,'oral':76,'GPA':0}, + {'name':'Ayse','sname':'Kaya','mid':78,'final':89,'oral':95,'GPA':0}, + {'name':'Zynep','sname':'Celik','mid':65,'final':70,'oral':80,'GPA':0}, + {'name':'Ali','sname':'Kara','mid':50,'final':60,'oral':55,'GPA':0}, + {'name':'Fatma','sname':'Yildiz','mid':88,'final':85,'oral':90,'GPA':0}, + {'name':'Murat','sname':'Aydin','mid':72,'final':68,'oral':74,'GPA':0}, + {'name':'Elif','sname':'Aksoy','mid':95,'final':90,'oral':88,'GPA':0}, + {'name':'Hakan','sname':'Ozturk','mid':45,'final':50,'oral':55,'GPA':0}, + {'name':'Canan','sname':'Tas','mid':80,'final':75,'oral':82,'GPA':0}] +#The answers: +#The first requirement(Calculate each student's GPA and add it to the dictionary): +for i in range(len(students)): + GPA=(students[i]['mid']+students[i]['final']+students[i]['oral'])/3 + students[i]['GPA']=GPA + print(students[i]) +##The second requirement(Find the student with the highest GPA and print it on the screen): +maxGPA=max(students,key=lambda x:x['GPA']) +print(maxGPA) +print(maxGPA['name'],maxGPA['sname'],maxGPA['GPA'],maxGPA['mid'],maxGPA['final'],maxGPA['oral']) +student_data = [] +for student in students: + student_data.append((student['name'], student['sname'])) + +student_data +#The Third and fourth requirements(Sort students by name and surname alphabetically)and(Separate each student's name from their surname and store them in a separate tuple and add them to a list): +sorted_students = sorted(students, key=lambda student: (student['name'], student['sname'])) + +#The fifth requirement(Keep students with a GPA below 70 in a cluster): +for student in sorted_students: + print(f"{student['name']},{student['sname']}") +low_gpa_students = set() +for student in students: + if student['GPA'] < 70: + low_gpa_students.add(student['name']) +low_gpa_students diff --git a/zahid_team_leader_week1_question1.py b/zahid_team_leader_week1_question1.py new file mode 100644 index 0000000..79ebf74 --- /dev/null +++ b/zahid_team_leader_week1_question1.py @@ -0,0 +1,4 @@ +#Question #1 +i=0 +for i in range(1,13): + print(i) \ No newline at end of file diff --git a/zahid_team_leader_week1_question10.py b/zahid_team_leader_week1_question10.py new file mode 100644 index 0000000..bae72cf --- /dev/null +++ b/zahid_team_leader_week1_question10.py @@ -0,0 +1,15 @@ +#Question no 10 + +weight = int(input('Please Enter Weight')) +height = int(input('Please Enter Height in cm')) +# convert cm to meters +meter = height/100 +BMI = round(weight/(meter**2)) +if(BMI < 25): + print("You are Week!") +elif(BMI >= 25 and BMI <= 30): + print("You are Normal!") +elif(BMI > 30 and BMI <= 40): + print("You are over weight!") +else: + print("You are obese weight!") diff --git a/zahid_team_leader_week1_question11.py b/zahid_team_leader_week1_question11.py new file mode 100644 index 0000000..97cda79 --- /dev/null +++ b/zahid_team_leader_week1_question11.py @@ -0,0 +1,11 @@ +#Question no 11 + +number1 = int(input('Please Enter first number')) +number2 = int(input('Please Enter 2nd number')) +number3 = int(input('Please Enter 3rd number')) +if number1 > number2 and number1 > number3: + print("number1 is Largest ") +elif number2 > number1 and number2 > number3: + print("number2 is Largest ") +else: + print("Number2 is Largest") diff --git a/zahid_team_leader_week1_question12.py b/zahid_team_leader_week1_question12.py new file mode 100644 index 0000000..ace3554 --- /dev/null +++ b/zahid_team_leader_week1_question12.py @@ -0,0 +1,11 @@ +#Question no 12 + +for i in range(1,5): + seconde_term = float(input(f"Enter midterm grade Subject {i}:")) + final_term = float(input(f"Enter final term grade {i}:")) + average_marks_subject = (seconde_term * 0.4) + (final_term * 0.6) + if average_marks_subject >= 50: + final_result = "SUCCESSFUL" + else: + final_result = "FAILED" + print(f"Averege Marks{average_marks_subject:.2f} Result {final_result}") diff --git a/zahid_team_leader_week1_question2.py b/zahid_team_leader_week1_question2.py new file mode 100644 index 0000000..8522d7e --- /dev/null +++ b/zahid_team_leader_week1_question2.py @@ -0,0 +1,10 @@ +#Quesion #2 +user_input = input('Please Enter Number') +i = 1 +for i in range(i,int(user_input)): + if i%2 == 0: + print(i) +while i <= int(user_input): + i += 1 + if i%2 == 0: + print(i) diff --git a/zahid_team_leader_week1_question3.py b/zahid_team_leader_week1_question3.py new file mode 100644 index 0000000..b01b193 --- /dev/null +++ b/zahid_team_leader_week1_question3.py @@ -0,0 +1,9 @@ +#Question #3 +value1 = int(input('Please Enter First Number')) +value2 = int(input('Please Enter 2nd Number')) +if value1 > value2: + print("Error! Please Enter Valid first Value should less the 2nd value") +else: + while value1 < value2: + value1 += 1 + print(value1) \ No newline at end of file diff --git a/zahid_team_leader_week1_question4.py b/zahid_team_leader_week1_question4.py new file mode 100644 index 0000000..e241d40 --- /dev/null +++ b/zahid_team_leader_week1_question4.py @@ -0,0 +1,6 @@ +# Question #4 +value1 = int(input('Please Enter Number')) +if value1 % 2 == 0: + print('Even Number') +else: + print("Odd Number") \ No newline at end of file diff --git a/zahid_team_leader_week1_question5.py b/zahid_team_leader_week1_question5.py new file mode 100644 index 0000000..d24c73c --- /dev/null +++ b/zahid_team_leader_week1_question5.py @@ -0,0 +1,7 @@ +#Question #5 + +number = int(input('Please Enter Number')) +factorial = 1 +for i in range(2, number + 1): + factorial *= i +print(factorial) diff --git a/zahid_team_leader_week1_question6.py b/zahid_team_leader_week1_question6.py new file mode 100644 index 0000000..75fa57e --- /dev/null +++ b/zahid_team_leader_week1_question6.py @@ -0,0 +1,8 @@ +# Question # 6 +value1=int(input('enter the number')) +for i in range(2, int(value1**0.5) + 1): + if value1 % i == 0: + print(str(value1)+" Not a Prime number ") + break +print(str(value1)+" Not a Prime number ") +# Need To bit discuss diff --git a/zahid_team_leader_week1_question7.py b/zahid_team_leader_week1_question7.py new file mode 100644 index 0000000..88bbefc --- /dev/null +++ b/zahid_team_leader_week1_question7.py @@ -0,0 +1,11 @@ +#Question # 7 +number = int(input('Please Enter Number')) +i=0 +numer_calc = 0 +add_number = 1 +while i < number: + final_number = numer_calc + add_number + print(numer_calc) + numer_calc = add_number + add_number = final_number + i += 1 \ No newline at end of file diff --git a/zahid_team_leader_week1_question8.py b/zahid_team_leader_week1_question8.py new file mode 100644 index 0000000..68db842 --- /dev/null +++ b/zahid_team_leader_week1_question8.py @@ -0,0 +1,8 @@ +#Question no 8 + +text = input('Please Enter Word') +tlen = len(text) - 1 +new_text = '' +for i in range(tlen, -1, -1): + new_text = new_text+text[i] +print(new_text) \ No newline at end of file diff --git a/zahid_team_leader_week1_question9.py b/zahid_team_leader_week1_question9.py new file mode 100644 index 0000000..ac05275 --- /dev/null +++ b/zahid_team_leader_week1_question9.py @@ -0,0 +1,8 @@ +#Question no 9 + +text = input('Please Enter Word') +revers_word = text[::-1] +if text == revers_word: + print("word is a palindrome") +else: + print("word is Not a palindrome") \ No newline at end of file