Python Exercises for Beginners - Exercise #1

preview_player
Показать описание
Looking for Python practices to learn Python better? Watch this video to practice Python.

Python Exercises for Beginners:

Python Cheat Sheet:

Want to learn more from me? Check out my blog and courses:

Рекомендации по теме
Комментарии
Автор

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! 🙌🙏

shahilghale
Автор

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')

panda
Автор

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!

TheDrumtracks
Автор

For i in range(1, 10):
If i % 2 == 0:
Print(i)
Print(“we have 4 even numbers”)

prynsh
Автор

for a in range(1, 10):
if a%2==0:
print(a)
b= a.bit_length()
print(f"we have {b} numbers")

RohitKumarRathi
Автор

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
Автор

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")

pastehl
Автор

Thank you so much for this, ! Just getting started with Python (and programming in general), and was having trouble finding excercices like these.

Just_Me_Being_Myself
Автор

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

matankkanu
Автор

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!")

KampfhelikopterTiger
Автор

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

khalilsial
Автор

i am only one who feel so dumb after watching this?

radekspilka
Автор

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")

pacosmosisx
Автор

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.

ericadsuara
Автор

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

spriteguy
Автор

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"

LowGameplays
Автор

#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")

kangajankuganathan
Автор

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.

Demourer
Автор

Thanks I learned (1, 10) because I've tried
for x in range(10):
if x % 2 == 0:
if x != 0:
count += 1
print(x)
then comeback to this and realized before I see the whole correct answer:
for x in range(1, 10):
if x % 2 == 0:
count += 1
print(x)

CRandomMotivations
Автор

Sir print even numbers from 1 to 10
This method also applicable
For In range(0, 10, 2)
Print(i)

slc