# Python Tutorials – If Statements

///Python Tutorials – If Statements

## Python Tutorials – If Statements

In this tutorial you learn how to use if statements to make a simple calculator. Don’t forget to rate comment and subscribe!

My Website:
http://rengenmilitia.weebly.com

By |2017-05-01T12:21:32+00:00April 26th, 2017|Programming Video Tutorials, Python Video Tutorials|35 Comments

1. Collin Clifton April 26, 2017 at 9:18 pm - Reply

Really love your tuts, you’re like the young "thenewboston"

2. jaka runi April 26, 2017 at 9:19 pm - Reply

you are awesome my friend

3. Unknown Blaziken April 26, 2017 at 9:21 pm - Reply

merry christmas dood

4. chopper ch April 26, 2017 at 9:23 pm - Reply

5. MSK9productions April 26, 2017 at 9:25 pm - Reply

The same thing happened to me and I did what you said and it still didn’t work D:

6. Xedret Belmont April 26, 2017 at 9:25 pm - Reply

C is for coooookie! – Cookie Monster

7. MELL09494 April 26, 2017 at 9:29 pm - Reply

Can anyone tell me why python 3.3.5 tells me invalid syntax when i run my code. at first it pointed to the answer = (num1 + num2) and now it points to the colon

print (‘What operation would you like to conduct’)
print (‘2 = Subtraction’)
print (‘3 = Multiplication’)
print (‘4 = Division’)
c = int(input(()
if c == 1:
num1 = int(input())
num2 = int(input(()
elif c == 2:
num1 = int(input())
num2 = int(input(()
elif c == 3:
num1 = int(input())
num2 = int(input(()
elif c == 4:
num1 = int(input())
num2 = int(input(()
else:
print (‘ERROR*’)
print ((‘Please enter a fucking number between 1 and 4!’)

8. Stuffy Duffer April 26, 2017 at 9:29 pm - Reply

My 10 year old son, who is interested in all things "engineering" but has never programmed anything in his life, added "squaring" and "cubing" options to the calculator on his own after watching the first four videos. This proves he’d understood the code and the steps you explained rather than just copying it "parrot fashion". His wide grin and sense of achievement was thanks to you. Brilliant, many thanks.

9. Sergii Fedosov April 26, 2017 at 9:29 pm - Reply

Thanks

10. j choi April 26, 2017 at 9:29 pm - Reply

11. Noel M John April 26, 2017 at 9:31 pm - Reply

Hi… Can you please tell why and what is the purpose of using a semicolon after; while/ if/ elif/ else?

12. Abass Za April 26, 2017 at 9:32 pm - Reply

thank you, it is very helpful, however if the picture is enlarged, it would be perfect and become much visible to most of us as we struggle to see some of the characters.

thank you once again.

13. Nardos Of Rivia April 26, 2017 at 9:34 pm - Reply

your cool kid 😀 does python program is better than java and c++? im actually wondering who i will master first

14. Ori Atias April 26, 2017 at 9:34 pm - Reply

great videos thank you, i have a problem with this one though..
i tried to do like you did and leave all the line with ‘if’s and ‘else’ in the last one
but i didnt got the error that you got, for me the program worked fine even in that way
do you have any idea why? btw im using 3.3.2

15. Nick Cachola April 26, 2017 at 9:35 pm - Reply

in the beginning you say "shortened to int of course", took me three listens, I thought you were saying, "short for intercourse" lol!

17. anapauomark April 26, 2017 at 9:36 pm - Reply

Question: the message "Please enter a number between 1 and 4" comes up, but then I just get the number I type – it doesn’t take me back to the option to select between 1 and 4 or to calculation – just keeps copying the number I type. How can I rectify this?!

18. Darius Restivan April 26, 2017 at 9:42 pm - Reply

another rewrite version of this program,but this time without using str syntax can be:
print("What do you want to do with the numbers?")
c=int(input())
print("Enter the first number")
num1 = int(input())
print("..and the second one")
num2 = int(input())
if c == 1:
elif c == 2:
elif c == 3:
elif c==4:
else:
print ("you`re an idiot","use a number between 1 and 4")

19. Fritz R. April 26, 2017 at 9:43 pm - Reply

Thanks for the nice tutorial. I changed the code a bit in order to shorten it – as one always enters two numbers in this example, I
– moved the input routines for the two numbers up and on top of the if / elif / else – block
– moved the output routine print (answer) down to the bottom

########################################
print ("What operation would you like to conduct?")
print ("2 = Subtraction")
print ("3 = Multiplication")
print ("4 = Division")
c = int(input())

num1 = int(input())
num2 = int(input())

if c == 1:
elif c == 2:
elif c == 3:
elif c == 4:
else
print ("*ERROR*")
print ("Please enter a number between 1 and 4")

20. Andrew Paige April 26, 2017 at 9:45 pm - Reply

21. lordhuebi April 26, 2017 at 9:46 pm - Reply

my division doesn’t do decimals. maybe cause i’m using python 2.7.5?

22. Qasim Mustafa Ali April 26, 2017 at 9:47 pm - Reply

print ("chose one of the following")
print ("1 = multiply")
print ("3 = devide")

c = int(input())

if c == 1;
num1 = int (input())
num2 = int (input())

if c == 2;
num1 = int (input())
num2 = int (input())

if c == 3;
num1 = int (input())
num2 = int (input())

23. ipodappsworld April 26, 2017 at 9:51 pm - Reply

this is awesome 😀

24. DeRobyJ April 26, 2017 at 9:55 pm - Reply

I never really understood "else" and "else if" statements, both in Pascal and C/C++. Now I do. lol

25. martin nygård April 26, 2017 at 10:01 pm - Reply

But–uhm 🙂

26. Nabeel Rajabali April 26, 2017 at 10:02 pm - Reply

I am getting this error
File "<pyshell#14>", line 6, in <module>
if c == 1:
NameError: name ‘c’ is not defined

27. srijith bhandary April 26, 2017 at 10:04 pm - Reply

you say semi-colon, but you put colon.

28. korab berisha April 26, 2017 at 10:12 pm - Reply

mine doesent work, it says “TypeError: ‘str’ object is not callable” error?

29. phur tenzin April 26, 2017 at 10:12 pm - Reply

more coming up ?

30. Aaron Roberts April 26, 2017 at 10:13 pm - Reply

31. Unknown Blaziken April 26, 2017 at 10:14 pm - Reply

belated

32. MacMazza 10 April 26, 2017 at 10:15 pm - Reply

does this work on python 3.3.3?

33. Mahipal Raj April 26, 2017 at 10:16 pm - Reply

There is a problem, after I enter a no more than 4 it says enter the no but it doesn’t go back to enter the no. What should we do make it operate again after entering the no more than 4. Thanks

34. kongbook10 April 26, 2017 at 10:18 pm - Reply

thanks man really thanks ur great easy and fas t

35. FrankiTheGreat April 26, 2017 at 10:18 pm - Reply

How so?