Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple addition program in python [duplicate]

I am trying to learn python and for that purpose i made a simple addition program using python 2.7.3

print("Enter two Numbers\n")
a = int(raw_input('A='))
b = int(raw_input('B='))
c=a+b
print ('C= %s' %c)

i saved the file as add.py and when i double click and run it;the program run and exits instantenously without showing answer.

Then i tried code of this question Simple addition calculator in python it accepts user inputs but after entering both numbers the python exits with out showing answer.

Any suggestions for the above code. Advance thanks for the help

like image 451
Eka Avatar asked Jun 02 '13 10:06

Eka


People also ask

How do you make duplicates in Python?

In Python, we use = operator to create a copy of an object.

How do you add duplicates to a list in Python?

Method #1 : Using * operator We can employ * operator to multiply the occurrence of the particular value and hence can be used to perform this task of adding value multiple times in just a single line and makes it readable.

What is the program of addition in Python?

The Python sum() function calculates the sum of elements of the iterable. Iterable can be a list, a tuple, or a dictionary. sum() function works with both integers and floating-point numbers. It has an optional parameter to add a number to the total that is called as start value.


1 Answers

add an empty raw_input() at the end to pause until you press Enter

print("Enter two Numbers\n")
a = int(raw_input('A='))
b = int(raw_input('B='))
c=a+b
print ('C= %s' %c)
raw_input() # waits for you to press enter 

Alternatively run it from IDLE, command line, or whichever editor you use.

like image 142
jamylak Avatar answered Oct 03 '22 02:10

jamylak