Software & Finance

Python - Input Integers and Floating Point Numbers


Here is the python source code to explaining how to input integers and floating point numbers. This code is tested with Python version 2.6


        print "Program to add two numbers"
        print "Enter First Number:",
        a = 0
        a = input()
        print "Enter Second Number:",
        b = 0
        b = input()
        print "Result: ", a + b

        print "Program to add two floating point numbers"
        print "Enter First Number:",
        c = 0.0
        c = input()
        print "Enter Second Number:",
        d = 0.0
        d = input()
        e = 0.0
        e = c + d
        print "Result: $.4f" %e
        #sample output
        #Program to add two numbers
        #Enter First Number: 10
        #Enter Second Number: 20
        #Result:  30
        #Program to add two floating point numbers
        #Enter First Number: 1.111
        #Enter Second Number: 2.222
        #Result: 3.3330