Learn to Program 5 : Functions

[ad_1]
Code & Transcript :

Best Python Book :

Interactive Tutorial with Quiz Here :

Support me on Patreon :

In this part of my Learn to Program series I’ll focus on functions. We’ll see what local and global variables are. We’ll solve algebraic equations. We’ll learn how to pass and return an unknown number of values into and out of functions. We’ll generate prime numbers. And, we’ll see how to create small functions that make our code easier to understand.

Thank you to Patreon supports like the following for helping me make this video

@kyleaisho
@thetwistedhat
vjFaLk


Posted

in

by

Tags:

Comments

22 responses to “Learn to Program 5 : Functions”

  1. Alchad Plays - Minecraft Tutorials & More Avatar

    It just giving me a blank when i run it.

  2. Hasnain Ahmed Avatar

    What does .argv do?

  3. Alchad Plays - Minecraft Tutorials & More Avatar

    Application Details
    This is an application for simple
    just for view don't take it as i am coding or programming just for
    review of some of the paragraph I have been written today.

    also the showcase of this is an illegal copy of Microsoft as Bill Gates gone crazy on his work so don't view this program to anyone. it could also be a bug or virus for just any view.

    Warning: Do not touch with some of code, because it could also
    interrupt the application and cause it to crash the application also
    your operating system you are using right now. Always Dennis Ritchie
    eats pies every morning C looks like or BUGS. So take care of yourself and others.

    News of Microsoft

    Microsoft has been arrested and also Bill Gates because of bugs in his
    operating systems and manslaughtings software created by Microsoft also
    ignored the one of the famous game called Minecraft . The court says that the Microsoft company should be closed sooner.

    also delete their programs that they have been just developed through stoling software like Pycharm And Monodevelop.

    Conclusion

    Microsoft is grinding wheat and also killing bugs in his hair because
    of poor man just not to be honest also to be poor as beggers and
    theives.

  4. Alchad Plays - Minecraft Tutorials & More Avatar

    Derek Banas, is linux operating system good for programming.

  5. Alchad Plays - Minecraft Tutorials & More Avatar

    thanks for the video for python programming i was looking this tutorial for a long time and now i got it.

  6. Aditya D Avatar

    What if I don't want X to be in front? How do I make the code determine where the position of X is so if I type in (5 + x = 3) it still works?

  7. Jake Ambrose Avatar

    i use both windows and mac. for now when im on windows and i save a file as .py where is it going? i cant find where its at ( havnt been using windows long ) , also how do i find what the full root of a file is as in when im calling it in a command so i can type it out or however youd state that ? thanks Boss

  8. Sirin Öngörur Avatar

    Now I got it! Thanks for the great vids!

  9. Sirin Öngörur Avatar

    Hi Derek,

    I have a question about the function mult_divide. What does it mean logicaly when you write " return (num1*num2),(num1/num2)". And why does mult, divide=mult_divide(num1,num2) mean that mult = return (num1*num2) and divide=(num1/num2). I understand what happens when you write the code like this but I don´t grasp the logic behind it. Not sure if you understood what I mean.

  10. Manning Chen Avatar

    Hey derek, I love your videos. Could you make similar series like this but instead of with python teach C++.

  11. Paavan Gupta Avatar

    Sir, whenever i am running my python programme after saving it, that gives an error saying that
    .
    This version of program is not compatible with the version of windows you are running. check
    your system's information to see whether you need an x86(32-bit) or x64(64-bit) version of this
    program and then contact the software publisher
    .
    sir plz can you tell the solution of this problem

  12. Barbell Bender Avatar

    Just wanted to share my solution to the fun little "solver problem":

    def eq_solv(eqs):

    counter = 0
    for i in eqs:
    if i.isdigit():
    counter += int(i)
    return counter

    eq = input("Enter equation: ")
    eq_s = eq.split("=")

    lc = eq_solv(eq_s[0])
    rc = eq_solv(eq_s[1])

    print("X =", rc – lc)

    As usual, great tutorial!

  13. Stefan Avatar

    This is how I solved the problem with x:

    def xsolver (calc):

    x, operator, num1, equals, num2 = calc.split()

    num1, num2 = int(num1), int(num2)

    if operator == ("+"):
    return "x = " + str(num2 – num1)
    elif operator == "-":
    return "x = " + str(num2 + num1)
    elif operator == "/":
    return "x = " + str(num2 * num1)
    elif operator == "*":
    return "x = " + str(num2 / num1)

    def xsolver2 (calc2):

    num1, operator, x , equals , num2 = calc2.split()
    num1,num2 = int(num1), int(num2)

    if operator == ("+"):
    return "x = " + str(num2 – num1)
    elif operator == "-":
    return "x = " + str(num1 – num2)
    elif operator == "/":
    return "x = " + str(num1 / num2)
    elif operator == "*":
    return "x = " + str(num2 / num1)

    while True:
    equation = (input("enter a equation to solve x : "))
    store = (equation)[0]
    try:
    if store == "x":
    print(xsolver(equation))
    break
    else:
    print(xsolver2(equation))
    break
    except ValueError:
    print("You didn't enter the right equation")

  14. Stefan Avatar

    Hey Derek, why do you convert the code back to a string at 10:04?

  15. Paul Sicurello Avatar

    I got to work by adding under x, add, num1, equal, num2 = equation.split()
    assert isinstance (num2,object)
    and for reason it works. Has anyone ever come across something like this?

  16. Paul Sicurello Avatar

    I get this error and I don't seem to be able to figure it out
     Traceback (most recent call last):
    File "C:/Users/Paul/Desktop/python/Learing_to_program/programming_101.py", line 22, in <module>
    print(solve_eq("x + 4 = 9"))
    File "C:/Users/Paul/Desktop/python/Learing_to_program/programming_101.py", line 16, in solve_eq
    return "x = " + str(num2 – num1)
    TypeError: unsupported operand type(s) for -: 'str' and 'str'

  17. Nick Virdee Avatar

    Could you possibly help me with a function to count how many integers all together there are in a list of integers and strings combined e.g.
    my list = [1 , 2, 3, 'four', 'five']
    how would i only return the number of integers and then return 0 if there are no integers
    many thanks.

  18. Balla Baby Avatar

    I wasn't even aware that we could make a statement like the split statement to cover so many variables such as the one used in the first example. Was this even taught in past videos or did I forget it?

  19. Clay Brown Avatar

    So what's up with the "mult, divide = mult_divide(5, 4)" line? What are the mult and divide variables? Are they storing "(num1 * num2) and (num1 / num2)?"

  20. Umar Baba Jidda Avatar

    First up Don Banas (yeah, you are like THE code mafia don) thumbs up and thanks for the tuts. My question is this: am new to Python and I'd like to know how to write a program and make it as a desktop application, like a normal Windows .exe

  21. Theofilos Mitrentsis Avatar

    def addition(a_string):
    a_list = list(a_string.split())
    return int(a_list[4]) – int(a_list[2])

    user_input = input('enter an addition with the syntax "x + a = b" : ')
    print(" x = {}".format(addition(user_input)))

  22. TheWildHealer Avatar

    I think this was the most tricky part of the series so far. I think I need to work more with functions to get used to this kind of thinking.

Leave a Reply

Your email address will not be published. Required fields are marked *