Skip to content
Open

check #143

Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 10 additions & 4 deletions FunProjects/Grades.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@ def __init__(self):
self.grades = {}

def add_grade(self, student, grade):
self.grades[student] = grade
print(student,"Grade is ",self.grades[student])
if isinstance(grade, (int, float)):
self.grades[student] = grade
print(student, "Grade is", self.grades[student])
else:
print(f"Invalid grade for {student}. Grade must be a number.")

def calculate_average(self):
if not self.grades:
return 0 # Avoid division by zero
total = sum(self.grades.values())
average = total / len(self.grades)
return average

# Example Usage
# Example Usage !
grades = StudentGrades()
grades.add_grade("John", 85)
grades.add_grade("Sarah", 90)
grades.add_grade("Mike", 78)
print("Average grade:", grades.calculate_average())
print("Average grade:", grades.calculate_average())
17 changes: 9 additions & 8 deletions problems/easy/easy_q13.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Month Name: Write a program that takes a number (1-12) and prints the corresponding month name using a switch case.
def month_name(month):
switch = {
months = {
1: "January",
2: "February",
3: "March",
Expand All @@ -14,12 +13,14 @@ def month_name(month):
11: "November",
12: "December"
}

return switch.get(month)

return months.get(month, "Invalid month number")

if __name__ == "__main__":
chooseMonthNum = int(input("Enter the Month from 1 to 12: "))


return switch.get(month, "Invalid Month")
try:
chooseMonthNum = int(input("Enter the Month from 1 to 12: "))
print("Month is:", month_name(chooseMonthNum))
except ValueError:
print("Invalid input. Please enter a number.")


37 changes: 13 additions & 24 deletions problems/easy/easy_q14.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
# Vowel or Consonant: Accept a character and use a switch case to determine if it is a vowel or a consonant.
def vowel_or_consonant(char):
char=char.lower()
switch = {
'a': "Vowel",
'e': "Vowel",
'i': "Vowel",
'o': "Vowel",
'u': "Vowel",
'A': "Vowel",
'E': "Vowel",
'I': "Vowel",
'O': "Vowel",
'U': "Vowel",
}

if char in switch:
return "Vowels"
char = char.lower()
vowels = {'a', 'e', 'i', 'o', 'u'}

if len(char) != 1 or not char.isalpha():
return "Invalid input. Please enter a single alphabet letter."

if char in vowels:
return "Vowel"
else:
return "Consonant"

if __name__ == "__main__":
characterInput = input("Enter the character : ")

return switch.get(char)
characterInput = input("Enter a single alphabet character: ")
result = vowel_or_consonant(characterInput)
print("Result:", result)



return switch.get(char, "constant")


24 changes: 5 additions & 19 deletions problems/easy/easy_q15.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@

# Grade Description: Write a program that accepts a grade (A, B, C, D, F) and prints its description (e.g., A = Excellent, B = Good, etc.) using a switch case.
def grade_description(grade):
switch = {

'A': "Excellent",
'B': "Good",
'C': "Average",
'D': "Poor",
'B': "Good",
'C': "Average",
'D': "Poor",
'A': "Excellent",

'F': "Fail"


}

return switch.get(grade, "Not a valid grade")
return switch.get(grade, "Not a valid grade")

if __name__ == "__main__":

user = input("Enter grade among A,B,C,D,F *in captial:")
rs = grade_description(user)

alp = input("Enter a grade: ").upper()
rs = grade_description(alp)

print(rs)
grade_input = input("Enter a grade (A, B, C, D, F) in capital letters: ").upper()
result = grade_description(grade_input)
print(result)