Page 58 - PYTHON-11
P. 58

Ans.  (a)  Spyware
                (b)  Email Spoofing
                (c)  Email Filtering and Scanning Software
                (d)  Antivirus Software
                (e)  Blocking IP addresses using Firewall or Network Filter
            37.  Write a menu-driven Python program that takes user inputs for required parameters and performs the following
               operations:                                                                                  [5]
                (a)  Square of a number
                (b)  Cube of a number
                (c)  Square root of a number
                (d)  Prime number check
                (e)  Exit

           Ans.  import math
               while True:
                     print("\nMenu:")
                     print("1. Square")
                     print("2. Cube")
                     print("3. Square Root")
                     print("4. Prime Number Check")
                     print("5. Exit")
               ch = int(input("Enter your choice (1-5): "))
               if ch == 5:
                     print("Exiting the program.")
                     break
               num = int(input("Enter a number: "))
               if ch == 1:
                     print("Square:", num ** 2)
               elif ch == 2:
                     print("Cube:", num ** 3)
               elif ch == 3:
                     if num >= 0:
                     print("Square Root:", round(math.sqrt(num), 2))
               else:
                     print("Cannot compute square root of a negative number.")
               elif ch == 4:
                     if num < 2:
                     print("Not Prime")
               else:
                     for i in range(2, int(num ** 0.5) + 1):
                            if num % i == 0:
                                   print("Not Prime")
                                          break
               else:
                     print("Prime")
               else:
                     print("Invalid choice. Please select from 1 to 5.")

                                                           M.7
   53   54   55   56   57   58   59   60   61   62   63