Python Exercises for Beginners - Exercise #1
ฝัง
- เผยแพร่เมื่อ 2 พ.ย. 2018
- 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:
programmingwithmosh.com/pytho...
Python Cheat Sheet:
programmingwithmosh.com/pytho...
Want to learn more from me? Check out my blog and courses:
programmingwithmosh.com
/ programmingwithmosh
/ moshhamedani
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! 🙌🙏
Thank you so much for this,! Just getting started with Python (and programming in general), and was having trouble finding excercices like these.
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.
i am only one who feel so dumb after watching this?
No lol
I feel you
Meh it's easy. Loop it, check if it divides by 2 if yes + if no throw it out, print and done.
How it quite ez
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 😉
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 :)
This is the best channel to learn about python among the TH-cam, Thank you Sir Mosh. 🙏👌
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
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')
Ohh.. I did the same thing..
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??
@@maxnick7023 go get another profession
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!
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?
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!
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.
thank u sir it was really interesting to solve .make more such videos .i love the way u teach !!
for a in range(1,10):
if a%2==0:
print(a)
b= a.bit_length()
print(f"we have {b} numbers")
I really appreciate the help man!!!
Your videos are very helpful. Thanks.
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")
Thank you for the video!
Same here!
@@programmingwithmosh Do you know any website for practice python programming beginners?
Thank you for your video. keep going it will help us to improve our career.
For i in range(1,10):
If i % 2 == 0:
Print(i)
Print(“we have 4 even numbers”)
Thank you, professor, your explanation is wonderful
we need more quick exercises like this
Great , where can I find more videos like these?
Would you please make a video about printing prime number in given range?
I support the request for exercises 💜 loved it
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!")
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
please include more exercises like this.
This can also work with a range and for loop
Please make some tutorials on c++.
Not only me but many students would be thankful to you as we students need it for schools
I'm in a higher secondary school in 11th STD.
Yes I want to become a software engineer in future.
Helpful and easy to follow videos
for i in range(1,21):
if(i%2==0):
print(i)
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")
Sir print even numbers from 1 to 10
This method also applicable
For In range(0,10,2)
Print(i)
dastet dard nakone dadash!!
Need flask tutorial
Do how backend work video
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")
Thanks it is very simple and useful tutorial I like moooooooooooooore
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
We can do that also by making a empty list and adding even numbers to this list. Then print the list 😀
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"
I did it! feels good
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
i = 2
for num in range(1, 10):
print(i)
i+= 2
if i == 10:
break
print("We have 4 even numbers")
I like this sort of Exercise plz :)
I like this new approach,
Simple yet important things.
Keep it up bro.
Greetings from Tanzania
@@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
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 .
for i in range(2,10,2):
print(i)
if i == 8:
break
print(" we have 4 even number")
print()
for integers in range(2,10,2):
print(integers)
print('We have 4 even numbers')
Ez pz
Loved it thank u
wish you could have fullstack with python mosh.
For number in range(4):
number += 1
Print (number * 2)
Print ("we have count 4 numbers")
Good
we can also do count = number / 2
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")
You really saved me
Quick question, can you highlight what exactly (% , == , +=) mean and how they can be applied?
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...
The last syntax should be
print(f"We have {len(even)} even numbers")
Sir I have problem in c++ in if else statement I can't use multiple character why??
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"
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.")
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.
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 !")
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")
do you think python has alot of entry level developer postion comparing to javascript postion I'm debating on switching to python. I invested in javascript for almost 2 years now and no progress but close to landing a postion. any thoughts
so as for a self taught junior developer in python how is the differnce from landing a job comparing to web development than python development
Which software you are using and the extension
#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")
For count = count + 1 you can simply put count += 1 and it does the same thing
Its really helpful
no need to use if statement when you can just add 2 as 3rd parameter to range function
@moshhamedani please help I wrote the exact same code as you did but it is displaying every number separately followed by the 6th string
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.")
for i in range(1, 10):
if i % 2 == 0:
print(i)
else:
continue
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")
nums = [2,4,6,8,]
for items in nums:
print(items)
print("we even have 4 ")
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?
What about just using a for loop ?
Print ("We have 4 even numbers"). Job done! 😂
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'
how can i get a Financial aid for a cours of yours
Thank you for providing such informative content in the video. I appreciated the friendly manner in which the explanations were delivered.10905
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)
What is the 'f' in the last line please tell
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" )
which software did you used ?
Please create complete website with python so it will be more interested series
Will be very awesome.
@@programmingwithmosh can't wait for the series
How did bro already start with range function!? and for beginners!?
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)
val = 0
for value in range(2,10,2):
print(value)
val += 1
print(f"we have {val} even numbers ")
check this code
Mosh said don't use the step.
Cheater
You should have a python series with tkinter for beginners
Programming with Mosh yes
by looking to your name it seems that you have some Iranian roots ! so I must say "Baba Barikala!"
even_numbers = [x for x in range(1, 10) if x % 2 == 0]
print(f"We have {len(even_numbers)} even numbers.")
for number in range (2,9,2):
print(number)
print("We have 4 even Numbers")
Lol
what editor/ide used in this video?
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!')
even_list = [i for i in range(1,10) if i%2 == 0]
print(len(even_list))
my solution :
count = 0
for i in range(1,10):
if(i%2 == 0):
print(i)
count+=1
print ("we have " + str(count) + " even numbers")
for a bigginer i learned new way to print out values amongst characters
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."
search from youtube environmant variables path
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. :)
It does not count
I have done
Print("2,4,6,8") the
for i in range(2,9,2):
print(i)
print("Hello")
easy para hai too itna mushkil karne ki kiya zarurat
Shouldn't be
for i in range(1, 11):
where i can see more exercises?
If I wanted to print a list of the numbers that we found were % 2 == 0, how would we go about that?
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)
can u do exercise 2
nice
კაი კაცი! კაცური კაცი!