diff --git a/# Python program to illustrate the inter.py b/# Python program to illustrate the inter.py new file mode 100644 index 000000000..e69de29bb diff --git a/Desktop/Majd Readme/.vscode/launch.json b/Desktop/Majd Readme/.vscode/launch.json new file mode 100644 index 000000000..a75c1414f --- /dev/null +++ b/Desktop/Majd Readme/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python Debugger: Python File", + "type": "debugpy", + "request": "launch", + "program": "${file}" + } + ] +} \ No newline at end of file diff --git a/Desktop/Majd Readme/ET6-foundations-group-16 b/Desktop/Majd Readme/ET6-foundations-group-16 new file mode 160000 index 000000000..103e93825 --- /dev/null +++ b/Desktop/Majd Readme/ET6-foundations-group-16 @@ -0,0 +1 @@ +Subproject commit 103e9382537cf2957d242827679ed3b1437b9185 diff --git a/solutions/.vscode/launch.json b/solutions/.vscode/launch.json new file mode 100644 index 000000000..6b76b4fab --- /dev/null +++ b/solutions/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python Debugger: Current File", + "type": "debugpy", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal" + } + ] +} \ No newline at end of file diff --git a/solutions/Countvowels.py b/solutions/Countvowels.py new file mode 100644 index 000000000..3c9a4602f --- /dev/null +++ b/solutions/Countvowels.py @@ -0,0 +1,13 @@ +def count_vowels_recursively(string): + if not string: + return 0 + else: + if string[0].lower() in "aeiou": + return 1 + count_vowels_recursively(string[1:]) + else: + return count_vowels_recursively(string[1:]) + + +input_string = "Palestinian culture is beautiful." +a = count_vowels_recursively(input_string) +print(f"Number of vowels in '{input_string}' is: {a}") diff --git a/solutions/ET6-foundations-group-16 b/solutions/ET6-foundations-group-16 new file mode 160000 index 000000000..99711bc68 --- /dev/null +++ b/solutions/ET6-foundations-group-16 @@ -0,0 +1 @@ +Subproject commit 99711bc68b56eddf692ed70109d7d66ec927ba59 diff --git a/solutions/Intersection_element.py b/solutions/Intersection_element.py new file mode 100644 index 000000000..6acdf8180 --- /dev/null +++ b/solutions/Intersection_element.py @@ -0,0 +1,15 @@ +def common_elements(list1, list2): + # Convert both lists to sets to remove duplicates and find intersection + set1 = set(list1) + set2 = set(list2) + # Find the common elements + common = set1.intersection(set2) + # Convert the result back to a list + return list(common) + + +# Example usage +list1 = [1, 2, 3, 4, 5, 6, 7] +list2 = [4, 5, 6, 7, 8, 9] +result = common_elements(list1, list2) +print(result) # Output: [4, 5, 6] diff --git a/solutions/__init__.py b/solutions/__init__.py index 8b1378917..e69de29bb 100644 --- a/solutions/__init__.py +++ b/solutions/__init__.py @@ -1 +0,0 @@ - diff --git a/solutions/employee.py b/solutions/employee.py new file mode 100644 index 000000000..eca4dd5a0 --- /dev/null +++ b/solutions/employee.py @@ -0,0 +1,14 @@ +class Employee: + raise_amt =1.05 + def __init__(self,first,last,pay): + self.first=first + self.last=last + self.pay=pay + + def email(self): + return f'{self.first}.{self.last}@email.com' + def fullname(self): + return f'{self.first}.{self.last}' + def apply_raise(self): + self.pay=int(self.pay*self.raise_amt) + \ No newline at end of file diff --git a/solutions/grade.py b/solutions/grade.py new file mode 100644 index 000000000..aacbefb17 --- /dev/null +++ b/solutions/grade.py @@ -0,0 +1,68 @@ +def loadStudentData(fileName="grades.txt"): + students = {} + with open(fileName, "r") as file: + for student in file: + parts = student.strip().split() + name = parts[0] # key : Student name + grades = list(map(int, parts[1:])) # Value: A list of grades + students[name] = grades + return students + +def viewGrades(students): + print("\nStudent and their grades:") + for name, grades in students.items(): + print(f"{name}: {', '.join(map(str, grades))}") + +def studentAverage(students, sName): + if sName in students: + average = sum(students[sName])/3 + print(f"Average grade for {sName}: {average:.2f}") + else: + print(f"Student '{sName}' not found.") + +def classStatistics(students): + if not students: + print("No data available.") + return + + listOfGrades = [] + for grades in students.values(): + listOfGrades.append(sum(grades) /3) + + overall = sum(listOfGrades) / len(listOfGrades) + averages = {name: sum(grades) / len(grades) for name, grades in students.items()} + highest = max(averages, key=averages.get) + lowest = min(averages, key=averages.get) + print(f"Class average: {overall:.2f}") + print(f"Highest average: {highest} ({sum(students[highest]) / len(students[highest]):.2f})") + print(f"Lowest average: {lowest} ({sum(students[lowest]) / len(students[lowest]):.2f})") + +def saveData(students, file_name="grades.txt"): + with open(file_name, "w") as file: + for name, grades in students.items(): + file.write(f"{name} {' '.join(map(str, grades))}\n") + +def main(): + students = loadStudentData() + while True: + print("\nWelcome to the Student Grades Management System") + print("1. View all grades") + print("2. Calculate average for a student ") + print("3. View class statistics") + print("4. Exit\n") + + choice = input("Enter your choice : ") + if choice == "1": + viewGrades(students) + elif choice == "2": + sName = input("Enter the student's name: ") + studentAverage(students, sName) + elif choice == "3": + classStatistics(students) + elif choice == "4": + saveData(students) + print("Saving data to grades.txt...\nThank you for using the Student Grades Management System. Goodbye!") + break + else: + print("Invalid choice! Please try again.") +main() diff --git a/solutions/grades.txt b/solutions/grades.txt new file mode 100644 index 000000000..fe3f1becd --- /dev/null +++ b/solutions/grades.txt @@ -0,0 +1,4 @@ +John 85 90 78 +Alice 92 88 95 +Bob 70 75 80 +Carol 100 98 95 diff --git a/solutions/intersection_element.py b/solutions/intersection_element.py new file mode 100644 index 000000000..507f49d80 --- /dev/null +++ b/solutions/intersection_element.py @@ -0,0 +1,15 @@ +def common_elements(list1, list2): + # Convert both lists to sets to remove duplicates and find intersection + set1 = set(list1) + set2 = set(list2) + # Find the common elements + common = set1.intersection(set2) + # Convert the result back to a list + return list(common) + + +# Example usage +list1 = [1, 2, 3, 4, 5, 6,7] +list2 = [4, 5, 6, 7, 8, 9] +result = common_elements(list1, list2) +print(result) # Output: [4, 5, 6] diff --git a/solutions/studentGrades.py b/solutions/studentGrades.py new file mode 100644 index 000000000..c0937f24f --- /dev/null +++ b/solutions/studentGrades.py @@ -0,0 +1,69 @@ +import os +def loadStudentData(fileName="grades.txt"): + students = {} + with open(fileName, "r") as file: + for student in file: + parts = student.strip().split() + name = parts[0] # key : Student name + grades = list(map(int, parts[1:])) # Value: A list of grades + students[name] = grades + return students + +def viewGrades(students): + print("\nStudent and their grades:") + for name, grades in students.items(): + print(f"{name}: {', '.join(map(str, grades))}") + +def studentAverage(students, sName): + if sName in students: + average = sum(students[sName])/3 + print(f"Average grade for {sName}: {average:.2f}") + else: + print(f"Student '{sName}' not found.") + +def classStatistics(students): + if not students: + print("No data available.") + return + + listOfGrades = [] + for grades in students.values(): + listOfGrades.append(sum(grades) /3) + + overall = sum(listOfGrades) / len(listOfGrades) + averages = {name: sum(grades) / len(grades) for name, grades in students.items()} + highest = max(averages, key=averages.get) + lowest = min(averages, key=averages.get) + print(f"Class average: {overall:.2f}") + print(f"Highest average: {highest} ({sum(students[highest]) / len(students[highest]):.2f})") + print(f"Lowest average: {lowest} ({sum(students[lowest]) / len(students[lowest]):.2f})") + +def saveData(students, file_name="grades.txt"): + with open(file_name, "w") as file: + for name, grades in students.items(): + file.write(f"{name} {' '.join(map(str, grades))}\n") + +def main(): + students = loadStudentData() + while True: + print("\nWelcome to the Student Grades Management System") + print("1. View all grades") + print("2. Calculate average for a student ") + print("3. View class statistics") + print("4. Exit\n") + + choice = input("Enter your choice : ") + if choice == "1": + viewGrades(students) + elif choice == "2": + sName = input("Enter the student's name: ") + studentAverage(students, sName) + elif choice == "3": + classStatistics(students) + elif choice == "4": + saveData(students) + print("Saving data to grades.txt...\nThank you for using the Student Grades Management System. Goodbye!") + break + else: + print("Invalid choice! Please try again.") +main() diff --git a/solutions/tests/Test_countvowel.py b/solutions/tests/Test_countvowel.py new file mode 100644 index 000000000..2e887521c --- /dev/null +++ b/solutions/tests/Test_countvowel.py @@ -0,0 +1,51 @@ +# Test cases for the function count_vowels_recursively +def test_count_vowels_recursively(): + # Test case 1: Empty string + assert ( + count_vowels_recursivelycount_vowels_recursively("") == 0 + ), "Test case 1 failed" # type: ignore + + # Test case 2: String with no vowels + assert ( + count_vowels_recursivelycount_vowels_recursively("bcdfghjklmnpqrstvwxyz") == 0 + ), "Test case 2 failed" # type: ignore + + # Test case 3: String with only vowels + assert ( + count_vowels_recursivelycount_vowels_recursively("aeiouAEIOU") == 10 + ), "Test case 3 failed" # type: ignore + + # Test case 4: Mixed string + assert ( + count_vowels_recursivelycount_vowels_recursively("hello world,") == 3 + ), "Test case 4 failed" # type: ignore + + # Test case 5: Complex sentence + assert ( + count_vowels_recursivelycount_vowels_recursively( + "The quick brown fox jumps over the lazy dog" + ) + == 11 + ), "Test case 5 failed" # type: ignore + + # Test case 6: String with special characters and spaces + assert ( + count_vowels_recursivelycount_vowels_recursively("!@#$%^&*()_+ 1234567890-=") + == 0 + ), "Test case 6 failed" # type: ignore + + # Test case 7: Single character (vowel) + assert ( + count_vowels_recursivelycount_vowels_recursively("a") == 1 + ), "Test case 7 failed" # type: ignore + + # Test case 8: Single character (non-vowel) + assert ( + count_vowels_recursivelycount_vowels_recursively("b") == 0 + ), "Test case 8 failed" # type: ignore + + print("All test cases passed!") + + +# Run the tests +test_count_vowels_recursively() diff --git a/solutions/tests/__init__.py b/solutions/tests/__init__.py index 8b1378917..636ae1535 100644 --- a/solutions/tests/__init__.py +++ b/solutions/tests/__init__.py @@ -1 +1,190 @@ +from math import sqrt +# Write a function that takes a sentence and returns the longest word in that sentence +s = "I am learning Python programming language" + +# Split the sentence into words +words = s.split() + +# Initialize an empty string to store the longest word +res = "" + +# Iterate through each word +for word in words: + # Update 'res' if the current word is longer than 'res' + if len(word) > len(res): + res = word + +print(res) + +# Longest word + +# Reading sentence from user + +sentence = input("Enter sentence: ") + +# Finding longest word +longest = max(sentence.split(), key=len) + +# Displaying longest word +print("Longest word is: ", longest) +print("And its length is: ", len(longest)) + + +# Function to check the Vowel +def isVowel(ch): + return ch.upper() in ["A", "E", "I", "O", "U"] + + +# to count total number of +# vowel from 0 to n +def countVovels(str, n): + if n == 1: + return isVowel(str[n - 1]) + + return countVovels(str, n - 1) + isVowel(str[n - 1]) + + +# Driver Code + +# string object +str = "abc de" +# Total numbers of Vowel +print(countVovels(str, len(str))) + + +def count_vowels_recursively(string): + if not string: + return 0 + else: + if string[0].lower() in "aeiou": + return 1 + count_vowels_recursively(string[1:]) + else: + return count_vowels_recursively(string[1:]) + + +input_string = "Palestinian culture is beautiful." +a = count_vowels_recursively(input_string) +print(f"Number of vowels in '{input_string}' is: {a}") + +# Different Sizes using Sorting + + +def medianOf2(a, b): + # Merge both the arrays + c = a + b + + # Sort the concatenated array + c.sort() + + len_c = len(c) + + # If length of array is even + if len_c % 2 == 0: + return (c[len_c // 2] + c[len_c // 2 - 1]) / 2.0 + + # If length of array is odd + else: + return c[len_c // 2] + + +if __name__ == "__main__": + a = [-5, 3, 6, 12, 15, 44] + b = [-12, -10, -6, -3, 21, 10] + + print(medianOf2(a, b)) + +# write a code that return a list of the elements that are common to both lists, without duplicates. +a = [1, 2, 3, 4, 5] +b = [4, 5, 6, 7, 8] + +# Find common elements using nested loops +common = [] +for x in a: + if x in b: + common.append(x) + +print(common) + + +# Given a positive integer, determine if it is a prime number +# (a number greater than 1 that has no divisors other than 1 +# and itself). +# prime function to check given number prime or not +def Prime(number, itr): + # base condition + if itr == 1 or itr == 2: + return True + # if given number divided by itr or not + if number % itr == 0: + return False + # Recursive function Call + if Prime(number, itr - 1) == False: + return False + + return True + + +num = 14 + +itr = int(sqrt(num) + 1) + +print(Prime(num, itr)) + +# Python program to find the factorial of a number provided by the user. + +# change the value for a different result +num = 6 + +# To take input from the user +# num = int(input("Enter a number: ")) + +factorial = 1 + +# check if the number is negative, positive or zero +if num < 0: + print("Sorry, factorial does not exist for negative numbers") +elif num == 0: + print("The factorial of 0 is 1") +else: + for i in range(1, num + 1): + factorial = factorial * i + print("The factorial of", num, "is", factorial) + + # Python program to find the factorial of a number provided by the user +# using recursion + + +def factorial(x): + """This is a recursive function + to find the factorial of an integer""" + + if x == 1 or x == 0: + return 1 + else: + # recursive call to the function + return x * factorial(x - 1) + + +# change the value for a different result +num = 8 + +# to take input from the user +# num = int(input("Enter a number: ")) + +# call the factorial function +result = factorial(num) +print("The factorial of", num, "is", result) + + +# Python program to illustrate the intersection +# of two lists in most simple way +def intersection(lst1, lst2): + lst3 = [value for value in lst1 if value in lst2] + return lst3 + + +# Driver Code +lst1 = [4, 9, 1, 17, 11, 26, 28, 54, 69] +lst2 = [9, 9, 74, 21, 45, 11, 63, 28, 26] +print(intersection(lst1, lst2)) diff --git a/solutions/tests/test_employee.py b/solutions/tests/test_employee.py new file mode 100644 index 000000000..b18e590f3 --- /dev/null +++ b/solutions/tests/test_employee.py @@ -0,0 +1,58 @@ +import unittest +import sys +import os +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) +from ..employee import Employee + +class TestEmployee(unittest.TestCase): + def setUp(self): + self.emp_1=Employee('Majd','Soud',50000) + self.emp_2=Employee('Scott','Edan',90000) + + def test_employee_pay(self): + self.assertEqual(self.emp_1.pay,50000) + self.assertEqual(self.emp_2.pay,90000) + + def tearDown(self): + pass + + def test_email(self): + self.assertEqual(self.emp_1.email(),'Majd.Soud@email.com') + self.assertEqual(self.emp_2.email(),'Scott.Edan@email.com') + self.emp_1.first='Jhone' + self.emp_2.first='Jane' + self.assertEqual(self.emp_1.email(),'Jhone.Soud@email.com') + self.assertEqual(self.emp_2.email(),'Jane.Edan@email.com') + + def test_fullname(self): + self.assertEqual(self.emp_1.fullname(),'Majd.Soud') + self.assertEqual(self.emp_2.fullname(),'Scott.Edan') + + self.emp_1.first='John' + self.emp_2.first='Jane' + + self.assertEqual(self.emp_1.fullname(),'John.Soud') + self.assertEqual(self.emp_2.fullname(),'Jane.Edan') + + def test_apply_raise(self): + self.emp_1=Employee('Majd','Soud',50000) + self.emp_2=Employee('Scott','Edan',90000) + + self.emp_1.apply_raise() + self.emp_2.apply_raise() + + self.assertEqual(self.emp_1.pay,52500) + self.assertEqual(self.emp_2.pay,94500) + +if __name__== '__main__': + unittest.main() + + + + + + + + + + diff --git a/solutions/tests/test_grade.py b/solutions/tests/test_grade.py new file mode 100644 index 000000000..2e9b9bc4e --- /dev/null +++ b/solutions/tests/test_grade.py @@ -0,0 +1,54 @@ +#from ..grade import classStatistics, loadStudentData, saveData, studentAverage, viewGrades +import sys +import os +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) +from grade import classStatistics, loadStudentData, saveData, studentAverage, viewGrades +import unittest +def test_loadStudentData(): + students = loadStudentData("grades.txt") + assert students == { + "Alice": [90, 85, 88], + "Bob": [78, 82, 80], + "Charlie": [92, 91, 94] + }, f"Test failed for loadStudentData" + +def test_viewGrades(): + students = { + "Alice": [90, 85, 88], + "Bob": [78, 82, 80] + } + # Check the printed output manually by running viewGrades function + viewGrades(students) + +def test_studentAverage(): + students = { + "Alice": [90, 85, 88], + "Bob": [78, 82, 80] + } + # Test for existing student + studentAverage(students, "Alice") # Expected output: 87.67 + # Test for non-existing student + studentAverage(students, "David") # Expected output: "Student 'David' not found." + +def test_classStatistics(): + students = { + "Alice": [90, 85, 88], + "Bob": [78, 82, 80], + "Charlie": [92, 91, 94] + } + classStatistics(students) + +def test_saveData(): + students = { + "Alice": [90, 85, 88], + "Bob": [78, 82, 80] + } + saveData(students, "grades.txt") + +# Run all tests +test_loadStudentData() +test_viewGrades() +test_studentAverage() +test_classStatistics() +test_saveData() + diff --git a/solutions/tests/test_grade_student.py b/solutions/tests/test_grade_student.py new file mode 100644 index 000000000..48647e77e --- /dev/null +++ b/solutions/tests/test_grade_student.py @@ -0,0 +1,52 @@ +from studentGrades import classStatistics, loadStudentData, saveData, studentAverage, viewGrades +import unittest +def test_loadStudentData(): + students = loadStudentData("test_grades.txt") + assert students == { + "Alice": [90, 85, 88], + "Bob": [78, 82, 80], + "Charlie": [92, 91, 94] + }, f"Test failed for loadStudentData" + +def test_viewGrades(): + students = { + "Alice": [90, 85, 88], + "Bob": [78, 82, 80] + } + # Check the printed output manually by running viewGrades function + viewGrades(students) + +def test_studentAverage(): + students = { + "Alice": [90, 85, 88], + "Bob": [78, 82, 80] + } + # Test for existing student + studentAverage(students, "Alice") # Expected output: 87.67 + # Test for non-existing student + studentAverage(students, "David") # Expected output: "Student 'David' not found." + +def test_classStatistics(): + students = { + "Alice": [90, 85, 88], + "Bob": [78, 82, 80], + "Charlie": [92, 91, 94] + } + classStatistics(students) + +def test_saveData(): + students = { + "Alice": [90, 85, 88], + "Bob": [78, 82, 80] + } + saveData(students, "test_grades.txt") + +# Run all tests +test_loadStudentData() +test_viewGrades() +test_studentAverage() +test_classStatistics() +test_saveData() + +if __name__ == "__main__": + unittest.main() \ No newline at end of file diff --git a/solutions/tests/test_intersection.py b/solutions/tests/test_intersection.py new file mode 100644 index 000000000..f0ca1086b --- /dev/null +++ b/solutions/tests/test_intersection.py @@ -0,0 +1,42 @@ +def test_common_elements(): + # Test case 1: Common elements exist + list1 = [1, 2, 3, 4, 5] + list2 = [4, 5, 6, 7, 8] + assert sorted(common_elements(list1, list2)) == [4, 5], "Test case 1 failed" # type: ignore + + # Test case 2: No common elements + list1 = [1, 2, 3] + list2 = [4, 5, 6] + assert common_elements(list1, list2) == [], "Test case 2 failed" # type: ignore + + # Test case 3: Identical lists + list1 = [1, 2, 3, 4, 5] + list2 = [1, 2, 3, 4, 5] + assert sorted(common_elements(list1, list2)) == [ + 1, + 2, + 3, + 4, + 5, + ], "Test case 3 failed" # type: ignore + + # Test case 4: One list is empty + list1 = [] + list2 = [1, 2, 3] + assert common_elements(list1, list2) == [], "Test case 4 failed" # type: ignore + + # Test case 5: Both lists are empty + list1 = [] + list2 = [] + assert common_elements(list1, list2) == [], "Test case 5 failed" # type: ignore + + # Test case 6: Lists with duplicate elements + list1 = [1, 2, 2, 3, 4] + list2 = [3, 3, 4, 5, 6] + assert sorted(common_elements(list1, list2)) == [3, 4], "Test case 6 failed" # type: ignore + + print("All test cases passed!") + + +# Run the tests +test_common_elements() diff --git a/solutions/tests/test_intersection_element.py b/solutions/tests/test_intersection_element.py new file mode 100644 index 000000000..5bd11862d --- /dev/null +++ b/solutions/tests/test_intersection_element.py @@ -0,0 +1,68 @@ +# Write Python 3 code in this online + + +def common_elements(list1, list2): + # Convert both lists to sets to remove duplicates and find intersection + set1 = set(list1) + set2 = set(list2) + # Find the common elements + common = set1.intersection(set2) + # Convert the result back to a list + return list(common) + + +# Example usage +list1 = [1, 2, 3, 4, 5, 6] +list2 = [4, 5, 6, 7, 8, 9] +result = common_elements(list1, list2) +print(result) # Output: [4, 5, 6] + +# Example usage +list1 = [1, 2, 3, 4, 5, 6] +list2 = [4, 5, 6, 7, 8, 9] +result = common_elements(list1, list2) # type: ignore +print(result) # Output: [4, 5, 6] + + +def test_common_elements(): + # Test case 1: Common elements exist + list1 = [1, 2, 3, 4, 5] + list2 = [4, 5, 6, 7, 8] + assert sorted(common_elements(list1, list2)) == [4, 5], "Test case 1 failed" # type: ignore + + # Test case 2: No common elements + list1 = [1, 2, 3] + list2 = [4, 5, 6] + assert common_elements(list1, list2) == [], "Test case 2 failed" # type: ignore + + # Test case 3: Identical lists + list1 = [1, 2, 3, 4, 5] + list2 = [1, 2, 3, 4, 5] + assert sorted(common_elements(list1, list2)) == [ + 1, + 2, + 3, + 4, + 5, + ], "Test case 3 failed" # type: ignore + + # Test case 4: One list is empty + list1 = [] + list2 = [1, 2, 3] + assert common_elements(list1, list2) == [], "Test case 4 failed" # type: ignore + + # Test case 5: Both lists are empty + list1 = [] + list2 = [] + assert common_elements(list1, list2) == [], "Test case 5 failed" # type: ignore + + # Test case 6: Lists with duplicate elements + list1 = [1, 2, 2, 3, 4] + list2 = [3, 3, 4, 5, 6] + assert sorted(common_elements(list1, list2)) == [3, 4], "Test case 6 failed" # type: ignore + + print("All test cases passed!") + + +# Run the tests +test_common_elements()