Page 443 - Computer Science Class 11 With Functions
P. 443

print(f"GCD of {num1} and {num2} is {gcd}")


                 def calculateFactorial():
                     '''
                     Objective : To calculate the factorial of a number

                     Input Parameter : None
                     Return Value : None
                     '''
                     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'


                                                                                                      Practical  441
   438   439   440   441   442   443   444   445   446   447   448