Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 146 - 2612 Digimind C6
P. 146

    Program 2. Write a program to add two numbers.

                          Program2.py
                       File  Edit  Format   Run   Options  Window    Help

                       #Program to add two numbers
                       num1 = int(input(" Enter first number: "))
                       num2 = int(input(" Enter Second number: "))
                       ans=num1+num2
                       print(" The sum is : ", ans)

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

                          Output
                       Enter first number: 3
                       Enter Second number: 2
                       The sum is : 5

                      Program 3. Write a program to calculate the average marks of three subjects.

                          Program3.py
                       File  Edit  Format   Run   Options  Window    Help

                       #Program to calculate the average marks of three subjects
                       Eng = float(input(" Enter English Marks: "))
                       Math = float(input(" Enter Math Marks: "))
                       Hindi = float(input(" Enter Hindi Marks: "))
                       avg=( Eng+ Math + Hindi)/3
                       print("Average is :", avg)

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

                          Output

                       Enter English Marks: 90
                       Enter Math Marks: 95
                       Enter Hindi Marks: 80
                       Average is : 88.33333333333333

                                        Imagine, comments in Python are secret messages from a wise mentor. What advice
                                        or tips would you leave in your code for future programmers to discover?

                      144   Premium Edition-VI

| 141 142 143 144 145 146 147 148 149 150 151 |