Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 127 - 2607_Trackpad_Pro_5.1_flipbook_C7
P. 127

    4.  In a bank, if the withdrawal amount is more than the balance, the system denies the transaction.
                      Otherwise, it proceeds. Write a program using if-else to check this.
                  5.  A treasure chest opens only if the code is divisible by 3. Write a program using if-else to check if
                      the entered code unlocks the chest.

                  6.  Below is a code snippet that determines if someone is eligible to vote:

                      age = 15
                      if age >= 18:
                          print(“You are eligible to vote.”)

                      else:
                          print(“You are not eligible to vote.”)

                      Modify the code to take user input for age and then check if the person is eligible to vote.
                  7.  Study the following code that assigns a grade based on marks:
                      marks = 72

                      if marks >= 90:
                          print(“Grade: A”)

                      elif marks >= 70:
                          print(“Grade: B”)
                      else:

                          print(“Grade: C”)
                      Write the output of the above code. Then, modify the code to add one more condition for marks
                      between 50 and 69 that should print Grade: C.
                  8.  Given below a simple nested if example to check if a number is positive, negative, or zero:

                      number = -5
                      if number >= 0:
                          if number == 0:

                              print(“The number is zero.”)
                          else:
                              print(“The number is positive.”)
                      else:

                          print(“The number is negative.”)
                      Explain the role of the nested if statement in this code. What will the output be if the value of
                      number is 0?

                  Chapter 9: Future of Artificial Intelligence

                  1.  Rohan  lives  in  a  large  residential  community  where  thefts  have  recently  increased.  The
                      management installed AI-enabled CCTV systems. How would these AI systems help detect
                      unusual activities, alert residents like Rohan in real-time, and improve safety?

                      126   Premium Edition-VII

| 122 123 124 125 126 127 128 129 130 131 132 |