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>

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

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

equation = x + y

s = input("Choose an equation: (+) Add, (*) Multiplaction, (-) Subtract, (/) Divide")
if s == '+':
    print x + y
if s == '*':
    print x * y
if s == '-':
    print x - y
if s == '/':
    print x / y
</code></pre>

<p>First, I made the input of x and y int because before it was being taken as a string and that will not work.</p>

<p>Second, I made s = input (s is a random letter in my mind) and I had it equal different things ( add, multiply, subtract, divide).</p>

<p>Then, I set 4 if statements. I will explain one of them because they are all similar.</p>

<pre><code>if s == '+'
    print x + y
</code></pre>

<p>This is saying if the user inputed + then it will print the first number (x) added to the second number (y). </p>

<p>Hope that helps :)</p>

<p>Edit: This new code will only allow you to enter numbers 1-12 for both x and y that is line 9: if x in range(1,12,1) and y in range(1,12,1): It is simply saying if the first number you enter (X) is not in range 1-12 it will not display the answer. Same goes with y.</p>

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

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


s = input("Choose an equation: (+) Add, (*) Multiplaction, (-) Subtract, (/) Divide ")

if x in range(1,12,1) and y in range(1,12,1):

    if s == '+':
            print x + y
    if s == '*':
            print x * y
    if s == '-':
            print x - y
    if  s == '/':
            print x / y 
</code></pre>

python for-loop range