Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Student average #84

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
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
Empty file.
14 changes: 14 additions & 0 deletions Desktop/Majd Readme/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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}"
}
]
}
1 change: 1 addition & 0 deletions Desktop/Majd Readme/ET6-foundations-group-16
Submodule ET6-foundations-group-16 added at 103e93
15 changes: 15 additions & 0 deletions solutions/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
13 changes: 13 additions & 0 deletions solutions/Countvowels.py
Original file line number Diff line number Diff line change
@@ -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}")
1 change: 1 addition & 0 deletions solutions/ET6-foundations-group-16
Submodule ET6-foundations-group-16 added at 99711b
15 changes: 15 additions & 0 deletions solutions/Intersection_element.py
Original file line number Diff line number Diff line change
@@ -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]
1 change: 0 additions & 1 deletion solutions/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

14 changes: 14 additions & 0 deletions solutions/employee.py
Original file line number Diff line number Diff line change
@@ -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)

68 changes: 68 additions & 0 deletions solutions/grade.py
Original file line number Diff line number Diff line change
@@ -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()
4 changes: 4 additions & 0 deletions solutions/grades.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
John 85 90 78
Alice 92 88 95
Bob 70 75 80
Carol 100 98 95
15 changes: 15 additions & 0 deletions solutions/intersection_element.py
Original file line number Diff line number Diff line change
@@ -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]
69 changes: 69 additions & 0 deletions solutions/studentGrades.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import os

Check failure on line 1 in solutions/studentGrades.py

View workflow job for this annotation

GitHub Actions / py_linting

Ruff (F401)

solutions/studentGrades.py:1:8: F401 `os` imported but unused

Check failure on line 1 in solutions/studentGrades.py

View workflow job for this annotation

GitHub Actions / py_linting

Ruff (F401)

solutions/studentGrades.py:1:8: F401 `os` imported but unused
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()
51 changes: 51 additions & 0 deletions solutions/tests/Test_countvowel.py
Original file line number Diff line number Diff line change
@@ -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

Check failure on line 5 in solutions/tests/Test_countvowel.py

View workflow job for this annotation

GitHub Actions / py_linting

Ruff (F821)

solutions/tests/Test_countvowel.py:5:9: F821 Undefined name `count_vowels_recursivelycount_vowels_recursively`

Check failure on line 5 in solutions/tests/Test_countvowel.py

View workflow job for this annotation

GitHub Actions / py_linting

Ruff (F821)

solutions/tests/Test_countvowel.py:5:9: F821 Undefined name `count_vowels_recursivelycount_vowels_recursively`
), "Test case 1 failed" # type: ignore

# Test case 2: String with no vowels
assert (
count_vowels_recursivelycount_vowels_recursively("bcdfghjklmnpqrstvwxyz") == 0

Check failure on line 10 in solutions/tests/Test_countvowel.py

View workflow job for this annotation

GitHub Actions / py_linting

Ruff (F821)

solutions/tests/Test_countvowel.py:10:9: F821 Undefined name `count_vowels_recursivelycount_vowels_recursively`

Check failure on line 10 in solutions/tests/Test_countvowel.py

View workflow job for this annotation

GitHub Actions / py_linting

Ruff (F821)

solutions/tests/Test_countvowel.py:10:9: F821 Undefined name `count_vowels_recursivelycount_vowels_recursively`
), "Test case 2 failed" # type: ignore

# Test case 3: String with only vowels
assert (
count_vowels_recursivelycount_vowels_recursively("aeiouAEIOU") == 10

Check failure on line 15 in solutions/tests/Test_countvowel.py

View workflow job for this annotation

GitHub Actions / py_linting

Ruff (F821)

solutions/tests/Test_countvowel.py:15:9: F821 Undefined name `count_vowels_recursivelycount_vowels_recursively`

Check failure on line 15 in solutions/tests/Test_countvowel.py

View workflow job for this annotation

GitHub Actions / py_linting

Ruff (F821)

solutions/tests/Test_countvowel.py:15:9: F821 Undefined name `count_vowels_recursivelycount_vowels_recursively`
), "Test case 3 failed" # type: ignore

# Test case 4: Mixed string
assert (
count_vowels_recursivelycount_vowels_recursively("hello world,") == 3

Check failure on line 20 in solutions/tests/Test_countvowel.py

View workflow job for this annotation

GitHub Actions / py_linting

Ruff (F821)

solutions/tests/Test_countvowel.py:20:9: F821 Undefined name `count_vowels_recursivelycount_vowels_recursively`

Check failure on line 20 in solutions/tests/Test_countvowel.py

View workflow job for this annotation

GitHub Actions / py_linting

Ruff (F821)

solutions/tests/Test_countvowel.py:20:9: F821 Undefined name `count_vowels_recursivelycount_vowels_recursively`
), "Test case 4 failed" # type: ignore

# Test case 5: Complex sentence
assert (
count_vowels_recursivelycount_vowels_recursively(

Check failure on line 25 in solutions/tests/Test_countvowel.py

View workflow job for this annotation

GitHub Actions / py_linting

Ruff (F821)

solutions/tests/Test_countvowel.py:25:9: F821 Undefined name `count_vowels_recursivelycount_vowels_recursively`

Check failure on line 25 in solutions/tests/Test_countvowel.py

View workflow job for this annotation

GitHub Actions / py_linting

Ruff (F821)

solutions/tests/Test_countvowel.py:25:9: F821 Undefined name `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-=")

Check failure on line 33 in solutions/tests/Test_countvowel.py

View workflow job for this annotation

GitHub Actions / py_linting

Ruff (F821)

solutions/tests/Test_countvowel.py:33:9: F821 Undefined name `count_vowels_recursivelycount_vowels_recursively`

Check failure on line 33 in solutions/tests/Test_countvowel.py

View workflow job for this annotation

GitHub Actions / py_linting

Ruff (F821)

solutions/tests/Test_countvowel.py:33:9: F821 Undefined name `count_vowels_recursivelycount_vowels_recursively`
== 0
), "Test case 6 failed" # type: ignore

# Test case 7: Single character (vowel)
assert (
count_vowels_recursivelycount_vowels_recursively("a") == 1

Check failure on line 39 in solutions/tests/Test_countvowel.py

View workflow job for this annotation

GitHub Actions / py_linting

Ruff (F821)

solutions/tests/Test_countvowel.py:39:9: F821 Undefined name `count_vowels_recursivelycount_vowels_recursively`

Check failure on line 39 in solutions/tests/Test_countvowel.py

View workflow job for this annotation

GitHub Actions / py_linting

Ruff (F821)

solutions/tests/Test_countvowel.py:39:9: F821 Undefined name `count_vowels_recursivelycount_vowels_recursively`
), "Test case 7 failed" # type: ignore

# Test case 8: Single character (non-vowel)
assert (
count_vowels_recursivelycount_vowels_recursively("b") == 0

Check failure on line 44 in solutions/tests/Test_countvowel.py

View workflow job for this annotation

GitHub Actions / py_linting

Ruff (F821)

solutions/tests/Test_countvowel.py:44:9: F821 Undefined name `count_vowels_recursivelycount_vowels_recursively`

Check failure on line 44 in solutions/tests/Test_countvowel.py

View workflow job for this annotation

GitHub Actions / py_linting

Ruff (F821)

solutions/tests/Test_countvowel.py:44:9: F821 Undefined name `count_vowels_recursivelycount_vowels_recursively`
), "Test case 8 failed" # type: ignore

print("All test cases passed!")


# Run the tests
test_count_vowels_recursively()
Loading
Loading