Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 142 - 2612_Digimind
P. 142

    SOME MORE PROGRAMS

                      Program 5: To test whether a given number is even or odd

                          Program5.py

                       File  Edit  Format    Run   Options   Window    Help

                       #Program to check whether the number is even or odd
                       number = int(input("Enter an integer: "))
                       if number % 2 == 0:
                           print("The number is even.")
                       else:
                           print("The number is odd.")

                      On running the above program, we get the following output:

                          Output

                       Enter an integer: 24
                       The number is even.

                      Program 6: To determine the weather is hot, warm, cool or cold based on given temperature

                          Program6.py
                       File  Edit  Format    Run   Options   Window    Help

                       #Program to determine the weather is hot, warm, cool or cold based on given
                       temperature.
                       temperature = float(input("Enter the temperature in Celsius: "))

                       if temperature > 30:
                           print("It's hot outside.")
                       elif temperature > 20:
                           print("It's warm outside.")
                       elif temperature > 10:
                           print("It's cool outside.")
                       else:
                           print("It's cold outside.")

                      On running the above program, we get the following output:

                          Output

                       Enter the temperature in Celsius: 15
                       It's cool outside.

                      140   Premium Edition-VII

| 137 138 139 140 141 142 143 144 145 146 147 |