Friday, May 17, 2019

Abhijeet Pal: Python Program to Add Two Numbers

Problem Definition

Create a Python program to add two numbers and print the result, taking runtime input from the user.

Solution

  1. Take input from the user save them in variables
  2. Add the numbers and print the result
  3. End

Program

num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
sum = num1 + num2

print("The Sum is", sum)

Runtime Test Cases

Enter first number: 2
Enter second number: 4
The Sum is 6

Explanation

The input() function takes the input from the user however we need to convert the input to an integer using int() method to perform mathematical operation i.e. addition(+).

This program simply takes two arbitrary input from the keyboard store them in two different variables later these numbers are added and stored in another variable sum which at the end gets printed out.

The post Python Program to Add Two Numbers appeared first on Django Central.



from Planet Python
via read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...