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

'''
                       num = int(input("Enter a number: "))

                       if num < 0:
                           print("Factorial is not defined for negative numbers.")
                       else:
                           factorial = 1
                           for i in range(1, num + 1):

                               factorial *= i
                           print(f"Factorial of {num} is {factorial}")
                   while True:
                       print("\nMenu:")
                       print("1. Square Root of a number")

                       print("2. GCD of two numbers")
                       print("3. Factorial of a number")
                       print("4. Exit")
                       choice = input("Enter your choice (1/2/3/4): ")
                       if choice == '1':

                           calculateSquareRoot()
                       elif choice == '2':
                           calculateGCD()
                       elif choice == '3':
                           calculateFactorial()

                       elif choice == '4':
                           print("Exiting the program.")
                           break
                       else:
                           print("Invalid choice. Please select a valid option.")

               Program 31: Consider a string blessing  =  'Stay  Happy  n  Healthy'. For each of the five rows of the
               following table, write the appropriate slicing statement in the space provided in the table that produces the output
               given in the second column.

              Assume the string blessing is defined as follows:

              blessing = 'Stay Happy n Healthy'
                   Verified Command

                   blessing[:6]
                   blessing[2:10:4]
                   blessing[3:10]
                   blessing[-1::-1]
                   blessing[-3:-12:-2]






               508   Touchpad Computer Science (Ver. 2.0)-XI
   517   518   519   520   521   522   523   524   525   526   527