

You can do this by using Python’s built-in input() function to accept user-generated input from the keyboard. Keep in mind that when asking for input, it can be helpful to include a space at the end of your string so that there is a space between the user’s input and the prompting string:Ĭalculator.py number_1 = int ( input ( 'Enter your first number: ' ) ) Inside of the parentheses of the input() function you can pass a string to prompt the user, and then assign the user’s input to a variable. Display problem numbers - whether or not to show problem numbers (1, 2, etc.) on the worksheet Advanced Options. Number_2 = int ( input ( 'Enter your second number: ' ) ) # Addition print ( ' = '. Some options have advanced features, as described here: Number of digits - allows you to explicitly set the range of values to be used for the first number and the second number in the addition problems. upper ( ) = 'N' : print ( 'See you later.' ) else : format (number_1, number_2 ) ) print (number_1 / number_2 ) else : print ( 'You have not typed a valid operator, please run the program again.' ) # Add again() function to calculate() function again ( ) def again ( ) :Ĭalculate ( ) elif calc_again.

Type in the equation in text and get the equation as an image. You can now run your program with python calculator.py in your terminal window and you’ll be able to calculate as many times as you would like. Very useful for submitting homeworks or putting it in the email. Now you have a nice, fully functional program. However, there is a lot more you can do to improve this code.
