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
In Python, we use = operator to create a copy of an object.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With