Browse Source

Dy 21 assignment

Mahiva 1 week ago
parent
commit
53d3b75db4
2 changed files with 110 additions and 0 deletions
  1. 105 0
      dy 21 assignment
  2. 5 0
      dy 24

+ 105 - 0
dy 21 assignment

@@ -0,0 +1,105 @@
+students=[
+    {"name": "John",
+     "course":"Computer Science",
+     "marks":78
+    },
+    {
+        "name":"Mary",
+        "course":"Information Technology",
+        "marks":91  
+    },
+    {
+        "name":"Brian",
+        "course":"Computer Science",
+        "marks":64
+    },
+    {
+        "name":"Jane",
+        "course":"Data Science",
+        "marks":85
+    },
+    {
+        "name":"David",
+        "course":"Information Technology",
+        "marks":48
+    }
+]
+
+#TASK 1
+for student in students:
+    print(student["name"])
+    
+
+#TASK 2
+for student in students:
+    if student["marks"] >= 50:
+        print(student["name"])
+        
+
+#TASK 3
+for student in students:
+    if student["marks"] >= 80:
+        print(student["name"])
+    break      
+
+#TASK 4
+for course in set(student["course"] for student in students):
+    print(course)
+
+
+#TASK 5
+for student in students:
+    student_name = student["name"]
+    student_marks = student["marks"]
+    print(f"{student_name}: {student_marks}")
+    
+
+#TASK 6
+for student in students:
+    if student["marks"] >= 80:
+        student["grade"] = "A"
+    elif student["marks"] >= 70:
+        student["grade"] = "B"
+    elif student["marks"] >= 60:
+        student["grade"] = "C"
+    elif student["marks"] >= 50:
+        student["grade"] = "D"
+    else:
+        student["grade"] = "F"
+    
+    student_name = student["name"]
+    student_grade = student["grade"]
+    print(f"{student_name}: {student_grade}")
+    
+
+#TASK 7
+for student in students:
+    average_marks = sum(student["marks"] for student in students) / len(students)
+print(f"Average Marks: {average_marks}")
+
+#TASK 8
+for student in students:
+    display_info = f"Name: {student['name']}, Course: {student['course']}, Marks: {student['marks']}, Grade: {student.get('grade', 'N/A')}"
+    print(display_info)
+    passing_students = [student for student in students if student["marks"] >= 50]
+    print(f"Passing Students: {passing_students}")
+    top_students = [student for student in students if student["marks"] >= 80]
+    print(f"Top Students: {top_students}")
+    courses = [course for course in set(student["course"] for student in students)]
+    print(f"Courses: {courses}")
+    average_marks = sum(student["marks"] for student in students) / len(students)
+    print(f"Average Marks: {average_marks}")
+    break 
+
+    #TASK 9
+    for student in students:
+        course = student["course"]
+        if course == "Computer Science":
+            print(f"{student['name']} is enrolled in Computer Science.")
+        elif course == "Information Technology":
+            print(f"{student['name']} is enrolled in Information Technology.")
+        elif course == "Data Science":
+            print(f"{student['name']} is enrolled in Data Science.")
+        else:
+            print(f"{student['name']} is enrolled in an unknown course.")
+        break

+ 5 - 0
dy 24

@@ -0,0 +1,5 @@
+numbers=[1000, 950, 600, 200, 100, 70, 50, 99]
+numbers.sort()
+print(numbers)
+numbers.sort(reverse=True)
+print(numbers)