How To Use Functions In Python (Python Tutorial #3)

Поделиться
HTML-код
  • Опубликовано: 26 янв 2025

Комментарии • 2,7 тыс.

  • @CSDojo
    @CSDojo  7 лет назад +575

    Below is an outline of this video.
    0:41: How to use sample files
    1:41: Using comments
    2:21: What’s a function? - Example 1
    4:57: What’s a function? - Example 2
    7:09: A function that takes multiple arguments
    7:58: What’s a function? - 2 more examples
    10:30: Creating a BMI calculator
    Also, a few tips:
    1. Here is the playlist for this series: ruclips.net/video/Z1Yd7upQsXY/видео.html
    2. Follow along as I explain to make sure you understand everything
    3. Ideally, work with a friend so you can help each other when you’re stuck
    4. If you want to learn faster than I talk, I’d recommend 1.25x or 1.5x speed :)
    5. Check the outline in the comment section below if you want to skip around.
    6. Download the sample files here to follow along (they are Jupyter Notebook files): www.csdojo.io/python3
    7. To make sure you don’t miss my future tutorial videos, sign up to my newsletter: www.csdojo.io/news
    8. Have fun! If anything is unclear, please let me know in a comment.

    • @namlehai2737
      @namlehai2737 7 лет назад +2

      local host... did you make all that?

    • @Jass_9676
      @Jass_9676 7 лет назад +12

      Love from india
      Helpful videos

    • @harisar17
      @harisar17 7 лет назад +3

      Again i hit like for your video..

    • @gilangvirgiawan2780
      @gilangvirgiawan2780 7 лет назад +1

      Ur something thanks

    • @parveshkhatri7971
      @parveshkhatri7971 7 лет назад +10

      Hi YK ,
      In india we are not taught what we want . There is useless matter in our syllabus. Even many people with master degree in computer science can't create any simple application without any GUI interface help and swing controls. They teach us for marks not for knowledge.
      Should I learn computer science online leaving my school ?

  • @emanjavascript8358
    @emanjavascript8358 5 лет назад +879

    men i watch every advertisement that comes out to my screen just to be fair by teaching us for free..your awesome men

    • @warframeees8013
      @warframeees8013 4 года назад +22

      Eman JavaScript watching the entire ad wont give him more revenue but a nice act nevertheless

    • @aarohansharma4551
      @aarohansharma4551 4 года назад +8

      It only gives revenue to RUclips or something I guess

    • @warframeees8013
      @warframeees8013 4 года назад +10

      Aarohan Sharma it doesn’t matter how long you watch the ad it’s per view, doesn’t matter if you skip the ad 5 sec in or watch the entirety

    • @katharina...
      @katharina... 4 года назад +20

      @@warframeees8013 It does matter how long a viewer watches a skippable ad for. If a viewer skips it, the uploader doesn't get paid at all, you have to watch it for 30 seconds or longer for the uploader to be paid.

    • @warframeees8013
      @warframeees8013 4 года назад +3

      Katharina interesting if thats true

  • @Haldiki
    @Haldiki 5 месяцев назад +3

    Saying thank you is saying nothing at all It's the first time that I've understood programming without a sweaty forehead. CS Dojo is like a real teacher - competent and consequent. Forget other courses. Stay here, you won't regret. Kudos to CS Dojo.

  • @Mindput
    @Mindput 4 года назад +462

    Hello CS Dojo. I don't know if you are going to read this, but I just passed an Exam in Python because of you! Thank you so much! I spend like 10 hours to watch your awesome lectures :)

    • @mustafaaljanabi4818
      @mustafaaljanabi4818 3 года назад +28

      Masha Allah! Well done brother!

    • @AS-nx9fu
      @AS-nx9fu 3 года назад +2

      @ツMoon Owner - Owner of the Moon tf is he typing like that for? 😭💀

    • @joeroganpodfantasy42
      @joeroganpodfantasy42 2 года назад

      But his lecture are around 3 hours?
      Do you mean total watching and practicing or just watching and rewatching?

    • @Mindput
      @Mindput 2 года назад +6

      @@joeroganpodfantasy42 Sorry for the late answer. Yes, by re-watching and doing everything by myself twice to get it :)

    • @ramajyello
      @ramajyello 2 года назад +1

      @@AS-nx9fu I deleted that acc 😂. Literally just stumbled upon this. Ig my path has been set in stone

  • @kei7150
    @kei7150 3 года назад +281

    I'm skipping school to learn coding from this guy and i gotta say it's worth it.. this dude is way better than all of my teachers

  • @thatwakandaboy
    @thatwakandaboy 2 года назад +35

    I am 4 years late to this channel and 43 years late to Programming, but I am enjoying every minute of this series. Thanks YK and the entire CS Dojo team.

    • @Addistoday
      @Addistoday Год назад +1

      😂😂😂😂😂😂😂 same here,Things happen at Gods will time. enjoy❤❤❤❤ much love from Ethiopia🇪🇹

  • @ammarahmed8155
    @ammarahmed8155 5 лет назад +415

    I started watching these tutorials yesterday and I figured out by myself how to use these functions to create a program to solve the quadratic formula. I know thats probably nothing for coders but I feel really accomplished and if anyone wants to see the code I can send it to you over email. I just feel really accomplished and I wanna share it with someone. This guy is such a good teacher.

    • @gabz8469
      @gabz8469 5 лет назад +5

      Hi Ammar
      Would you be able to send the code to geebee71@hotmail.com please?
      Appreciated..Thanks

    • @YashSharma-nm1zc
      @YashSharma-nm1zc 5 лет назад +2

      Pls share me codes

    • @oblivious7045
      @oblivious7045 5 лет назад +55

      Why don't you just post it in the comments?

    • @Aminhirari
      @Aminhirari 4 года назад +19

      Be careful it’s a virus torchan

    • @ykyk7771
      @ykyk7771 4 года назад +31

      Post it here bruh

  • @dhruvalraval8078
    @dhruvalraval8078 7 лет назад +318

    You are being so helpful. Please continue with this series of python

  • @tradeviper874
    @tradeviper874 6 лет назад +328

    Well, out of all of the different, gazillion sites and videos I have paid for and not paid for, you are, in the 61 yr olds opinion, The Best. Knowing what you are doing, and Teaching, are two different skill sets. In my business, just because you have intellect and mental ability, does not mean you will make money. You are doing quite well, starting with a base concept, then giving a practical example, then breaking it down to show how it works. Outstanding job, young man just outstanding. Also, Kudos on your English, bring multilingual myself, it can be a daunting task at times, but you have also done well here. Keep up the good work and I look forward to seeing your future success, by the way, maybe a paid forum might help keep a roof over your head? :)
    The Ever Kudoing VIPER

    • @zumzumwater3018
      @zumzumwater3018 6 лет назад +4

      Hey Trade, My dad is 65, and his typing speed is 11wpm, anything below 30 is considered very slow. How do I get my dad to stop acting like such an old man?

    • @rickydawn6313
      @rickydawn6313 5 лет назад +12

      @@zumzumwater3018 Viagra gives you wings.

    • @PeterLucasathome
      @PeterLucasathome 4 года назад +7

      @Trade Viper, I endorse your comments. At 71, I am learning to code thanks to this young man. He is doing an excellent job. Last time I did any coding was back in the 80's, when if you couldn't write a little BASIC, you couldn't get a computer to do anything. @CS Dojo , you deserve success!

    • @HHTP6
      @HHTP6 3 года назад

      dont worry grandpa this video alone can get 15 months of rent

    • @AnonymousXvictoriouS
      @AnonymousXvictoriouS 3 года назад

      @@zumzumwater3018 he is an old man

  • @epiccownerdfighter
    @epiccownerdfighter 2 года назад +13

    I know this is an old vid I'm commenting on, but you earned an instant sub (well, after 3 videos). Informative, understandable, well presented, quick. Great stuff for a beginner like me!

  • @youdonthaveto
    @youdonthaveto 3 года назад +12

    You are so helpful. I've grown up in a broke family and I don't have any money to buy course for learning Python. Your videos mean a lot to me. Thank you so much Dojo

    • @FirepowerIGuess
      @FirepowerIGuess Год назад +3

      I'm so glad people like CS are making these tutorials for free, genuinely. I hope you're in a more financially stable condition now than before.

  • @legal827
    @legal827 7 лет назад +42

    I absolutely love your videos. My father inspired me to learn programming, as in the past I’ve learned some but I’ve gathered a lot of laziness towards programming because of a lot of heavy school work. My father encourages me to just read the documentation and learn Python piece by piece, but I find that boring and hard to follow.
    Your videos keep me going and they are professional and clear. Instead of buying courses on Udemy, I just use your courses and they’re amazing. Thank you so much.

    • @Toxicbeing8750
      @Toxicbeing8750 5 месяцев назад

      how are you now doing you must be a guru now

  • @shahin2324
    @shahin2324 3 года назад +61

    My Professor thinks he's the real shit in Python by creating videos that are 5 hours long just to explain one concept!!!! Now, this is called a real teaching video!!!! short and informative!!!

    • @elkresurgence
      @elkresurgence 3 года назад +8

      maybe your prof really delved into that concept during those five hours. Short isn't always good, although in the case of this tutorial it is

    • @joeroganpodfantasy42
      @joeroganpodfantasy42 2 года назад +1

      Maybe if your professor would release his videos on youtube people would appreciate them more.
      I have noticed people tend to dislike what it's offered to them locally or thru a system and they like what they find themselves online.

    • @t345m
      @t345m 9 месяцев назад +1

      At least yours tries my professor gives us half examples and then stops teaching 30 mins in. The class is supposed to be 3 hours! Be happy that he actually cares, unlike mine.

  • @3niracer
    @3niracer Год назад +12

    Learned more from you in an hour than 2 weeks of a course. Thanks for taking the time and effort. Much appreciated 🙏🏽

  • @emmanuelpierre8856
    @emmanuelpierre8856 2 года назад +2

    Hey YK, I from Canada, Québec, Gatineau and I speak french more than english. I am an absolute beginners on python (leaning how to code). I want to let you know that all your Python tutorial are well explained and I love following your courses cause you take your time to explain step by step and I found this a great quality and skills you have. Keep continue what you do, teaching us, sharing your knowledge and more. Your great energy will bring you where ever you want and you will get what ever you need to accomplish your goals. 👍

  • @keerthanaanandan6062
    @keerthanaanandan6062 5 лет назад +761

    Def comment1():
    print("thanks for teaching me")
    print("thanks once again")
    Comment1()

    • @rickydawn6313
      @rickydawn6313 5 лет назад +6

      Input Error missing Positional input

    • @allipse8224
      @allipse8224 4 года назад +1

      @@puchu_5001 same

    • @oussematoussli8085
      @oussematoussli8085 4 года назад +5

      Comment 1() should be comment1() not with the Capital letter

    • @jinsonthekkan7420
      @jinsonthekkan7420 4 года назад +4

      D should be also small letter

    • @KS_Harshith
      @KS_Harshith 4 года назад +11

      def comment1():
      print("thanks for teaching me")
      print("thanks once again")
      print(comment1())
      # this is the correct code

  • @TheNewTravel
    @TheNewTravel 4 года назад +195

    I was hoping you would go back and add the "is" before "not overweight', it was driving me crazy haha. Great video :)

  • @elmo890
    @elmo890 5 лет назад +12

    miles = int(input())
    def convert(miles):
    print("KM:")
    return miles*1.6
    km = convert(miles)
    print(km)
    Asks to type in miles when run, converts input to KM. Or remove int(input()) and set miles = "amount of miles"

    • @KokkuBhanuprakash
      @KokkuBhanuprakash 4 года назад

      excellent bro😱😱😱😱

    • @guiantony
      @guiantony 2 года назад +1

      miles = int(input())
      def convert(miles):
      print("KM:", end="")
      return miles*1.6
      km = convert(miles)
      print(km)
      (with it stays in the same line :) )

  • @evelyn-ed7nn
    @evelyn-ed7nn 2 года назад +1

    I think what is insane is that these videos were made in 2018 and I'm sitting here on the same program in 2022 and it still looks the same, still works the same, it's just so easy to use; it's incredible.

  • @lovathon6365
    @lovathon6365 2 года назад +2

    I've been self studying using another website where I bought a course on sale, and I have been struggling so much with functions that I even stopped for 2-3 weeks because I just felt so dumb that I couldn't grasp what was being asked of me... this video broke it down so nicely that after so long I'm finally able to grasp what was being said all along. thank you for making this video, it has brought me back to coding!!

  • @abdulkhadir4498
    @abdulkhadir4498 2 года назад +8

    For those who want to write a quadratic equation, I wrote a code and felt I should share this. So here is the code:
    def function2(x):
    a=2
    b=3
    c=4
    return a*(x**2)+b*x+c
    value_of_my_equation=function2(-2.2)
    print(value_of_my_equation)
    Note: you can assign any value for x inside the parentheses beside value_of_my_equation=function2 and any values to a,b,c.

  • @kennethchin278
    @kennethchin278 4 года назад +3

    I thought the overview of functions was excellent. Covering what one can use functions for, quickly and concisely, ( be it mappings and returning calculations. ) as well as using of strings. Much appreciate. I've watched a few online Python vidoes and it's nowhere near as sysynced and easy to understand with useful examples as yours. Keep up the good work.

  • @siddhijha894
    @siddhijha894 7 лет назад +186

    YK 😁😍 thank u and keep working over it ,u r an awesome teacher 😂

  • @joemorris6544
    @joemorris6544 4 года назад

    I have been following along with Python Crash Course book in my spare time and anytime I get stuck on a problem or don’t quite understand what I’m doing I always come to your channel.
    This video helped me understand functions a lot more.

  • @dansmith9406
    @dansmith9406 2 года назад

    5 years later and this video is still amazing! You just helped a total noob complete part of the cs50 course with this video. I had no idea how to do mapping with a function. Perfect explanation. Thank you

  • @paulovinicius5833
    @paulovinicius5833 5 лет назад +9

    Best functions classes I've ever seen. Congrats!

    • @geniushalo5473
      @geniushalo5473 4 года назад

      You mean "Thanks"?

    • @RealSpyduh
      @RealSpyduh 4 года назад +1

      @@geniushalo5473 ahahahahah yeah i think thats what he meant XD

    • @geniushalo5473
      @geniushalo5473 4 года назад

      @@RealSpyduh Yeah xd. Its kinda wierd to congratulate someonw

    • @delubiod1970
      @delubiod1970 4 года назад +1

      @@geniushalo5473 We Brazilians Congratulate everyone who does that extra mile when teaching. He deserves to be Congratulated. Don't you think?
      Teaching is hard. When someone teaches a topic so easy, just thanking him will sound like an understatement to his effort, I guess....

  • @droidzz4935
    @droidzz4935 6 лет назад +27

    Here is the function:
    def convert(miles):
    km = 1.6 * miles
    print("km: ")
    print(km)

    • @zz-nj1bq
      @zz-nj1bq 5 лет назад

      ok

    • @ThErrandBoy
      @ThErrandBoy 4 года назад +3

      @akash anil he's not wrong, you just have to call the function cos he didn't assign it to a variable (since he used print and not return.) and he should have said km = 1.6/miles not 1.6*miles.

    • @michaelegiebor524
      @michaelegiebor524 4 года назад

      Should have used return argument instead

    • @rahmats.8913
      @rahmats.8913 4 года назад

      it's not a function

    • @droidzz4935
      @droidzz4935 4 года назад

      @@rahmats.8913 ?

  • @vasileafloarei251
    @vasileafloarei251 6 лет назад +12

    def functie_km(km):
    return 1.6 * km
    print("conversis km in mile")
    a = functie_km(4)
    print(a)

    • @pranithsukhavasi2502
      @pranithsukhavasi2502 4 года назад +1

      return 0.6*km(correction)

    • @am_sf6574
      @am_sf6574 4 года назад

      @@pranithsukhavasi2502 it's not 0.6 though

    • @Dark_dragon1212
      @Dark_dragon1212 8 месяцев назад

      why not just do
      def convert(miles):
      print("converted km in miles")
      return 1.6*miles
      convert(4)
      I assume conversis is a synonym for convert or converted.

  • @AAsisters84
    @AAsisters84 3 года назад

    After searching on RUclips for 30 minutes, This video was the only one that really helped me understand how to use the functions. Thx a lot.

  • @nzehemmanuel3774
    @nzehemmanuel3774 2 года назад +1

    I’m Emmanuel from Ghana and I was thinking about how to start my semester Computer programming. I didn’t know what to do but from the fews videos I have been watching from your site . I very motivated to do this course. Thank you soo much for giving me this foundation 🙏🙏

  • @devonchin94
    @devonchin94 5 лет назад +4

    def convert(miles):
    return miles*1.6
    km = convert(int(input("Enter miles here: ")))
    print(str(km) + " km")
    I decided to take it one step further with the challenge. Allow a user input to convert miles to km, and convert that integer to a string to show the km after the value!
    Thanks so much for these videos! I am absolutely loving learning python3 (my first programming language). And having passionate people recording tutorials like this really helps more than I could ever put into words!

    • @rakotai9998
      @rakotai9998 5 лет назад

      honestly i did the same thing the reason i took a step further was cuz the actual challange was too easy and tried to make a user type the miles and it convertes it to km and i was bout to paste the code in here but guess I was slow. LMAO you got me.

  • @lzcracker
    @lzcracker 6 лет назад +12

    This is the most clear, concise explanation of python I've found, thank you so much for the hard work. :)

  • @milittt
    @milittt 4 года назад +70

    The best part:
    Running a code without error 😑😑😑

    • @AQ-101
      @AQ-101 3 года назад

      @Loai Alghamdi yes 😁

  • @saganmcvander636
    @saganmcvander636 5 лет назад

    @CS_Dojo Wow you actually explain functions properly unlike the thousands of 30 minute youtube videos that never explain any of this properly.

  • @LaxmiGupta-cl2go
    @LaxmiGupta-cl2go 4 года назад

    def miles(x):
    return 1.6*x
    y= miles (45)
    print ('y=', y, 'km')
    y= 72.0 km
    ( I prefer it with unit, hence)
    Your teaching is really good. Thanks YK!

  • @shashiverma6219
    @shashiverma6219 7 лет назад +21

    Love from India bro..I learned PHP year ago ..and at that time I was keen to learn python..but didn't happened.. I did 2 months job as PHP developer in a small company..I left..coz i thought it's not that's I want..but after watching ur another videos and that python series..I think I can do this..thanks for uploading the videos ..and keep uploading bro..thank you so much brother.

    • @diogo8386
      @diogo8386 6 лет назад +1

      Hey man, how many time you took to learn php and to get the job?

    • @OsadeTOOT
      @OsadeTOOT 6 лет назад

      i thought you said "love you indian bro" lol

  • @shree2710
    @shree2710 7 лет назад +123

    Its like waiting for the new episode of your favourite anime, only the difference is that you dont know when the new episode is gonna be dropped.

    • @Ahmedcoday
      @Ahmedcoday 7 лет назад +2

      loooool

    • @rakotai9998
      @rakotai9998 5 лет назад

      LMAO! i am currently watching Kenja no maga , Kimitsu no yoba , fairy tale: final season and thats all

    • @77shaiksultan
      @77shaiksultan 5 лет назад +1

      You can't compare anime with this

    • @kennyg1953
      @kennyg1953 5 лет назад

      Idk man I've been waiting for Naruto Ep 501 for a while.

    • @Red-yq6nc
      @Red-yq6nc 5 лет назад +1

      @@@kennyg1953 Fam naruto is over, now they have a half assed series named boruto which is basically like naruto filler but its cannon

  • @noflare1714
    @noflare1714 4 года назад +100

    You cannot imagine the amount of joy I felt when I converted km to miles😂😂😂😂

    • @chernobylcoleslaw6698
      @chernobylcoleslaw6698 4 года назад +10

      Nah I scream for joy when I nail some code; even if it is basic af.

    • @celineangelina2697
      @celineangelina2697 4 года назад +3

      howw? can you post it here?

    • @ShreyasV0
      @ShreyasV0 4 года назад +7

      @@celineangelina2697
      def convert(miles):
      print(1.6*miles)
      miles = int(input("Enter miles :"))
      convert(miles)

    • @MinotaurvsCyclops
      @MinotaurvsCyclops 4 года назад +3

      @@celineangelina2697 KM to MILES (my way):
      def convert(miles):
      km = miles / 1.6
      print(f"This is the amount in miles {km}")
      miles = float(input("Enter KM here: "))
      convert(miles)

    • @eleenasen4290
      @eleenasen4290 4 года назад +2

      @@chernobylcoleslaw6698 OMG same I was like YASSS IM NOT DUMB lolol

  • @fryaadil1687
    @fryaadil1687 3 года назад +1

    Just started learning Python as a hobby. I have no programming experience but I am really enjoying it so far. Thanks, man.
    Your teaching method is really good.

  • @HipsterBrooo
    @HipsterBrooo Год назад

    Bro I feel like I've browsed through a gazillion videos on Functions and only this video helped me. THANKS A TON😭

  • @am_sf6574
    @am_sf6574 4 года назад +10

    Def convert(x):
    Return x * 1.6 + " km"
    Km = convert(5) #5 miles
    Print Km

    • @khytron06
      @khytron06 3 года назад +3

      And you can also ask the user for an input :
      def convert(x):
      print(x*1.6+"km")
      a=int(input("Distance(miles): "))
      convert(a)

    • @builder481
      @builder481 3 года назад +4

      def convert(m):
      return m * 1.6
      km = convert(8)
      print(km)
      I also made this it convert feet to cm
      def hight(length):
      return length * 30.48

      tallinCm = hight(6.4)
      print(tallinCm)

  • @richardd5587
    @richardd5587 4 года назад +4

    Really good series. Thought I'd dip into Python as it's the language used in my nephew's school and he will be taking Computer Science next year. As a retired Science teacher with a lot of experience coding in VB and VBA I've found the presentations very clear and rarely miss a trick (like the importance of the number of leader spaces!). Although I was using PyCharm I now think the Jupyter IDE has the edge for younger students.

  • @agamgujral5696
    @agamgujral5696 4 года назад +9

    I did:
    def km(x):
    return (1.6 * x)
    Miles = km(20)
    print(miles)
    32

    • @khalanesachin
      @khalanesachin 4 года назад +2

      Yours is also right but you managed it little differently than he asked ..
      What he is expecting (in my opinion) is as follows...
      def convert(miles):
      return miles*1.6
      km = convert(100)
      print(km)
      160.0
      Which means 100 miles= 160km

    • @TollpatschZ123
      @TollpatschZ123 4 года назад

      @@khalanesachin Yeah makes more sense that way. Thanks for sharing.

  • @sultanmahamud7134
    @sultanmahamud7134 Год назад +1

    You just helped me with something i was stucked for long

  • @MrMikeIppo
    @MrMikeIppo 5 лет назад

    Sir, you are the most helpful teacher I have found online:
    def CS_Dojo():
    print("instant Like")
    print("instant Subscribe")

  • @Rinaa966
    @Rinaa966 2 года назад +5

    My solution ^^
    def convert(mile):
    km = mile * 1.60934
    return str(mile) + " mile is equal to " + str(km) + " km"

    • @rafnael8807
      @rafnael8807 2 года назад +3

      just add the print(convert(x)) statement

    • @pharmacist2576
      @pharmacist2576 Год назад

      @@rafnael8807 what about:
      def miles_km_converter(km, miles):
      km = 1.6 * miles
      print("km ")
      print(km)
      miles = 5
      miles_km_converter(km, miles)

  • @orthodox8224
    @orthodox8224 6 лет назад +7

    def convert(miles):
    print(1.6*miles)
    miles = int(input("Enter miles :"))
    convert(miles)

  • @xmisteralex
    @xmisteralex 4 года назад +6

    I did:
    def convert(miles):
    return 1.609*miles
    km=convert(150)
    print("km =",km)
    km = 241.35

  • @scorpiomischief
    @scorpiomischief 4 года назад

    I have been on app after app and watched tutorial after tutorial, but this is the first video I've seen that explained things clearly and directly using simple terms I could understand. I'm going to be a subscriber of yours forever now! You definitely have a gift for teaching. So many folks in computer science (even if they're brilliant coders) have difficulty explaining their process in a concise way. So thank you; you're a life saver! I'm going to go turn off my adblock now and re-watch this in gratitude :)

  • @supersoniq4102
    @supersoniq4102 2 года назад

    I was having a tough time understanding Functions from my other teachers since i'm new to .py. In Less than a Minute you've made it seem like ABC. You are a genius!!

  • @thejackgoldenbergsho
    @thejackgoldenbergsho 5 лет назад +8

    Hi, I am not that knowledgeable, but in minute 9:30 in this #3 Functions video, it is not clear why when you run the program a second time and call the function, the number 12 appears as a calculation but without the other two print commands.... WHY NOT?

    • @liquidsunsets194
      @liquidsunsets194 3 года назад

      if you run the function it will print the first two print commands but for the last return command its evaluating some value and return it as an output .. in order to print that value you have to assign it to a variable and then print it ... if you try to do these steps with a function that has no return command you’ll get (none) as in no output bcs you didnt include it in the function
      I hope this makes any sense but think of it as having a calculated value that you want to print but first need to assign a variable to it ^ ^

  • @shubhamkawade317
    @shubhamkawade317 5 лет назад +5

    so it's dec 2019, i know i'am late, but you saved me. thank you so much!

  • @adzefeabdulraman652
    @adzefeabdulraman652 6 лет назад +6

    I have been missing a lot.I just subscribed to your channel yesterday. I'm enjoying it.God bless you

  • @goodnessgideon8960
    @goodnessgideon8960 2 года назад

    wasn't understanding but later got a hang of it, cs dojo is the best coding tutor
    thanks

  • @martijnvangelder1902
    @martijnvangelder1902 Год назад

    Thanks bro, your calm demeanor made me understood functions immediately. I'm a guy studying chemistry, and have to take a class in python. I hope I pass, and if I do, it'll be because of your videos.

  • @xodiaki
    @xodiaki 4 года назад +3

    my solution:
    miles = int(input("Enter the amount of miles you'd like to convert :"))
    def convert(miles):
    return miles * 1.6
    km=convert(miles)
    print(km)
    kms=int(input("enter the amount of kms you'd like to convert :"))
    def convet_km(kms):
    return kms/1.6
    mile=convet_km(kms)
    print(mile)

    • @rinovichaz3168
      @rinovichaz3168 4 года назад +1

      If you convert your input as float instead of int it will be more accurate i think. I tried ur code using the input of 100.99999 an the conversion was a little off... using a float instead of an integer will not ignore decimals and therefore will give you the most accurate result. But ur code helped me out a little so thanks

    • @xodiaki
      @xodiaki 4 года назад

      @@rinovichaz3168 you're welcome and yes float will work better !

    • @Strawhaty
      @Strawhaty 4 года назад

      @@xodiaki surely your code would work without the miles? why use them??

    • @xodiaki
      @xodiaki 4 года назад

      @@Strawhaty what do u mean lol

  • @PNCNDNOB
    @PNCNDNOB 4 года назад +5

    learning so much here, i am going to get a official course on Pyhton (because i have to do some studies or work from the government here in the Netherlands), so i think that is going to be way easier now.. thanks a lot! as soon as i get a job again i am donating some money to you bro!!

  • @hashpants8034
    @hashpants8034 7 лет назад +64

    Could you please explain RETURN in more detail please.

    • @swallowedinthesea11
      @swallowedinthesea11 7 лет назад +17

      Return value gets stored and saved into a variable.
      def addSum(num, num2):
      return num + num2
      answer = addSum(500, 100)
      # answer = return 500 + 100
      # answer = return 600
      # variable answer is now equal to the return value 600.

    • @koconutto
      @koconutto 7 лет назад +11

      I Didnt understand return very good

    • @WhoForgot2Flush
      @WhoForgot2Flush 6 лет назад +21

      If anyone still needs helps, just think of a return as the value of the function. For instance at the end when he writes...
      km = convert(miles)
      you know the "convert" function will need to return something, can be an integer or a string or anything, because you are storing the returned value of the function to a variable. If you did not have a return in the convert method you would not be able to store it to a variable. Inside this function would be...
      return 1.6 * miles
      if you didn't put the return there it would still execute the code but you would not be able to say km = convert(mile) since the function would not be returning anything.

    • @KlimYadrintsev
      @KlimYadrintsev 6 лет назад +1

      Mike Naples thanks

    • @KlimYadrintsev
      @KlimYadrintsev 6 лет назад

      11swallowedinthesea thanks

  • @logantucker1835
    @logantucker1835 Год назад

    Watching this at the gym. Way more helpful than the class I’m taking

  • @tasneemalshamsi1852
    @tasneemalshamsi1852 3 года назад

    U don't even know how much this helped me .. I couldn't get the idea of this def thing until I saw ur vid and I'm so thankful that God leaded me to u .. seriously THANK U

  • @xxss97ssxx
    @xxss97ssxx 4 года назад +4

    mil = input("Enter miles: ")
    miles = float(mil)
    def convert(miles):
    km = 1.6 * miles
    return km
    conversion = convert(miles)
    print(conversion)

    • @alokpatnaik692
      @alokpatnaik692 4 года назад

      1 mile = 1.6 km
      So 1 km = 1 mile/1.6

    • @KrolPower
      @KrolPower 4 года назад +1

      You can also combine your first two lines to simplify and organize a bit better. Ex:
      miles = float(input("Enter miles:"))
      That way you don't have an extra variable to keep track of.

    • @elantris-2002
      @elantris-2002 4 года назад +2

      @@KrolPower I did it like this lol xD
      x = 1.6
      def c1 (x, y):
      return 1.6*y and print (1.6*y)

    • @KrolPower
      @KrolPower 4 года назад

      @@elantris-2002 lmao

    • @elantris-2002
      @elantris-2002 4 года назад +2

      @@KrolPower but it works 😂

  • @Akuphakpa
    @Akuphakpa 7 лет назад +5

    Finally i got this video. I has been waiting from your last video(if else statement )thank you so much yk ..

  • @sagnik0397
    @sagnik0397 4 года назад +3

    miles=int(input("Enter distance to miles: "))
    def conversion():
    km=1.6*miles
    return km
    print("Distance in kilometres is ",end="")
    print(conversion())
    #lemme know if I am correct or any way to improve the code.

    • @simeonnenov3499
      @simeonnenov3499 3 года назад

      miles=int(input("Enter distance to miles: "))
      Instead of int, you can put float, so that the code does not crash when someone enters a number with a "." Like 100.2

    • @sagnik0397
      @sagnik0397 3 года назад

      @@simeonnenov3499 yeahhh thanks a lot for helping

  • @dukhtarakhtar
    @dukhtarakhtar 2 года назад

    I tried after taking your 2 classes nd boom feeling like an expert btw it's my 1st programming language that I'm learning

  • @MAFABI-g7e
    @MAFABI-g7e Год назад

    These tutorials for YK are making me to improve day and night on python

  • @briangrey4849
    @briangrey4849 5 лет назад +6

    bmi_calculator(name, height_m, weight_kg):
    bmi = weight_kg / ( height_m**2)
    so here arguments/variables are name, height_m, weight_kg and name1, height_m1, weight_kg1 are different than name, height_m, weight_kg then when return result, how bmi knows that it has to do weight_kg1 / ( height_m1**2). i think it should only work for weight_kg, and height_m values as that values are in function and in bmi formula. weight_kg1 ,height_m1 are totally different values than weight_kg, height_m then how it works ?

    • @albertoavena
      @albertoavena 5 лет назад +1

      brian grey I have the exact same question and I'm been trying to figure it out for 2 days now! Where is name, height_m and weight_kg getting the values from if the three people you defined have different names??

    • @maamooon7910
      @maamooon7910 5 лет назад +2

      well im not the only one through 😂

    • @jaydebbhunia3676
      @jaydebbhunia3676 5 лет назад

      hey, Change the name of def value (name, height_m, weight_kg) to (a, b, c) still it will work - because that is the condition which is assigned to def function

    • @michaelmartinez8470
      @michaelmartinez8470 5 лет назад

      name, height_m, weight_kg are parameters that live inside the function bmi_calculator, used to calculate the bmi. you can think of them as "this" and "that" and "alsothis" or "a", "b", "c" or "x", "y", "z". they're just arguments; the function uses "three things". it calculates bmi by using (c divided by b**2 (or b squared)) and returns "name" or "this" or "a" or "x" + a printed string. it also "returns" a new value bmi but does so by printing it as a string, so it might be confusing. bmi still lives within the function.
      "result1 = bmi_caculator(name1, height_m1, weight_kg1)" is like saying "call the function bmi_calculator (which accepts three parameters), and execute it and assign to variable result1". it assigns result1 by plugging three arguments or parameters into the function. in result1's case its plugging in "YK" for name in bmi_calculator(name, height_m, weight_kg), "2" for height_m in bmi_calculator(name, height_m, weight_kg), and "90" for weight_kg in bmi_calculator(name, height_m, weight_kg). the confusion is probably coming from the parameter names being named similarly to the variable names. name1 could have been a variable t = "YK" and height_m1 could have been u = "2" and weight_kg1 could have been v = "90" and it could have been "result1 = bmi_calculator(t, u, v)" and it would have worked exactly the same.

  • @simantoahmed9849
    @simantoahmed9849 4 года назад +11

    I still don't understand that "return" string. Once called in function it appears but when calling BMI calculator, it doesn't appear until result1,2,3

    • @raves_r3177
      @raves_r3177 4 года назад +3

      the bmi calculation is already printed inside the function.The return does not print in the terminal unless printed in the main code. It's just like calling a built in function x = upper("hello"), you dont leave it like that because it does not print itself. you have to print it using print(x).

    • @arjunjain87
      @arjunjain87 4 года назад +2

      Because by using the return function we are 'returning' or 'assigning' the value to result1,2,3 or any other variable, it is just like, a = 5, so u will get 5 when u print(a) instead of when calling the function. Hope this helps. . . .

  • @nathanst-laurent8583
    @nathanst-laurent8583 6 лет назад +6

    NameError Traceback (most recent call last)
    in ()
    ----> 1 result1 = bmi_calculator(name1, height_m1, weight_kg1)
    2 result2 = bmi_calculator(name2, height_m2, weight_kg2)
    3 result3 = bmi_calculator(name3, height_m3, weight_kg3)
    what do I do?

    • @perry_cop
      @perry_cop 4 года назад

      yeah same

    • @perry_cop
      @perry_cop 4 года назад

      ok this comment is 2 year old did you get it

    • @George-pt2ot
      @George-pt2ot 4 года назад

      @@perry_cop lol

  • @mashiburrahmankhan2584
    @mashiburrahmankhan2584 4 года назад

    This is the best Python video so far. Your whole playlist is also extremely helpful. I tried to find other beginners python videos but yours is THE BEST, very well explained and elaborated! Great job!

  • @jieweikwan
    @jieweikwan 5 лет назад +1

    Hello YK! Just wanted to say I hardly had any interests in other videos - eg from Coursera as they were usually not straight to the point. But your videos keep me going n the step by step allows me to imprint the steps into my head! I think this is really important for someone who can’t listens to Long lectures and am really thankful to have found your video 🥺

  • @AntiagingVideos
    @AntiagingVideos 5 лет назад +5

    Hi dojo and thank you for the great tutorial. When you say
    "a function is a collection of structures". What is a structure?
    Thank you!

  • @oleksandrherasymenko3167
    @oleksandrherasymenko3167 6 лет назад +23

    So love your "Ahhhhh" stuff.

  • @evelynwang4818
    @evelynwang4818 4 года назад +3

    wow i learned more in the first 3 vids than i did taking a four week summer camp python course. thank you so much ! im in eighth grade and this understandable even for beginners.

  • @shudanhao8643
    @shudanhao8643 3 года назад +1

    Thank you so much. i am a new learner of python, the return and function are really confusing for me. This video perfectly explained them for me.
    Keep up the good work!!!

  • @mukhtarabdi8731
    @mukhtarabdi8731 2 года назад

    Thanks Sir for your introductory course to Python. I am a novice in python but have R prgoramming background. You made the whole learning process easy.
    here is the exercise which I have tried:
    # Write a function that converts 100 miles to km
    def conv_miles_km(miles):
    km = miles * 1.6
    print('100 miles is equal to {}'.format(km))
    # return km
    # call the function
    conv_miles_km(100)
    100 miles is equal to 160.0

  • @pilgrim273
    @pilgrim273 4 года назад +4

    print('hello yk')
    name = tom
    print(name)
    print('here and i want to thank you for the videos you create which are much better than how my teachers teach at school'')

  • @Chucky5525
    @Chucky5525 5 лет назад +4

    My miles to kilometer converter:
    def convert(miles):
    return 1.6 * miles
    def temp(x):
    return 1 * x
    a = convert(4)
    x = 4
    print(x)
    print(a)
    print(x, "miles is", a, "km")

  • @rubikulelerubiksandukulele4607
    @rubikulelerubiksandukulele4607 6 лет назад +10

    Is my code correct?
    When I run it, I got 32 :-)
    def mile(km):
    return 1.6*km
    print (mile(20))

    • @Xous_
      @Xous_ 4 года назад

      Miley Blutatu no it’s a = mile(20) print(a)

    • @ToshDeCamerz
      @ToshDeCamerz 4 года назад

      @@Xous_ mileys code is much more efficient and writing a=.... Is unnecessary

  • @anuragd398
    @anuragd398 4 года назад

    Best Tutorial In RUclips CS Dojo

  • @harshp2577
    @harshp2577 4 года назад

    I've watched this video like 5 times trying to understand why the bmi code works the way it does. Finally got it

  • @alfredtubale790
    @alfredtubale790 6 лет назад +6

    Hi! Whenever I place "?" on my python file title, it errors. Why was yours working?

    • @fp_hav1s712
      @fp_hav1s712 4 года назад

      same i cant place "?" after i write "What are functions"

    • @toeknee4689
      @toeknee4689 4 года назад

      @@fp_hav1s712 I know this is a necropost, but it's because windows doesn't allow files to have things like question marks and commas in its file names

  • @tyres9
    @tyres9 5 лет назад +4

    def convert(mile):
    km = 1.6 * mile
    return str(mile)+ " miles is " + str(km) + " kms"
    a = convert(float(input("input distance in miles: ")))
    print(a)

  • @QazDiaries
    @QazDiaries 4 года назад +3

    Def convert(miles):
    print (miles, "miles is", km, "kilometres")
    return 1.6 * miles
    km = convert(miles)
    convert(2)
    print(km)
    2 miles is 3.2 kilometres

  • @Call.Me.Sly.
    @Call.Me.Sly. 3 года назад

    I should have known you a little earlier...You're the best and now I wanna take a course in python, I was here doing it for fun but you've inspired me.

  • @sagharxatami6648
    @sagharxatami6648 3 года назад

    I'm in love with your explanation. everything was obvious and understandable, but one point to those who actually code the same thing in their editor, if you run the program and don't get the result, try to read it one by one like python does and also pay attention, that if you actually haven't mentioned the value of your parameter in your function. After all, python won't understand if you use or call it in your function because everything you type in function is counted as the function's work so try to check out to make sure you didn't make that mistake and to make sure, you can basically look at your code to see the spaces and if there are 4 spaces where you mentioned the function it means you have called it in a function and to solve that problem you can go ahead and delete those spaces to begin from the beginning of the line. hope u understand me well.

  • @hanpeng9501
    @hanpeng9501 6 лет назад +4

    hi Dojo, i have a question. When i define a function just like you do , why this is a error called "name' function' is not defined"

    • @RizwanAbdul29
      @RizwanAbdul29 6 лет назад

      Same error for me also

    • @deepakjohnson6099
      @deepakjohnson6099 6 лет назад

      type as name1 = ( "hang peng" )

    • @nowwetalking6940
      @nowwetalking6940 6 лет назад

      you have to write the full name i.e function1/function2 (the name you defined) and not just function

    • @mlmaster8586
      @mlmaster8586 6 лет назад

      Hi Han Peng, I have the same trouble like what you face, and finally after checking all my script I found that I missed spell one of my script, so I suggest to check it carefully because maybe there some wrong wiitten word

  • @InsaneI
    @InsaneI 6 лет назад +6

    4:25 I hope they werent executed. I dont like seeing lines being killed

  • @TheHyrossl
    @TheHyrossl 4 года назад +31

    Here is my solution:
    def convert_km(miles):
    return 1.6*(miles)
    def convert_miles(km):
    return km / 1.6
    x = convert_km(20)
    y = convert_miles(10)
    print(x)
    print(y)

    • @examupdates3977
      @examupdates3977 4 года назад +1

      Great

    • @charliepickford8554
      @charliepickford8554 4 года назад +4

      What I did was:
      milesinput = 13
      def converter(miles):
      return (miles * 1.6)
      d = converter(milesinput)
      print(milesinput, "miles =", d, "km")

    • @sippincay
      @sippincay 4 года назад

      i did
      km = 5
      def convert(miles):
      print(“miles: “)
      print(km * 1.6)
      result1 = convert(miles)

    • @Kemachris
      @Kemachris 4 года назад

      '''very clean i like it! Mine is a bit clunky and only goes one way, but atleast i made it take user input :p '''
      miles = int(input("How many miles would you like to convert to KM's? "))
      def km(miles):
      km = miles * 1.6
      print((round(km,2,)), end="", flush=True)
      print(" KM's")
      km(miles)

    • @drdre1964
      @drdre1964 4 года назад

      Here's mine.
      def convert(miles):
      print(miles," miles is ",miles*1.6," kilometers")
      def convert2(km):
      print(km," kilometers is ",km/1.6," miles")
      a=convert(100)
      b=convert2(160)

  • @kingsleyosuala1423
    @kingsleyosuala1423 2 года назад

    Thank you so much CS Dojo, I have learned a lot from your tutorials. did the assignment, that converts miles to kilometer and also from kilometer to miles. I went further to ask the user for input.
    unit = str(input('What do you want to convert? Enter m for miles or k for kilometer: '))
    distance = eval(input('Enter distance: '))
    km = 1.6 * distance
    miles = distance / 1.6
    def convert():
    if unit == "m":
    return km
    elif unit == "k":
    return miles
    result = convert()
    if unit == "m":
    print(distance, "miles is equal to: ", result, "km")
    elif unit == "k":
    print(distance, "kilometer is equal to: ", result, "miles")

    else:
    print("Invalid unit or distance; enter m for miles or k for a kilometer and enter distance as a numeric value")

  • @bartkornacki3590
    @bartkornacki3590 3 года назад

    CS Dojo you put things into the plain explanation-something that the other tutorials lack

  • @saiyamnahata8510
    @saiyamnahata8510 6 лет назад +5

    14:30 1 mile = 1.6km and not the reverse

  • @Cmog884
    @Cmog884 4 года назад +53

    I feel like I can remake skyrim

    • @rdenel7126
      @rdenel7126 4 года назад +5

      killleeed me xDDDDDD
      I FELT LIKE I COULD FIX CYBERPUNK GLITCHES

    • @levnikitin7432
      @levnikitin7432 4 года назад +2

      @@rdenel7126 damn i think even for world's most infamous coders fixing cyberpunk would be difficult

    • @cybernerd7492
      @cybernerd7492 4 года назад +2

      Yes

    • @matmattarayao1277
      @matmattarayao1277 3 года назад

      @@cybernerd7492 sup cyberfucked

    • @cybernerd7492
      @cybernerd7492 3 года назад

      @@matmattarayao1277 sup dog😎

  • @stratecheese1302
    @stratecheese1302 6 лет назад +15

    There's one part that I'm still confused is about the bmi calculator you made
    you said:
    def bmi_calculator(name, height_m, weight_kg)
    in this part, you didn't denote the three variables with the numbering 1,2,3.
    and then in the part of:
    result1=(name1, height_m1, weight_kg1)
    why is this possibly works when it seems that "name" and "name1" are two different variables?

    • @nataliehall9416
      @nataliehall9416 6 лет назад +1

      I am curious about this as well.

    • @patrickw421
      @patrickw421 6 лет назад +14

      because (name, height_m, weight_kg) is just the name you use when defining the function and when you say result1 = bmi_calculator(name1, height_m1, weight_kg1) you actually put the value of name1 into the name variable of the function "bmi_calculator" and so on, meaning whenever you say bmi_calculator, the first value will fit into the name variable of the function, the 2nd goes to height_m and 3rd goes to weight_kg.
      If you do not assign those value first, you can even input the value directly something like result5 = bmi_calculator("ABC", 1.9, 80) and get the bmi

    • @heliamvs2035
      @heliamvs2035 6 лет назад +1

      Patrick Wong Thanks man

    • @pheonixeye_1162
      @pheonixeye_1162 6 лет назад +1

      Mate those three variables name, height.. Are just like dummy variables and those are just used to pass the values to the function so that calculations can be performed in this case the value of name1 will be passed on to the variable name and so on

    • @cripplingaddict
      @cripplingaddict 6 лет назад +2

      If you want a technical answer, the argument variables when you create the function are only local to the function and only reference the variables you pass through the actual function (the scope of those variables are inside the function). But for a simpler answer, they are just placeholder for actual variables to be used as arguments in the function. He might have confused you for not choosing different names but just note that you could put any name in the arguments and it will work the same.

  • @joseph5166
    @joseph5166 4 года назад

    I love that you can see even a simple function can be performed in all sorts of different ways from the comments here. Here's what I got:
    def convert_miles_to_km(miles):
    km = 1.6 * miles
    print(miles, "miles is equivalent to", km, "kilometers.")

  • @richardbryan4094
    @richardbryan4094 6 лет назад +11

    why tf do i need school, if i spend my whole day watching your tutorials

  • @allridio
    @allridio 5 лет назад +8

    Def convert(miles)
    Km = 1.6*miles
    Print(miles)
    Return km
    M=convert(any value)
    Print(M)

  • @anemawbishaw2827
    @anemawbishaw2827 4 года назад +4

    It's harder than i thought 😨

  • @Sam-uc2qh
    @Sam-uc2qh 3 года назад

    this is probably the best video explaining functions that i can find on the internet!

  • @Partyhardrocker
    @Partyhardrocker 3 года назад

    i like randomly wanted to learn how to attach html spotify link to my tumblr and all of the sudden here i am on part 3 learning about python. IM YELLING its so fun

  • @friendsarelife-lifeisshort381
    @friendsarelife-lifeisshort381 6 лет назад +6

    How can I use your tutorials without the internet?

    • @RajeshSinghGautam
      @RajeshSinghGautam 6 лет назад +3

      FriendsAreLife - LifeIsShort save the video offline