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

ความคิดเห็น • 195

  • @shahilghale5163
    @shahilghale5163 4 ปีที่แล้ว +70

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

  • @Just_Me_Being_Myself
    @Just_Me_Being_Myself 3 ปีที่แล้ว +8

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

  • @ericadsuara1283
    @ericadsuara1283 2 ปีที่แล้ว +4

    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.

  • @radekspilka273
    @radekspilka273 3 ปีที่แล้ว +251

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

    • @onlyforprogramming7916
      @onlyforprogramming7916 3 ปีที่แล้ว +9

      No lol

    • @aiman7282
      @aiman7282 3 ปีที่แล้ว +5

      I feel you

    • @666222333111
      @666222333111 3 ปีที่แล้ว +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 2 ปีที่แล้ว +2

      How it quite ez

    • @Luiz997488
      @Luiz997488 2 ปีที่แล้ว +12

      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 😉

  • @prashanttiwari120
    @prashanttiwari120 3 ปีที่แล้ว +7

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

  • @chandanaparanavithana8965
    @chandanaparanavithana8965 ปีที่แล้ว

    This is the best channel to learn about python among the TH-cam, Thank you Sir Mosh. 🙏👌

  • @khalilsial1
    @khalilsial1 4 ปีที่แล้ว +7

    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

  • @panda9315
    @panda9315 2 ปีที่แล้ว +14

    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 ปีที่แล้ว +1

      Ohh.. I did the same thing..

    • @maxnick7023
      @maxnick7023 2 ปีที่แล้ว +1

      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 ปีที่แล้ว

      @@maxnick7023 go get another profession

  • @TheDrumtracks
    @TheDrumtracks 3 ปีที่แล้ว +9

    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 หลายเดือนก่อน

      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?

  • @DevineInnovations
    @DevineInnovations 5 ปีที่แล้ว +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 ปีที่แล้ว +1

      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.

  • @supriyaramesh6814
    @supriyaramesh6814 3 ปีที่แล้ว +1

    thank u sir it was really interesting to solve .make more such videos .i love the way u teach !!

  • @RohitKumarRathi91
    @RohitKumarRathi91 ปีที่แล้ว +1

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

  • @ExcelTutorials1
    @ExcelTutorials1 3 ปีที่แล้ว +7

    I really appreciate the help man!!!

  • @sairamnagarajan8289
    @sairamnagarajan8289 5 ปีที่แล้ว

    Your videos are very helpful. Thanks.

  • @pastehl
    @pastehl ปีที่แล้ว +1

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

  • @wesley25101
    @wesley25101 5 ปีที่แล้ว +9

    Thank you for the video!

  • @adishct4371
    @adishct4371 ปีที่แล้ว

    Thank you for your video. keep going it will help us to improve our career.

  • @prynsh7737
    @prynsh7737 3 ปีที่แล้ว +9

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

  • @lamiamz9618
    @lamiamz9618 8 หลายเดือนก่อน

    Thank you, professor, your explanation is wonderful

  • @guidc
    @guidc 2 ปีที่แล้ว

    we need more quick exercises like this

  • @yasmeenxxx
    @yasmeenxxx 4 ปีที่แล้ว +2

    Great , where can I find more videos like these?

  • @prabeshpokhrel
    @prabeshpokhrel 2 ปีที่แล้ว

    Would you please make a video about printing prime number in given range?

  • @anastasiakhudzyk123
    @anastasiakhudzyk123 2 ปีที่แล้ว

    I support the request for exercises 💜 loved it

  • @KampfhelikopterTiger
    @KampfhelikopterTiger 9 หลายเดือนก่อน +3

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

  • @matankkanu1937
    @matankkanu1937 4 หลายเดือนก่อน

    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

  • @adishct4371
    @adishct4371 ปีที่แล้ว

    please include more exercises like this.

  • @_Manic_Man
    @_Manic_Man 3 ปีที่แล้ว

    This can also work with a range and for loop

  • @ompatel9971
    @ompatel9971 5 ปีที่แล้ว +4

    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 ปีที่แล้ว +1

      I'm in a higher secondary school in 11th STD.
      Yes I want to become a software engineer in future.

  • @sethmosiere3428
    @sethmosiere3428 4 ปีที่แล้ว

    Helpful and easy to follow videos

  • @shruts_thegirl
    @shruts_thegirl 2 ปีที่แล้ว +1

    for i in range(1,21):
    if(i%2==0):
    print(i)

  • @JSRJS
    @JSRJS ปีที่แล้ว

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

  • @slc388
    @slc388 2 ปีที่แล้ว +1

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

  • @alimahmoudi8485
    @alimahmoudi8485 5 ปีที่แล้ว

    dastet dard nakone dadash!!

  • @hamrogarage4658
    @hamrogarage4658 5 ปีที่แล้ว +1

    Need flask tutorial
    Do how backend work video

  • @JustHackIt1
    @JustHackIt1 8 หลายเดือนก่อน

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

  • @neouia777
    @neouia777 2 ปีที่แล้ว

    Thanks it is very simple and useful tutorial I like moooooooooooooore

  • @spriteguy7819
    @spriteguy7819 ปีที่แล้ว +1

    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

  • @ah_zuzanka567
    @ah_zuzanka567 3 ปีที่แล้ว +4

    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 8 หลายเดือนก่อน

      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"

  • @alephnull423
    @alephnull423 2 ปีที่แล้ว

    I did it! feels good

  • @reemarazif2176
    @reemarazif2176 11 หลายเดือนก่อน

    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

  • @Fishian.
    @Fishian. ปีที่แล้ว

    i = 2
    for num in range(1, 10):
    print(i)
    i+= 2
    if i == 10:
    break
    print("We have 4 even numbers")

  • @mansmor7211
    @mansmor7211 3 ปีที่แล้ว

    I like this sort of Exercise plz :)

  • @raymondmichael4987
    @raymondmichael4987 5 ปีที่แล้ว +2

    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

  • @tidtid4992
    @tidtid4992 ปีที่แล้ว

    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 .

  • @twizerimanaanastase3447
    @twizerimanaanastase3447 4 วันที่ผ่านมา

    for i in range(2,10,2):
    print(i)
    if i == 8:
    break
    print(" we have 4 even number")
    print()

  • @Flamecasts
    @Flamecasts 2 ปีที่แล้ว +2

    for integers in range(2,10,2):
    print(integers)

    print('We have 4 even numbers')
    Ez pz

  • @mymothermylife4033
    @mymothermylife4033 2 ปีที่แล้ว

    Loved it thank u

  • @jonasalbert20
    @jonasalbert20 5 ปีที่แล้ว

    wish you could have fullstack with python mosh.

  • @billionare_Quotes..
    @billionare_Quotes.. 11 หลายเดือนก่อน

    For number in range(4):
    number += 1
    Print (number * 2)
    Print ("we have count 4 numbers")
    Good

  • @creem3897
    @creem3897 4 ปีที่แล้ว

    we can also do count = number / 2

  • @pacosmosisx8607
    @pacosmosisx8607 9 หลายเดือนก่อน +1

    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 หลายเดือนก่อน

      You really saved me

    • @sivuyile3380
      @sivuyile3380 หลายเดือนก่อน

      Quick question, can you highlight what exactly (% , == , +=) mean and how they can be applied?

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

  • @rahulchauhan496
    @rahulchauhan496 5 ปีที่แล้ว

    Sir I have problem in c++ in if else statement I can't use multiple character why??

  • @LowGameplays
    @LowGameplays ปีที่แล้ว +1

    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"

  • @pablosantos1860
    @pablosantos1860 3 หลายเดือนก่อน

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

  • @metalman2140
    @metalman2140 8 หลายเดือนก่อน

    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.

  • @ruandemeneses9513
    @ruandemeneses9513 3 หลายเดือนก่อน

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

  • @inasbadr
    @inasbadr 2 ปีที่แล้ว +1

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

  • @skillfulactor09
    @skillfulactor09 5 ปีที่แล้ว

    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

    • @skillfulactor09
      @skillfulactor09 5 ปีที่แล้ว

      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

  • @pubggamer1984
    @pubggamer1984 2 ปีที่แล้ว

    Which software you are using and the extension

  • @kangajankuganathan7457
    @kangajankuganathan7457 5 ปีที่แล้ว +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 3 ปีที่แล้ว +2

      For count = count + 1 you can simply put count += 1 and it does the same thing

  • @aadhilks2281
    @aadhilks2281 3 ปีที่แล้ว

    Its really helpful

  • @es-ck6eu
    @es-ck6eu ปีที่แล้ว

    no need to use if statement when you can just add 2 as 3rd parameter to range function

  • @thefamouspizza101
    @thefamouspizza101 ปีที่แล้ว

    @moshhamedani please help I wrote the exact same code as you did but it is displaying every number separately followed by the 6th string

  • @S-cl9sl
    @S-cl9sl 15 วันที่ผ่านมา

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

  • @faithsuh
    @faithsuh 3 หลายเดือนก่อน

    for i in range(1, 10):
    if i % 2 == 0:
    print(i)
    else:
    continue

  • @sm1116
    @sm1116 5 หลายเดือนก่อน

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

  • @devontathomas8571
    @devontathomas8571 10 หลายเดือนก่อน

    nums = [2,4,6,8,]
    for items in nums:
    print(items)
    print("we even have 4 ")

  • @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?

  • @iamachubbybunny
    @iamachubbybunny ปีที่แล้ว

    What about just using a for loop ?

  • @sammychivasa
    @sammychivasa 4 หลายเดือนก่อน

    Print ("We have 4 even numbers"). Job done! 😂

  • @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'

  • @sbd8825
    @sbd8825 2 ปีที่แล้ว

    how can i get a Financial aid for a cours of yours

  • @user-vk9rd7qv9x
    @user-vk9rd7qv9x 2 หลายเดือนก่อน

    Thank you for providing such informative content in the video. I appreciated the friendly manner in which the explanations were delivered.10905

  • @za6604
    @za6604 3 ปีที่แล้ว

    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)

  • @mishab8064
    @mishab8064 หลายเดือนก่อน

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

  • @user-kg7uf6ji6h
    @user-kg7uf6ji6h 2 ปีที่แล้ว

    which software did you used ?

  • @ZixZag
    @ZixZag 5 ปีที่แล้ว +3

    Please create complete website with python so it will be more interested series

    • @baderalrahamneh8671
      @baderalrahamneh8671 5 ปีที่แล้ว +3

      Will be very awesome.

    • @ZixZag
      @ZixZag 5 ปีที่แล้ว +1

      @@programmingwithmosh can't wait for the series

  • @gamerboyguy8500
    @gamerboyguy8500 2 หลายเดือนก่อน

    How did bro already start with range function!? and for beginners!?

  • @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)

  • @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

  • @itstwilight7417
    @itstwilight7417 5 ปีที่แล้ว

    You should have a python series with tkinter for beginners

  • @anthonyartoonian.5989
    @anthonyartoonian.5989 5 ปีที่แล้ว +4

    by looking to your name it seems that you have some Iranian roots ! so I must say "Baba Barikala!"

  • @mishab8064
    @mishab8064 หลายเดือนก่อน

    even_numbers = [x for x in range(1, 10) if x % 2 == 0]
    print(f"We have {len(even_numbers)} even numbers.")

  • @Vixator
    @Vixator ปีที่แล้ว

    for number in range (2,9,2):
    print(number)
    print("We have 4 even Numbers")

  • @viprin1664
    @viprin1664 2 ปีที่แล้ว

    what editor/ide used in this video?

  • @t0lsi
    @t0lsi 2 หลายเดือนก่อน

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

  • @user-ls9li8pf1u
    @user-ls9li8pf1u 6 หลายเดือนก่อน

    even_list = [i for i in range(1,10) if i%2 == 0]
    print(len(even_list))

  • @tokenlb
    @tokenlb 5 หลายเดือนก่อน

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

    • @tokenlb
      @tokenlb 5 หลายเดือนก่อน

      for a bigginer i learned new way to print out values amongst characters

  • @ahmedalimaher1725
    @ahmedalimaher1725 4 ปีที่แล้ว +1

    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 ปีที่แล้ว +2

      search from youtube environmant variables path

  • @markuss_2255
    @markuss_2255 ปีที่แล้ว

    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. :)

  • @krishmainali8573
    @krishmainali8573 5 ปีที่แล้ว +4

    I have done
    Print("2,4,6,8") the

  • @marvelstudios9780
    @marvelstudios9780 3 หลายเดือนก่อน

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

  • @edixonbalzan1142
    @edixonbalzan1142 ปีที่แล้ว

    where i can see more exercises?

  • @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)

  • @AM-lq4rz
    @AM-lq4rz 3 ปีที่แล้ว

    can u do exercise 2

  • @chisaleWinderford
    @chisaleWinderford หลายเดือนก่อน

    nice

  • @Luka_WiFi
    @Luka_WiFi 4 ปีที่แล้ว

    კაი კაცი! კაცური კაცი!