Page 242 - Computer Science V2.0 Class 11
P. 242

elif choice == 4:
                            radius = float(input("Enter the radius of the circle: "))
                            area = computeCircleArea(radius)
                            circumference = computeCircleCircumference(radius)
                            print("Area of Circle:", area)
                            print("Circumference of Circle:", circumference)

                        elif choice == 5:
                            radius = float(input("Enter the radius of the cylinder: "))
                            height = float(input("Enter the height of the cylinder: "))
                            surfaceArea = computeCylinderSurfaceArea(radius, height)
                            print("Surface Area of Cylinder:", surfaceArea)

                        elif choice == 6:
                            break

                        else:
                            print("Invalid shape choice. Please provide input again!")
                 8.  Write a program that creates a GK quiz consisting of any five questions of your choice. The questions should be displayed randomly.
                    Create a user defined function score() to calculate the score of the quiz and another user defined function remark (scorevalue) that
                    accepts the final score to display remarks as follows:
                     Marks       Remarks
                     5           Outstanding
                     4           Excellent
                     3           Good
                     2           Read more to score more
                     1           Needs to take interest
                     0           General knowledge will always help you. Take it seriously.
               Ans.
                    import random
                    questionsAndAnswers=\
                    {
                        "What is the capital of India?": "Delhi",
                        "Who wrote 'Romeo and Juliet'?": "William Shakespeare",
                        "What is the largest mammal in the world?": "Blue Whale",
                        "Which planet is known as the Red Planet?": "Mars",
                        "What is the chemical symbol for gold?": "Au",
                        "Who painted the Mona Lisa?": "Leonardo da Vinci",
                        "What is the powerhouse of the cell?": "Mitochondria",
                        "Which year did Christopher Columbus first reach the Americas?": "1492",
                        "What is the currency of Japan?": "Yen",
                        "Who is the author of 'To Kill a Mockingbird'?": "Harper Lee"
                    }

                    # Function to create a GK quiz with five random questions
                    def createQuiz():
                        quizQuestions = random.sample(list(questionsAndAnswers.keys()), 5)
                        return quizQuestions


               228   Touchpad Computer Science (Ver. 2.0)-XI
   237   238   239   240   241   242   243   244   245   246   247