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

else:
                              discountPercentage = 0  # No discount for amounts below 500

                          # Additional 5% discount for store members
                          if isMember:
                              discountPercentage += 5

                          # Calculate discount amount
                          discountAmount = (discountPercentage / 100) * shoppingAmount

                          # Calculate net amount payable
                          netPayable = shoppingAmount - discountAmount

                          return discountAmount, netPayable

                      # Example usage
                      shoppingAmount = float(input("Enter the shopping amount: "))
                      isMember = input("Are you a store member? (yes/no): ").lower() == "yes"

                      if isMember == 'yes':
                          isMember = True
                      discount, netPayable = calculateDiscount(shoppingAmount, isMember)

                      print("Discount:", discount)
                      print("Net Amount Payable:", netPayable)
                    3.  ‘Play and learn’ strategy helps toddlers understand concepts in a fun way. Being a senior student you have taken responsibility to develop
                      a program using user defined functions to help children master two and three-letter words using English alphabets and addition of single
                      digit numbers. Make sure that you perform a careful analysis of the type of questions that can be included as per the age and curriculum.
                  Ans.
                      import random
                      def generateWordQuestion():
                          # List of two and three-letter words
                          words = ["cat", "dog", "bat", "sun", "cup", "pen", "hat", "bus", "run"]
                          # Randomly select a word
                          word = random.choice(words)
                          return "What is the word " +word.capitalize()

                      num1, num2 = 0, 0
                      def generateAdditionQuestion():
                          global num1, num2
                          # Generate two random single-digit numbers
                          num1 = random.randint(1, 9)
                          num2 = random.randint(1, 9)
                          return "What is " + str(num1) +"+" + str(num2)

                      def playAndLearnGame():
                          # Welcome message
                          print("Welcome to Play and Learn!")


                                                                                             Introduction to Functions  221
   230   231   232   233   234   235   236   237   238   239   240