Page 440 - Ai_V3.0_c11_flipbook
P. 440

19.   Assume marks of 30 students in a class. Write Python code to calculate and display mean, median and mode of the
                   marks.
                     import statistics
                     # Assume the marks of 30 students
                     marks = [85, 78, 92, 88, 76, 81, 90, 87, 69, 95, 77, 84, 82, 73, 91,
                              79, 85, 89, 94, 83, 74, 80, 86, 88, 77, 72, 93, 91, 78, 88]
                     # Calculate the mean
                     mean_marks = statistics.mean(marks)
                     # Calculate the median
                     median_marks = statistics.median(marks)
                     # Calculate the mode
                     mode_marks = statistics.mode(marks)
                     mode_count = marks.count(mode_marks)
                     # Display the results
                     print("Mean of the marks: ", mean_marks)
                     print("Median of the marks:", median_marks)
                     print("Mode of the marks:",mode_marks,"appears",mode_count,"times")
                   Output:
                     Mean of the marks:  83.5
                     Median of the marks: 84.5
                     Mode of the marks: 88 appears 3 times
              20.  Plot a bar chart representing the number of books sold by different genres in a bookstore:    [CBSE Handbook]
                   •  Fiction: 120 books

                   •  Mystery: 90 books
                   •  Science Fiction: 80 books
                   •  Romance: 110 books

                   •  Biography: 70 books
                     import matplotlib.pyplot as plt
                     # Data
                     genres = ['Fiction', 'Mystery', 'Science Fiction', 'Romance', 'Biography']
                     books_sold = [120, 90, 80, 110, 70]

                     # Create the bar chart
                     plt.figure(figsize=(10, 6))
                     plt.bar(genres, books_sold, color='skyblue')


                     # Add title and labels
                     plt.title('Number of Books Sold by Genre')
                     plt.xlabel('Genre')
                     plt.ylabel('Number of Books Sold')


                     # Show the plot
                     plt.show()





                    438     Touchpad Artificial Intelligence (Ver. 3.0)-XI
   435   436   437   438   439   440   441   442   443   444   445