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
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
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..
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.?
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.
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.......
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....
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.
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)
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?
@@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
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
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
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
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"?
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)
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
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.
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?
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
I am unable to understand the today class
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
Page not found 404????
Page 404
Visit exercise from function video and then check full directory of exercises! You will find every video exercises!
if i open the link its showing page not found
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..
I watched different tutorials in loops, and this is the best video I have ever seen! Easily understandable!
☺️👍
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.?
Awesome karthik chekuri, code looks very good
This code is not working
Sir without declaring the items how you item put in print plz clearfy this doubt
I watched different videos from other tutorial regarding loops and this one I understand the most. Thank you!
Learn data science with python and pandas: ua-cam.com/video/CmorAWRsCAw/v-deo.html
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.
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.......
Great. I wish you all the best prajwal 😊👍
thnks sir.
incase if you want to print only odd number then use i%2!=0
where can I get more challenging exercises. you are such a great teacher I need harder problems
hackerrank and other websites..
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....
for i in range(1,6):
s=i**2
if s%2==1:
print(s)
#output :
1
9
25
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.
Revise for loop exercise video description
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)
you explain in a great way with those explanations beside the code is awesome.Thanks
Glad it helped!
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?
Hello Amazing Sir, the exercise files aren't working, would be huge favor if you take-care of it.
the printing of square of only odd numbers
this approach is also effective :
for i in range(1,10,2):
print(i*i)
Hindi WALI video kha hau
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 '
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
@@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
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
Good explanation, but at 02:15 .... How do you know we aren't already grandfathers?? 😁 Mature people reskill too you know 😂😂
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
Write the last print statement out of the for loop
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
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
Can I give while condition and another condition ime giving 2 conditions using and operator just like we do in if statement
Granddaddy hha
The "continue " code ....wow! i=i+1 very important!
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"?
not only numbers,An "item" is a general term that can refer to any object within a collection.
if i want to print n numbers so what should I give the range ?
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)
Good Morning Sir. Is this same for notepad? What you are explaining in pycharm and python 3
man this guy loves his monthly expenses XDXD
Thankyou, i couldn't still do the exercises tho;/
Appreciate it, bro. Thanks
great channel to learn data science skills with projects.
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
i think ,it breaks the execution from only if_else condition. since there no other condition inside for loop, execution gets terminated
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.
hi Sir , i have one doubt in example of for loop with continue statement when we use conitnue statement else statement is not required?
Nope. When you continue the control flow goes back to next iteration in for loop and you don't need else
Superb explanation sir ☺️😊
sir your videos are really very great
Idk u could use c# for that
thank you for the excellent content and work!
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?
It is happening because you indented the final print command, remove the indentation to remove the print command from the for loop
Awesomeeeeeeeee
great
😘
Nice sir
6:58
well explained
Gurpreet, I am happy this was helpful to you
in 5:47, is "item" a keyword used with for loop?
Yes item is a keyword