Creating a python calculator using for loop
<p>so I have been asked to write a Python assignment for a basic calculator. It needs to include the operation I want to use (e.g. 1+1=, 2*2=). I am not so shabby at the keywords but when it comes to the construction from below the for i in range(1, 12, 1) statement I kinda falter. Im a bit fuzzy about how the data from the bottom reads from top. This is basically my code starts</p>

<pre><code>print ("Welcome to my Calculator")

x = input('Please enter first number: ')
y = input('Please enter a second number: ')

equation = x + y

print input("Choose an equation: (a) Add, (m) Multiplaction, (s) Subtract, (/) Divide")

for equation in range(1, 12, 1): 
</code></pre>

<p>I feel like the other answer lacks indicators to what you do wrong. You will need to look further into Python's grammar before going further. Basically you have some things problematic :</p>

<p><code>equation = x + y</code> computes the sum of x + y. To create an equation to which you can send x and y, you could create a function like this:</p>

<pre><code>def my_sum(argument1, argument2):
    return argument1 + argument2
</code></pre>

<p>Look into Python's dock to functions you are calling like <code>input</code>. <a href="https://docs.python.org/" rel="nofollow">Python Doc</a> There is no need to print input as it's will print the message itself. There is no handling regarding the answer given by the user to the "Choose an equation". The for loop you are trying to accomplish has no meaning; obviously you would want the input from the user (which could be a, m, s or /) to lead to some equation. To realize this, save the value of the input into a variable:</p>

<p><code>user_answer = input("Choose an equation: ")</code></p>

<p>Then use this variable for redirecting towards the correct equation function:</p>

<pre><code>if user_answer == 'a':
     my_sum()  # This is the function defined above
</code></pre>

python for-loop range