# SumImproved.py Copyright (c) 2006 Kari Laitinen # http://www.naturalprogramming.com # 2006-05-28 File created. # 2006-05-28 Last modification. # This is a simple calculator program that can # calculate the sum of the two integers that are # typed in from the keyboard. # The number sign (#) starts a comment line in Python. # All statements in Python 'main' program must begin in the # first column. Statements may not be indented unnecessarily since # indented statements form a nested program block. # You must use a backslash (\) to continue a statement on the # following program line. # Variables are not declared in Python programs. Instead, variables # are 'born' when they are assigned values. # Built-in runction raw_input() reads a string from the keyboard. # Built-in function int() converts a string to an integer value. # print is a Python keyword. print statements normally print a # newline after the printing operation. This can be prevented by # writing a comma at the end of the print statement. # See programs Distance.py and Formatting.py in pythonfiles2 for # information about the format specifiers (e.g. %d). print "\n Please, type in an integer: ", first_integer_from_keyboard = int( raw_input() ) print "\n Please, type in another integer:", second_integer_from_keyboard = int( raw_input() ) sum_of_two_integers = first_integer_from_keyboard + \ second_integer_from_keyboard print "\n The sum of %d and %d is %d." % ( first_integer_from_keyboard, second_integer_from_keyboard, sum_of_two_integers )