Тёмный
No video :(

Python Exercises for Beginners - Exercise #1 

Programming with Mosh
Подписаться 4,1 млн
Просмотров 336 тыс.
50% 1

Looking for Python practices to learn Python better? Watch this video to practice Python.
🔥Subscribe for more Python tutorials like this: goo.gl/SjXTT7
🔥Python tutorial for beginners: • Python Tutorials for B...
Python Exercises for Beginners:
programmingwit...
Python Cheat Sheet:
programmingwit...
Want to learn more from me? Check out my blog and courses:
programmingwith...
/ programmingwithmosh
/ moshhamedani

Опубликовано:

 

29 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 201   
@shahilghale5163
@shahilghale5163 4 года назад
Please make more of these Exercises for each and different programming languages, having such questions can help us understand and strengthen our programming knowledge and understanding. With solutions to it as well. Seen your Python tutorial and its been a blessing to stumble upon your video! If I do happen to land a job, it'll be all thanks to you! Much love from Nepal! 🙌🙏
@panda9315
@panda9315 2 года назад
Here's a different solution for the first exercise: num = [] for x in range(2, 10, 2): print(x) num.append(x) c = len(num) print(f'We have {c} even numbers')
@adyyy00
@adyyy00 2 года назад
Ohh.. I did the same thing..
@maxnick7023
@maxnick7023 2 года назад
My sol'n is totally different 😐 a = range(1,5) for i in a: print(i*2) print(f"we have {i} even numbers") Is it good??
@i-will-trigger-you
@i-will-trigger-you 2 года назад
@@maxnick7023 go get another profession
@TheDrumtracks
@TheDrumtracks 3 года назад
counter = 0 for x in range(10): if x > 0: if x % 2 == 0: counter += 1 print(x) print("We have", counter, "even numbers! :)") Thank you! Nice Exercise!
@mishab8064
@mishab8064 4 месяца назад
Why would you ignore his hint at the beginning about using range(1,10). Could you explain why you would do x>0 instead of adding 1 to the range?
@RohitKumarRathi91
@RohitKumarRathi91 Год назад
for a in range(1,10): if a%2==0: print(a) b= a.bit_length() print(f"we have {b} numbers")
@prynsh7737
@prynsh7737 4 года назад
For i in range(1,10): If i % 2 == 0: Print(i) Print(“we have 4 even numbers”)
@radekspilka273
@radekspilka273 3 года назад
i am only one who feel so dumb after watching this?
@onlyforprogramming7916
@onlyforprogramming7916 3 года назад
No lol
@aiman7282
@aiman7282 3 года назад
I feel you
@666222333111
@666222333111 3 года назад
Meh it's easy. Loop it, check if it divides by 2 if yes + if no throw it out, print and done.
@brentdan68
@brentdan68 3 года назад
How it quite ez
@Luiz997488
@Luiz997488 2 года назад
Dont worry about feeling dumb. As long as you get the logic of the process you'll get better. We're all gonna make it 😉
@pastehl
@pastehl Год назад
c = 0 for i in range (10): if(i % 2 == 0 and i!= 0): print(i) c+= 1 print("There is "+str(c)+ " even numbers")
@pacosmosisx8607
@pacosmosisx8607 Год назад
This is how I solved this exercise: numbers = range(1, 10) count = 0 for i in numbers: if i % 2 == 0: count += 1 print(i) print(f"We have {count} even numbers")
@sivuyile3380
@sivuyile3380 3 месяца назад
You really saved me
@sivuyile3380
@sivuyile3380 3 месяца назад
Quick question, can you highlight what exactly (% , == , +=) mean and how they can be applied?
@KampfhelikopterTiger
@KampfhelikopterTiger 11 месяцев назад
Here is a different solution, bc a number with a comma number cant be an int and must be a float: even_num = [] for i in range(1, 10): if i/2 == int(i/2): even_num.append(i) print(i) print("There are " + str(len(even_num)) + " even numbers!")
@Just_Me_Being_Myself
@Just_Me_Being_Myself 4 года назад
Thank you so much for this,! Just getting started with Python (and programming in general), and was having trouble finding excercices like these.
@DevineInnovations
@DevineInnovations 5 лет назад
I got everything except for printing "We have 4 numbers" (before I looked at the solution). But in my defense, I don't think I've learned formatted strings yet. I also defined it as a function called evens(x,y), so that evens(1,10) gave me the right numbers. Thanks, this was a good exercise!
@DevineInnovations
@DevineInnovations 5 лет назад
BTW, I've never seen your channel before and I just realized this was uploaded a few days ago. I just happened to be searching "python practice" today.
@matankkanu1937
@matankkanu1937 6 месяцев назад
Syntax : count = 0 for i in range ( 1,11): if (i % 2)==0: print (i) count +=1 else: pass print(f"we have {count} even numbers") Nice exercise sir
@khalilsial1
@khalilsial1 4 года назад
Bro could you please make one complete video that have only exercises and their solution same like this one for beginners to the expert level programmers. Thanks
@spriteguy7819
@spriteguy7819 Год назад
for x in range(1,10): if x%2 ==0: print(x) print('We Have 4 Even Numbers') # I did this to get the output in the video
@ericadsuara1283
@ericadsuara1283 2 года назад
This really helps to brainstorm and have more knowledge if you want to take a course in computer science. Please make more courses in terms of coding and programming since it helps a lot of people who wants to learn the basics and have common knowledge in this course. Also please make more exercises like these so that we can brainstorm.
@doublebeanieba7633
@doublebeanieba7633 Месяц назад
Just starting my journey with Python! Learning so I can afford AC in this 105 degree weather 🥵. Cant run my laptop between the hours of 12pm - 10pm or it will overheat in 10 mins. So I moslty learn at night. Thank you Mosh for the videos! Hope everyone here is successful in their endeavors 😊
@Flamecasts
@Flamecasts 2 года назад
for integers in range(2,10,2): print(integers) print('We have 4 even numbers') Ez pz
@sm1116
@sm1116 7 месяцев назад
here's my solution: numbers = range(2, 9, 2) for item in numbers: print(item) if len(numbers) == 4: print("We have 4 even numbers ") else: print("That's it")
@LowGameplays
@LowGameplays Год назад
My code: r = range(1, 10) even = 0 for i in r: if not i % 2: print(i) even += 1 print("We have " + str(even) + " even numbers"
@metalman2140
@metalman2140 11 месяцев назад
I'm not sure if this would be considered a valid solution: import math upper_limit = int(input("What is the highest number within this range?")) upper_limit_halved = math.ceil(upper_limit/2) even_num = [] for i in range(1,upper_limit_halved): print(i*2) even_num.append(i) print(f"We have {str(len(even_num))} even numbers!") The thought behind this is that whatever range we have could be halved (and rounded up in the case of an odd upper limit to the range). Then every integer within our new range could be multiplied by two to give us our even list.
@shruts_thegirl
@shruts_thegirl 2 года назад
for i in range(1,21): if(i%2==0): print(i)
@Fishian.
@Fishian. Год назад
i = 2 for num in range(1, 10): print(i) i+= 2 if i == 10: break print("We have 4 even numbers")
@JustHackIt1
@JustHackIt1 10 месяцев назад
I used the following code: for item in range(0,10,2): print(item) print(str(len(range(0,10,2))) + " are the amount of even numbers between 1 to 10")
@pablosantos1860
@pablosantos1860 5 месяцев назад
contador = 0 for x in range (1,10): if x % 2 == 0: contador += 1 print(x) print(f"Nós temos {contador} números pares.")
@mishab8064
@mishab8064 4 месяца назад
even_numbers=[] for x in range (1,10): if x % 2==0: even_numbers.append(x) print(x) amnt_of_even_numbers=len(even_numbers) print(f"We have {amnt_of_even_numbers}. even numbers" )
@S-cl9sl
@S-cl9sl 3 месяца назад
even_numbers = [str(i) + " " for i in range(1, 10) if i % 2 == 0] print(*even_numbers) print("There are four even numbers from the range 1 to 10.")
@ruandemeneses9513
@ruandemeneses9513 5 месяцев назад
for i in range(1,10,1): # se o resto da divisão de I (variavel coringa do loop for) for = a 0 imprima o I) if i % 2 == 0: print(i) print("we have 4 even numbers !")
@slc388
@slc388 2 года назад
Sir print even numbers from 1 to 10 This method also applicable For In range(0,10,2) Print(i)
@devontathomas8571
@devontathomas8571 Год назад
nums = [2,4,6,8,] for items in nums: print(items) print("we even have 4 ")
@ExcelTutorials1
@ExcelTutorials1 4 года назад
I really appreciate the help man!!!
@kangajankuganathan7457
@kangajankuganathan7457 5 лет назад
#Even numbers count=0 for i in range(1,10): if i%2==0: count=count+1 print(i) print("we have",count,"even","numbers")
@chewypilot4734
@chewypilot4734 4 года назад
For count = count + 1 you can simply put count += 1 and it does the same thing
@billionare_Quotes..
@billionare_Quotes.. Год назад
For number in range(4): number += 1 Print (number * 2) Print ("we have count 4 numbers") Good
@wesley25101
@wesley25101 5 лет назад
Thank you for the video!
@kaiobatistaalmeida
@kaiobatistaalmeida 4 года назад
Same here!
@rahmatilloismoilov3323
@rahmatilloismoilov3323 3 года назад
​@@programmingwithmosh Do you know any website for practice python programming beginners?
@faithsuh
@faithsuh 6 месяцев назад
for i in range(1, 10): if i % 2 == 0: print(i) else: continue
@JSRJS
@JSRJS 2 года назад
Holy cow I did this a totally different way but it worked. I basically divided each number in the range by 2 and if that number % 2 equaled 0 then I put that number into a array and also printed that number. Then at the end of the program I just counted the length of the array. Thoughts? Here's my code nums = range(1, 10) array = [] for items in nums: mod = items % 2 if mod == 0: array.append(items) print(items) print("We have " +str(len(array))+ " even numbers")
@ompatel9971
@ompatel9971 5 лет назад
Please make some tutorials on c++. Not only me but many students would be thankful to you as we students need it for schools
@ompatel9971
@ompatel9971 5 лет назад
I'm in a higher secondary school in 11th STD. Yes I want to become a software engineer in future.
@ah_zuzanka567
@ah_zuzanka567 3 года назад
We can do that also by making a empty list and adding even numbers to this list. Then print the list 😀
@Lord_Inquisitor_William7391
@Lord_Inquisitor_William7391 11 месяцев назад
Sometimes you have a list of numbers that all aren't even and you need all the even ones or something else its not as simple as "just do even numbers"
@prashanttiwari120
@prashanttiwari120 4 года назад
Hi Mosh please make tutorial on spring boot and especially spring security .It will be very useful for lots of people , especially of you are doing :)
@za6604
@za6604 4 года назад
def count_evens(y, z): number = 0 for x in range(y, z): if x % 2 == 0: number += 1 print(x) print(f"There are {number} even numbers") count_evens(1, 10)
@Jin.oppas_left_hand
@Jin.oppas_left_hand 2 года назад
What is the 'f' in the last line please tell
@inasbadr
@inasbadr 2 года назад
I solved the exercise using this code and gave me the same result, is it wrong ??? numbers=[1,2,3,4,5,6,7,8] for number in numbers: if number %2 ==0: print(number) print("we have four even number only")
@mishab8064
@mishab8064 4 месяца назад
even_numbers = [x for x in range(1, 10) if x % 2 == 0] print(f"We have {len(even_numbers)} even numbers.")
@J4WS-t3i
@J4WS-t3i Год назад
I solved it but I didn't do your solution I did : i = 2 for i in range(10): i = i * 2 print(i) if i == 8: break print("we have 4 even numbers") But your solution is more clearly than mine, I started learning programming python at may 20 .
@t0lsi
@t0lsi 4 месяца назад
even_numbers = [] for num in range(1, 10): if num % 2 == 0: even_numbers.insert(0, num) print(num) print(f'There are {len(even_numbers)} even numbers!')
@Vixator
@Vixator 2 года назад
for number in range (2,9,2): print(number) print("We have 4 even Numbers")
@uroojfatima6456
@uroojfatima6456 Год назад
Lol
@Demourer
@Demourer 5 лет назад
numbers = [] for n in range(1, 10): if n % 2 == 0: print(n) numbers.append(n) print(f"We have {len(numbers)} even numbers.") Here's a different approach lam = list(filter(lambda num: num % 2 == 0, range(1, 10))) for num in lam: print(num) print(f"We have {len(lam)} even numbers.") Thanks for the tutorials, I'm learning so much from you.
@chandanaparanavithana8965
@chandanaparanavithana8965 Год назад
This is the best channel to learn about python among the RU-vid, Thank you Sir Mosh. 🙏👌
@reemarazif2176
@reemarazif2176 Год назад
for number in range(1,10): if number % 2 == 0: print(number) print('We have 4 even numbers') I got the same output but is it necessary to set the count=0
@nipuntiwari5517
@nipuntiwari5517 4 года назад
lst = range(1,10) even = list(filter(lambda a : a % 2 == 0 ,lst)) for i in even: print(i) print("We have 4 even numbers") We can do this even with anonymous (lambda) function...
@maxnick7023
@maxnick7023 2 года назад
The last syntax should be print(f"We have {len(even)} even numbers")
@user-gm9zp7qs1x
@user-gm9zp7qs1x Год назад
even_list = [] for i in range(1,10): even = True if i % 2 == 0: even = False if even: print(i) even_list.append(i) print(f'There are {len(even_list)} even numbers') Same result, is it good tho?
@user-ls9li8pf1u
@user-ls9li8pf1u 9 месяцев назад
even_list = [i for i in range(1,10) if i%2 == 0] print(len(even_list))
@ZixZag
@ZixZag 5 лет назад
Please create complete website with python so it will be more interested series
@baderalrahamneh8671
@baderalrahamneh8671 5 лет назад
Will be very awesome.
@ZixZag
@ZixZag 5 лет назад
@@programmingwithmosh can't wait for the series
@sammychivasa
@sammychivasa 7 месяцев назад
Print ("We have 4 even numbers"). Job done! 😂
@AerotaleYT
@AerotaleYT 3 года назад
My_Solution: count = 0 for iteration in range(1, 10): if iteration % 2 == 0: count += 1 print(iteration) print('We have ' + str(count) + ' numbers!')
@salmantechnologies282
@salmantechnologies282 2 года назад
val = 0 for value in range(2,10,2): print(value) val += 1 print(f"we have {val} even numbers ") check this code
@uroojfatima6456
@uroojfatima6456 Год назад
Mosh said don't use the step. Cheater
@es-ck6eu
@es-ck6eu Год назад
no need to use if statement when you can just add 2 as 3rd parameter to range function
@GarthFodder
@GarthFodder Год назад
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] print(numbers[1]) print(numbers[3]) print(numbers[5]) print(numbers[7]) print(numbers[9]) print("We have 5 even numbers")
@YouTubeAlines
@YouTubeAlines Год назад
Here we go! for a in range (2,10,2): print(a) print("We have 4 even numbers") -ik this one is awful😂 Thanks! Keep doin' whatcha doin'
@lamiamz9618
@lamiamz9618 10 месяцев назад
Thank you, professor, your explanation is wonderful
@supriyaramesh6814
@supriyaramesh6814 3 года назад
thank u sir it was really interesting to solve .make more such videos .i love the way u teach !!
@midnightanna9925
@midnightanna9925 Год назад
Thanks for the project! I wrote my code the opposite way but it worked! Here's what I wrote: for x in range(1,11): if x % 2 != 0: continue print(x)
@adishct4371
@adishct4371 2 года назад
Thank you for your video. keep going it will help us to improve our career.
@gamerboyguy8500
@gamerboyguy8500 4 месяца назад
How did bro already start with range function!? and for beginners!?
@_Manic_Man
@_Manic_Man 3 года назад
This can also work with a range and for loop
@raymondmichael4987
@raymondmichael4987 5 лет назад
I like this new approach, Simple yet important things. Keep it up bro. Greetings from Tanzania
@raymondmichael4987
@raymondmichael4987 5 лет назад
@@programmingwithmosh, I've seen you on js, to the extent I decided to buy your Javascript course; but not on python, these will be my first to concentrate on Greetings from Tanzania
@iamachubbybunny
@iamachubbybunny Год назад
What about just using a for loop ?
@StuartKnox
@StuartKnox 22 дня назад
what about this one😂 i m a beginner and I have absolutely no clue of your way sir, so I used a way that I just learn #x, y, z, o = 2, 4, 6, 8 #print(x) #print(y) #print(z) #print(o) #print("we have 4 even numbers ")
@anastasiakhudzyk123
@anastasiakhudzyk123 2 года назад
I support the request for exercises 💜 loved it
@alephnull423
@alephnull423 3 года назад
I did it! feels good
@krishmainali8573
@krishmainali8573 5 лет назад
I have done Print("2,4,6,8") the
@levonb24
@levonb24 Год назад
I have started programming on c++ and this is how I wrote this code at first. currentNumber = 2 quantity = 0 while(currentNumber < 10): print(currentNumber) currentNumber = currentNumber + 2 quantity = quantity + 1 print("You have " + str(quantity) + " even numbers") Much different from how I could do it.
@NOFAP22
@NOFAP22 Год назад
I have doubt in last line why are you written str(quantity) can you explain it sir
@levonb24
@levonb24 Год назад
@@NOFAP22 The print method should receive a string and the string is “ You have quantity even numbers. “, meaning quantity times even numbers, but quantity is a number here, so it needs to be converted into string. That is what str() method do.
@NOFAP22
@NOFAP22 Год назад
@@levonb24 thankyou sir
@ahmedalimaher1725
@ahmedalimaher1725 4 года назад
I can't run the code with ctrl + alt + n. I have this error "'python' is not recognized as an internal or external command, operable program or batch file."
@dashnaym3750
@dashnaym3750 4 года назад
search from youtube environmant variables path
@yasmeenxxx
@yasmeenxxx 4 года назад
Great , where can I find more videos like these?
@thefamouspizza101
@thefamouspizza101 2 года назад
@moshhamedani please help I wrote the exact same code as you did but it is displaying every number separately followed by the 6th string
@sairamnagarajan8289
@sairamnagarajan8289 5 лет назад
Your videos are very helpful. Thanks.
@theaeroz22
@theaeroz22 Год назад
If I wanted to print a list of the numbers that we found were % 2 == 0, how would we go about that?
@StefanoVerugi
@StefanoVerugi Год назад
try list comprehension, with the * you can show the numbers only a = [x for x in range(1,10,1) if x%2 == 0] print(*a)
@prabeshpokhrel
@prabeshpokhrel 2 года назад
Would you please make a video about printing prime number in given range?
@guidc
@guidc 2 года назад
we need more quick exercises like this
@adishct4371
@adishct4371 2 года назад
please include more exercises like this.
@creem3897
@creem3897 4 года назад
we can also do count = number / 2
@neouia777
@neouia777 3 года назад
Thanks it is very simple and useful tutorial I like moooooooooooooore
@user-vk9rd7qv9x
@user-vk9rd7qv9x 4 месяца назад
Thank you for providing such informative content in the video. I appreciated the friendly manner in which the explanations were delivered.10905
@rahulchauhan496
@rahulchauhan496 5 лет назад
Sir I have problem in c++ in if else statement I can't use multiple character why??
@pubggamer1984
@pubggamer1984 2 года назад
Which software you are using and the extension
@mansmor7211
@mansmor7211 3 года назад
I like this sort of Exercise plz :)
@marvelstudios9780
@marvelstudios9780 5 месяцев назад
for i in range(2,9,2): print(i) print("Hello") easy para hai too itna mushkil karne ki kiya zarurat
@maestroandoy481
@maestroandoy481 2 года назад
Shouldn't be for i in range(1, 11):
@josietron6969
@josietron6969 9 месяцев назад
why does he equal the modulus to 0 and also why does he += to 1. I'm trying to review my programming hw and im stuck.
@1997AlexB
@1997AlexB 7 месяцев назад
You modulus equal 0 because it will give you numbers without remainders. so (5 % 2) will be 2 remainder 1 and (4 % 2) is 2 remainder 0. Therefore 5 will not print but 4 will. The +=1 just means he will add 1 to count every time the loop calls it. Youve probably figured it out already but if someone has the same question can read this. Hope it all worked out for you and good luck in the future :)
@ycppppp
@ycppppp Месяц назад
Can someone explain to me why I got this error? count += 1 ^^^^^ NameError: name 'count' is not defined. Did you mean: 'round'?
@markuss_2255
@markuss_2255 2 года назад
Does this counts? my_num = 2, 4, 6, 8 phrase = "We have 4 even numbers" print(my_num[0]) print(my_num[1]) print(my_num[2]) print(my_num[3]) print(phrase) I mean I did get the same result , but not entirely the same, Anyways thank you. :)
@uroojfatima6456
@uroojfatima6456 Год назад
It does not count
@devius072
@devius072 Год назад
I honestly think this guy explains everything in a way that is very hard to understand,what I mean by that is that he does indeed explain what he's doing but does not explain why the codes do the things they are supposed to do,so even if he says that using "if number % 2 == 0: " counts from 2 to 2,like 2,4,6,8 he doesn't explain why that command does so. It took me 5 minutes to look through the code myself to understand what everything does because he just won't say it himself,he just says "to that because it does that" and does not explain "why that is supposed to do something"
@hurriedue1674
@hurriedue1674 Год назад
Your right about that, his 1 hour course on python is exponentially better. I understood the first part of this but not the second took me a sec to understand
@sethmosiere3428
@sethmosiere3428 4 года назад
Helpful and easy to follow videos
@alimahmoudi8485
@alimahmoudi8485 5 лет назад
dastet dard nakone dadash!!
@viprin1664
@viprin1664 3 года назад
what editor/ide used in this video?
@hamrogarage4658
@hamrogarage4658 5 лет назад
Need flask tutorial Do how backend work video
@anthonyartoonian.5989
@anthonyartoonian.5989 5 лет назад
by looking to your name it seems that you have some Iranian roots ! so I must say "Baba Barikala!"
@mymothermylife4033
@mymothermylife4033 2 года назад
Loved it thank u
@ar.rity-learning
@ar.rity-learning 3 года назад
which software did you used ?
@sbd8825
@sbd8825 3 года назад
how can i get a Financial aid for a cours of yours
Далее
Python for Beginners - Learn Python in 1 Hour
1:00:06
Просмотров 18 млн
Solve any Star Pattern program in Python
18:44
Просмотров 930 тыс.
Functions in Python are easy 📞
10:38
Просмотров 456 тыс.
Python 101: Learn the 5 Must-Know Concepts
20:00
Просмотров 1,1 млн
3 PYTHON AUTOMATION PROJECTS FOR BEGINNERS
17:00
Просмотров 1,6 млн
Python Programming Practice: LeetCode #1 -- Two Sum
13:09
How I would learn to code (If I could start over)
9:16
👩‍💻 Python for Beginners Tutorial
1:03:21
Просмотров 3,2 млн
Please Master These 10 Python Functions…
22:17
Просмотров 143 тыс.
5 Useful F-String Tricks In Python
10:02
Просмотров 299 тыс.