Page 78 - Touhpad Ai
P. 78

21 st
                 AI TASK                                                            Century   #Coding & Computational Thinking
                                                                                     Skills
               1.  Let us create a small guessing game using Python!

                  import random
                  print("Welcome to the Guessing Game!")
                  print("Try to guess the number I am thinking of between 1 and 20.")
                  num = random.randint(1, 20)  # generate random integer
                  my_guess = -1  # initialize guess to an invalid value
                  while my_guess != num:
                      my_guess = int(input("Enter your guess: "))
                      if my_guess < num:
                          print("Too low, try again.")
               2.  Predict the output of the following code:
                  x = "I am eating mangos"

                  print("am" in x)
                  print("apple" in x)



               3.   Write a Python program that takes the lengths of three sides of a triangle as input, and then determines whether
                  the triangle is Equilateral, Isosceles, or Scalene.






















              The range() Function
              The range() function in Python generates a sequence of numbers. It is commonly used with for loops to iterate over a
              specific range of numbers. The syntax of the range function is as follows:

                 range(start, stop, step)
              where,

              start: Starting number of the sequence.
              stop: Generate numbers up to, but not including the last number.
              step: Difference between each number in the sequence.

              Python use range( ) function in three ways:
              1.   range(stop):  This generates  a sequence  of numbers  from 0 up  to  the  specified  stop  value but  not  including  it.
                 It implicitly starts from 0 and increments by 1.


                 76     Touchpad Artificial Intelligence - XI
   73   74   75   76   77   78   79   80   81   82   83