Python Tutorials – If Statements

///Python Tutorials – If Statements

Python Tutorials – If Statements

FavoriteLoadingAdd to favorites

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
Follow Me On Twitter:
http://twitter.com/rengenmilitia

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

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

    Add me on steam: acechopper

  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 (‘1 = addition’)
    print (‘2 = Subtraction’)
    print (‘3 = Multiplication’)
    print (‘4 = Division’)
    c = int(input(()
    if c == 1:              
        print (‘Please enter a number’)
        num1 = int(input())
        print (‘Please enter another number’)
        num2 = int(input(()       
        answer = (num1 + num2)
        print (answer)
    elif c == 2:                    
        print (‘Please enter a number’)
        num1 = int(input())
        print (‘Please enter another number’)
        num2 = int(input(()       
        answer = (num1 – num2)
        print (answer)
    elif c == 3:
        print (‘Please enter a number’)
        num1 = int(input())
        print (‘Please enter another number’)
        num2 = int(input(()       
        answer = (num1 * num2)
        print (answer)
    elif c == 4:
        print (‘Please enter a number’)
        num1 = int(input())
        print (‘Please enter another number’)
        num2 = int(input(()       
        answer = (num1 / num2)
        print (answer)
    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

    Feel like a pro already

  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

    Please add more tutorial

  16. shadfurman 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?")
    print("1-Addition,2-Multiplication,3-Substraction,4-Division")
    c=int(input())
    print("Enter the first number")
    num1 = int(input())
    print("..and the second one")
    num2 = int(input())
    if c == 1:
        answer = (num1 + num2)
    elif c == 2:
        answer = (num1 * num2)
    elif c == 3:
        answer = (num1 – num2)
    elif c==4:
        answer = (num1 / num2)
    else:
        print ("you`re an idiot","use a number between 1 and 4")
    print("your answer is:",(answer))
        

  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 ("1 = Addition")
    print ("2 = Subtraction")
    print ("3 = Multiplication")
    print ("4 = Division")
    c = int(input())

    print ("Please enter a number")
    num1 = int(input())
    print ("Please enter another number")
    num2 = int(input())

    if c == 1:
        answer = (num1 + num2)
    elif c == 2:
        answer = (num1 – num2)
    elif c == 3:
        answer = (num1 * num2)
    elif c == 4:
        answer = (num1 / num2)
    else
        print ("*ERROR*")
        print ("Please enter a number between 1 and 4")

    print (answer)

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

    Your videos are very helpful. Thank You. 

  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

    When I write ; after the if it gives me "invalid syntax" please help me

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

    c = int(input())

    if c == 1;
    print ("add the first number")
    num1 = int (input())
    print ("add the second number")
    num2 = int (input())
    answer1 = num1 * num2
    print ("the answer is" answer1)

    if c == 2;
    print ("add the first number")
    num1 = int (input())
    print ("add the second number")
    num2 = int (input())
    answer1 = num1 + num2
    print ("the answer is" answer1)

    if c == 3;
    print ("add the first number")
    num1 = int (input())
    print ("add the second number")
    num2 = int (input())
    answer1 = num1 * num2
    print ("the answer is" answer1)

  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

    I admit I watch your video for the syntax.

  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?

Leave A Comment

*