9. For loop [Python 3 Programming Tutorials]

Поділитися
Вставка
  • Опубліковано 29 вер 2024

КОМЕНТАРІ • 74

  • @codebasics
    @codebasics  2 роки тому

    Do you want to learn python from me with a lot of interactive quizzes, and exercises? Here is my project-based python learning course: codebasics.io/courses/python-for-beginner-and-intermediate-learners

    • @hemanthb5913
      @hemanthb5913 2 роки тому

      I am unable to understand the today class

  • @codebasics
    @codebasics  4 роки тому +6

    Here is the link of exercise along with the solution, please work on it as it will make your learning solid: github.com/codebasics/py/blob/master/Basics/Exercise/9_for/9_for_exercise.md

  • @ausafumarkhan5363
    @ausafumarkhan5363 4 роки тому +17

    Dear sir, I am watching the tutorials from last 7 days. The way of explaining the concept with example is very much effective and easy to get the things..

  • @AchuVlogs
    @AchuVlogs 3 роки тому +16

    I watched different tutorials in loops, and this is the best video I have ever seen! Easily understandable!

  • @karthikchekuri4781
    @karthikchekuri4781 4 роки тому +5

    how do i check if my code is good and it is the optimised code or not? for instance
    for the one of the practice example:
    1. This solution is given by dhaval (codebasics)
    month_list = ["January", "February", "March", "April", "May"]
    expense_list = [2340, 2500, 2100, 3100, 2980]
    e = input("Enter expense amount: ")
    e = int(e)
    month = -1
    for i in range(len(expense_list)):
    if e == expense_list[i]:
    month = i
    break
    if month != -1:
    print('You spent',e,'in',month_list[month])
    else:
    print('You didn\'t spend',e,'in any month') month_list = ["January", "February", "March", "April", "May"]
    expense_list = [2340, 2500, 2100, 3100, 2980]
    e = input("Enter expense amount: ")
    e = int(e)
    month = -1
    for i in range(len(expense_list)):
    if e == expense_list[i]:
    month = i
    break
    if month != -1:
    print('You spent',e,'in',month_list[month])
    else:
    print('You didn\'t spend',e,'in any month')
    2. My solution is:
    expense_list = [2340, 2500, 2100, 3100, 2980]
    month_list = ['jan', 'feb', 'march', 'april', 'may']
    expense_amount = int(input('please enter an amount number: >>> '))
    for i in range(len(expense_list)):
    if expense_amount == expense_list[i]:
    print (expense_list[i],' was spent in', month_list[i])
    break
    else:
    print('expense amount is not available')
    please help me how can I check a good is optimized code.?

    • @prasadhrv
      @prasadhrv 2 роки тому +1

      Awesome karthik chekuri, code looks very good

    • @lumbiniinfotech
      @lumbiniinfotech 8 місяців тому

      This code is not working

  • @mdasif-ze7bc
    @mdasif-ze7bc 2 роки тому +2

    Sir without declaring the items how you item put in print plz clearfy this doubt

  • @puddinfacekiki
    @puddinfacekiki 4 роки тому +8

    I watched different videos from other tutorial regarding loops and this one I understand the most. Thank you!

  • @codebasics
    @codebasics  5 років тому

    Learn data science with python and pandas: ua-cam.com/video/CmorAWRsCAw/v-deo.html

  • @tsaltslinger3268
    @tsaltslinger3268 3 роки тому +1

    John 15:11-14 (KJV) These things have I spoken unto you, that my joy might remain in you, and that your joy might be full.
    This is my commandment, That ye love one another, as I have loved you.
    Greater love hath no man than this, that a man lay down his life for his friends.
    Ye are my friends, if ye do whatsoever I command you.

  • @prajwalbhandari8541
    @prajwalbhandari8541 4 роки тому +3

    well you have created amazing tutorial till now, few months back I started with C and now these tutorials are really good, i think i will be watching whole play list.......

    • @codebasics
      @codebasics  4 роки тому +3

      Great. I wish you all the best prajwal 😊👍

  • @nadeemhalbhavi9274
    @nadeemhalbhavi9274 4 роки тому +1

    thnks sir.
    incase if you want to print only odd number then use i%2!=0

  • @arasukiasyan1
    @arasukiasyan1 Рік тому +1

    where can I get more challenging exercises. you are such a great teacher I need harder problems

    • @NibirWorks
      @NibirWorks Рік тому

      hackerrank and other websites..

  • @ganeshgunjal4220
    @ganeshgunjal4220 3 роки тому +1

    very useful assignments sir... they are definitly developing logic... most of time i use solution due to lack of logic.. but still it is useful... thanks for taking efforts for us....

  • @TechBalu
    @TechBalu 6 місяців тому

    for i in range(1,6):
    s=i**2
    if s%2==1:
    print(s)
    #output :
    1
    9
    25

  • @OrangeTiramisu
    @OrangeTiramisu 8 місяців тому

    2:09 "...what if your list had like hundred items in it. If you start writing all of these, you'll become granddaddy by the time you're done writing this." 🤣😂🤣😂
    Great and informative tutorial, with a hilarious teacher. Thank you.

  • @sprudviraj3759
    @sprudviraj3759 3 роки тому +1

    Revise for loop exercise video description

  • @kkumari4746
    @kkumari4746 Рік тому

    Hi sir this is krishna, daily iam following these videos but for loop video it is a bit of confusion while iam practicing on pycharm.
    (while, continue, break point)

  • @starman8505
    @starman8505 3 роки тому +1

    you explain in a great way with those explanations beside the code is awesome.Thanks

  • @D4nte-RN
    @D4nte-RN Рік тому

    Hello,
    Thank you, very much for your involved with teaching us with very simple and understanding way!
    According your suggestion, aftera watched your tutorial I switch to exerecises and I tried to doing myself.
    I have a problem with your 3-rd exercises and solution. Why in the code there's:
    "month = -1" and "month != -1" and whay even I put here value "month = -10" and "month != -10" it sill working correctly?

  • @muhammadzakiahmad8069
    @muhammadzakiahmad8069 3 роки тому

    Hello Amazing Sir, the exercise files aren't working, would be huge favor if you take-care of it.

  • @vasusharma2394
    @vasusharma2394 Рік тому

    the printing of square of only odd numbers
    this approach is also effective :
    for i in range(1,10,2):
    print(i*i)

  • @divyanshu901
    @divyanshu901 2 роки тому

    Hindi WALI video kha hau

  • @K-mk6pc
    @K-mk6pc 4 роки тому +1

    sir can you make a new video on for loop because i am watching every videos in series but this is more complifated it seems '

    • @codebasics
      @codebasics  4 роки тому

      Kiran, I have Hindi channel too. Codebasics Hindi. Watch tutorials there. You might be able to understand better as o have new and better videos there

    • @K-mk6pc
      @K-mk6pc 4 роки тому

      @@codebasics
      Sir thank you soo much basically my mother tongue is Kannada Anyways I will look through it sir can you provide me your contact details??? BTW I wish to make my career in data science soo i thought for asking you as a matter of reference
      Tq

  • @jhansireddy6110
    @jhansireddy6110 2 роки тому

    Hello sir .. thank you... your videos are really helpful ..I have a boudt. When I run a program in pycharm it is showing "some file is running parallel. " and a dialouge box showing " stop running any way" or " cancel". Please help me with this

  • @jaybee2402
    @jaybee2402 4 роки тому

    Good explanation, but at 02:15 .... How do you know we aren't already grandfathers?? 😁 Mature people reskill too you know 😂😂

  • @sank1388
    @sank1388 4 роки тому

    with the below code I am getting this output . Can you help
    exp = [2340,3455,4500,2344,2133]
    total=0
    for i in range(len(exp)):
    print('Month:',(i+1),'Expense:',exp[i])
    total=total+ exp[i]
    print('total exp:',total)
    output:
    Month: 1 Expense: 2340
    total exp: 2340
    Month: 2 Expense: 3455
    total exp: 5795
    Month: 3 Expense: 4500
    total exp: 10295
    Month: 4 Expense: 2344
    total exp: 12639
    Month: 5 Expense: 2133
    total exp: 14772

    • @lumbiniinfotech
      @lumbiniinfotech 8 місяців тому

      Write the last print statement out of the for loop

  • @sharmasudeep8526
    @sharmasudeep8526 3 роки тому

    with the same code my console is printing all the outputs like sum of first than second than third and so on and not like you have shown the output

  • @irfanshah4383
    @irfanshah4383 2 роки тому

    why my total showed to me like this
    "C:\documents\python projects\venv\Scripts\python.exe" "C:/documents/python projects/for loop.py"
    month 1 expense 2340
    month is 2340
    month 2 expense 2500
    month is 4840
    month 3 expense 2100
    month is 6940
    month 4 expense 3100
    month is 10040
    month 5 expense 2980
    month is 13020
    Process finished with exit code 0

  • @debojitmandal8670
    @debojitmandal8670 3 роки тому

    Can I give while condition and another condition ime giving 2 conditions using and operator just like we do in if statement

  • @surrealsoupuniverse
    @surrealsoupuniverse Рік тому

    Granddaddy hha

  • @tsaltslinger3268
    @tsaltslinger3268 3 роки тому

    The "continue " code ....wow! i=i+1 very important!

  • @peanutlifter9730
    @peanutlifter9730 Рік тому

    How does python know that "item" refers to the numbers in the list if it isnt written as a variable? Does it automatically assign the numbers as "item"?

    • @NibirWorks
      @NibirWorks Рік тому

      not only numbers,An "item" is a general term that can refer to any object within a collection.

  • @deekshashadakshari7474
    @deekshashadakshari7474 2 роки тому

    if i want to print n numbers so what should I give the range ?

  • @surewin3006
    @surewin3006 3 роки тому

    Hi, in exercise number 5, i tried below code and it seems working and giving same result. Not sure why need 2 range functions in the solution. Please enlighten me. Thanks, and as always more power to your channel. It's very helpful...
    Star = ""
    for i in range(1, 6):
    Star += "*"
    print(Star)

  • @-GRajesh
    @-GRajesh 4 роки тому

    Good Morning Sir. Is this same for notepad? What you are explaining in pycharm and python 3

  • @talhakhan-ht6hj
    @talhakhan-ht6hj 2 роки тому

    man this guy loves his monthly expenses XDXD

  • @ragragrec1
    @ragragrec1 3 роки тому

    Thankyou, i couldn't still do the exercises tho;/

  • @river.
    @river. 2 роки тому

    Appreciate it, bro. Thanks

  • @alishmed5936
    @alishmed5936 2 роки тому

    great channel to learn data science skills with projects.

  • @MrPrudhvisai
    @MrPrudhvisai 4 роки тому

    How for loop is terminated if we write break statement inside the if condition, i thought for loop will break only if break statement is under for loop condition. please elaborate this

    • @NibirWorks
      @NibirWorks Рік тому

      i think ,it breaks the execution from only if_else condition. since there no other condition inside for loop, execution gets terminated

  • @mohitmakhija8638
    @mohitmakhija8638 3 роки тому +2

    In the solution for the exercise for the topic, line 64 says 'print("You....' but it should say 'print(f"You...'. Just a minor thing in an otherwise brilliant series.

  • @khemrawat4144
    @khemrawat4144 4 роки тому

    hi Sir , i have one doubt in example of for loop with continue statement when we use conitnue statement else statement is not required?

    • @codebasics
      @codebasics  4 роки тому +1

      Nope. When you continue the control flow goes back to next iteration in for loop and you don't need else

  • @dharanibadri2530
    @dharanibadri2530 2 роки тому

    Superb explanation sir ☺️😊

  • @helloworld2740
    @helloworld2740 3 роки тому

    sir your videos are really very great

  • @BarredTitan
    @BarredTitan 3 роки тому

    Idk u could use c# for that

  • @hisky74
    @hisky74 3 роки тому

    thank you for the excellent content and work!

  • @yogeshgupta5112
    @yogeshgupta5112 4 роки тому +1

    Sir, I am running the same code as you created.
    but I am getting this :
    Month: 1 Expense: 200
    Total expense is: 200
    Month: 2 Expense: 100
    Total expense is: 300
    Month: 3 Expense: 350
    Total expense is: 650
    Why 'Total expense is' repeating?

    • @leondsouza8598
      @leondsouza8598 4 роки тому +1

      It is happening because you indented the final print command, remove the indentation to remove the print command from the for loop

  • @fekuchand7803
    @fekuchand7803 3 роки тому

    Awesomeeeeeeeee

  • @hirakdas770
    @hirakdas770 3 роки тому

    great

  • @harshnaik6989
    @harshnaik6989 2 роки тому

    😘

  • @basebuiltclasses1401
    @basebuiltclasses1401 5 років тому

    Nice sir

  • @RevenueSharePartner
    @RevenueSharePartner 3 роки тому

    6:58

  • @gurpreettata
    @gurpreettata 4 роки тому

    well explained

    • @codebasics
      @codebasics  4 роки тому +1

      Gurpreet, I am happy this was helpful to you

  • @tabassumhossain811
    @tabassumhossain811 3 роки тому

    in 5:47, is "item" a keyword used with for loop?