Page 627 - ComputerScience_Class_11
P. 627

The output of the preceding program is as follows:

                     Output

                  Menu:
                  1. Calculate Area of Rectangle
                  2. Calculate Area of Circle
                  3. Check if a Number is Prime
                  4. Exit
                  Enter your choice (1/2/3/4): 1
                  Enter the length of the rectangle: 10
                  Enter the width of the rectangle: 8
                  The area of the rectangle is: 80.0 square units.

                  Menu:
                  1. Calculate Area of Rectangle
                  2. Calculate Area of Circle
                  3. Check if a Number is Prime
                  4. Exit


                  Enter your choice (1/2/3/4): 4
                  Exiting the program...




                 35. Write a program to create a number guessing game.

                     Program 35.py
                  File  Edit  Format   Run   Options   Window     Help

                  import random
                  def guess_number():
                      number_to_guess = random.randint(1, 100)
                      guess = 0


                      while guess != number_to_guess:
                          guess = int(input("Guess the number between 1 and 100: "))
                          if guess < number_to_guess:
                              print("Too low!")
                          elif guess > number_to_guess:
                              print("Too high!")
                          else:
                              print("Congratulations, you guessed the correct number!")
                  guess_number()













                                                                                                Internal Assessment  625
   622   623   624   625   626   627   628   629   630   631   632