Python Tutorial - Looping your code back (to the beginning or middle) using a procedure

Поділитися
Вставка
  • Опубліковано 18 гру 2024

КОМЕНТАРІ • 82

  • @aloshie1
    @aloshie1 2 роки тому +4

    crystal clear and helpful no 15minutes of messing with my head, straight to the point, thank you so much

  • @sadgallington7850
    @sadgallington7850 3 роки тому +19

    You're literally a god my dude, you saved all my noobish code!. I wrote a giant if elif else code with a lot of shit, and I didn't know how to properly loop till I saw this video. Not even hours and hours of research did what your 6 min video did. Thanks... I REALLY apreciate it.

    • @billal2731
      @billal2731 3 роки тому

      Good luck for your work ^^

  • @myge_
    @myge_ 2 роки тому +2

    I HAVE BEEN LOOKIN FOR THIS FOR HOURS THANK YOU!!

  • @enternamehere6686
    @enternamehere6686 Рік тому +3

    TL;DW
    -Define (make a function) the program that you want to repeat or not repeat (depending on user input)
    -Make a variable input at the end of the function you just made, preferably an integer input for simplicity
    -Make either, 1 if statement and an elif/else, or make 2 if statements deciding whether the repeat variable was yes or no
    -If the repeat variable was yes then put the function name under the corresponding if statement, and if the repeat variable was no then put an "exit()" under the statement
    -Lastly, not under any function, call the function

  • @TuanTungTranDuc
    @TuanTungTranDuc 4 роки тому +1

    Thank you for a clear and useful tutorial with no superficial talk only relevant stuff

  • @likhomaki6203
    @likhomaki6203 Рік тому

    WOW... THANKS DAMN YOU GOOD. I HAVE BEEN STRUGGLING FOR DAYS AND YOU JUST MADE MY LOFE SIMPLE AS HELL.

  • @PlantLover008
    @PlantLover008 Рік тому +1

    Thank you, this really helped me out!

  • @debadeepdas1
    @debadeepdas1 3 роки тому +1

    Thanks a lot for the help 👍🏾😊

  • @lordbloxmans4358
    @lordbloxmans4358 11 місяців тому

    thanks so much bro, saved me so much time

  • @doko_bhai
    @doko_bhai 5 місяців тому

    Bro you deserve more subs than you have you saved my life

  • @ahmetserdarguldibi
    @ahmetserdarguldibi Місяць тому

    That's what i'm looking for. Thanks for your efforts. Nice video.

  • @djalone8445
    @djalone8445 Рік тому

    thanks for this helpful information

  • @amendez721
    @amendez721 4 роки тому +1

    Thank you very much for this tutorial!

  • @Topkinolar_uzbektilida
    @Topkinolar_uzbektilida Рік тому

    thank u bro, u helped me a lot

  • @abukmoha5092
    @abukmoha5092 5 років тому +4

    Thank you very helpful appreciate it 💖 🙏🏾👊🏾

  • @seherjabar4876
    @seherjabar4876 5 років тому +1

    Useful video! Thanks

  • @Kryptonite099
    @Kryptonite099 2 роки тому

    Nice man, I got a task and thanks to you I did it!

  • @im_jst_tired4280
    @im_jst_tired4280 2 роки тому

    Thank you you’re a legend good sir

  • @wadhajwdknawd
    @wadhajwdknawd Рік тому

    THANK YOU SO MUCH BRO

  • @zrhn4127
    @zrhn4127 2 роки тому

    thanks! If it weren't for this i'd still be stuck getting errors trying to loop with while and for. deserves a like and sub fam.

  • @ThunderBhai-y6r
    @ThunderBhai-y6r Рік тому

    Thanks a lot bro!!

  • @Subaka_
    @Subaka_ 3 роки тому

    Very helpful had to make some changes to match my needs but was still very helpful

  • @omargaming8988
    @omargaming8988 Рік тому

    Thank you very much bro❤❤❤

  • @wsaid_7912
    @wsaid_7912 2 роки тому

    earned urself a sub

  • @65senshi
    @65senshi 2 роки тому

    VERY Good explanation and helped me a lot!

  • @gabriel-accetta
    @gabriel-accetta 3 роки тому

    thanks, nice IDE bro

  • @godman1117
    @godman1117 3 роки тому

    Thanks you, very helpful script to know

  • @tigana
    @tigana 3 роки тому

    Thank you this is exactly what I needed! Subbed

  • @zx74c
    @zx74c 3 роки тому

    helped me alot! thank you!

  • @Mujiboy
    @Mujiboy 3 роки тому

    Thanks man, Appreciated

  • @Charlie-ci7xn
    @Charlie-ci7xn 4 роки тому

    Thanks mate it worked!

  • @thatsawesome.
    @thatsawesome. 2 роки тому

    thank you!

  • @NotMuj
    @NotMuj 3 роки тому

    Thanks so much!

  • @jogeshnanda7704
    @jogeshnanda7704 Рік тому

    Simple and Great... (Y)

  • @renieronronshi7120
    @renieronronshi7120 4 роки тому +1

    thank you so much
    you're a lifesaver
    thank you
    thank you
    thank youuuuuuuuuuuuuuu

  • @chickinuggit4487
    @chickinuggit4487 2 роки тому

    This is nice

  • @BizzaroBrainBoi
    @BizzaroBrainBoi 4 роки тому

    very clear, very cool

  • @ihavenoideafornamefr8418
    @ihavenoideafornamefr8418 Місяць тому

    The indent all is ruining all the the former indents I made, how do I prevent that?

  • @Kieranmcm07
    @Kieranmcm07 2 роки тому

    Hello ye I tried this and when i run the program nothing gets printed out? please help I have no clue whats wrong

  • @ricardoduplessis7127
    @ricardoduplessis7127 3 роки тому

    you are a god!!

  • @jorgemarinjaramillo221
    @jorgemarinjaramillo221 Рік тому

    Justo lo que necesitaba gracias!! // exactly what I needed thanks!!

  • @danielpo5771
    @danielpo5771 3 роки тому

    Thank you...Gooooodd!!!!

  • @jaiimecrm
    @jaiimecrm 3 роки тому

    i absolutely love you

  • @florinalexandruciovica2526
    @florinalexandruciovica2526 4 роки тому +2

    def main():
    print("type one of the following : goat, wolf , cabadge").lower()
    operator = input("What did the man chose?")
    if operator == "goat":
    print("excelent!")
    elif operator == "wolf":
    print("worng!")
    elif operator == "cabadge":
    print("worng!")
    else:
    print("WRONG!")
    repeat = input("Would you like to try again?").lower()
    if repeat == "yes":
    main()
    else:
    print("bye")
    exit()
    main()
    where am i wrong? is not coming back to start?

    • @aspire_minister5426
      @aspire_minister5426 4 роки тому +2

      Repeat = input("Would you like to retry?").lower()
      if Repeat == 'yes':
      main()
      else:
      print('Thanks for playing')
      exit()
      main()
      You need to make the text indent and define "main" at the start of where you want it to restart from.
      #!/bin/python3
      from random import randint
      import time
      import functools
      import operator
      import random
      import math
      print('Welcome to multiplication questions.')
      ans=input('Are you ready (yes/no) : ')
      if ans.lower() == 'yes':
      start_time = time.time()
      def main():
      score = 0
      # Game Logic
      while True:
      difficulty_setting = 2
      difficulty_progression = math.floor(score/10)
      overall_difficulty = difficulty_setting + difficulty_progression
      number_list = []
      for x in range(overall_difficulty):
      value = random.randint(1,9)
      number_list.append(value)
      answer = functools.reduce(operator.mul, number_list, 1)
      print('Multiply these numbers', number_list)
      guess = int(input())
      if guess == answer:
      score = score + (1* overall_difficulty)
      continue
      else:
      print('Game Over! The answer was', answer)
      elapsed_time = time.time() - start_time
      print('Your score was', score, 'in only', elapsed_time)
      break

      Repeat = input("Would you like to retry?").lower()
      if Repeat == 'yes':
      main()
      else:
      print('Thanks for playing')
      exit()
      main()
      That is an example of a code I used.

    • @invisibleinsociety
      @invisibleinsociety 3 роки тому

      ​@@aspire_minister5426 man it still doesn't works :(
      here is my code : ( it take an input from the user then he write a letter then the program tells the number ) :
      ############################
      def main():
      yeslist=["yes","y","YES","y","yeah","ok"]
      name=input("enter your name:")
      letter=input("enter a letter:")
      if letter in name:
      print(name.index(letter))
      else:
      print("something went wrong :(")
      repeat=input("do u want to restart ? :").lower()
      if repeat==yeslist:
      main()
      else :
      print("ok, bye :(")
      exit()
      main()

  • @silver1340
    @silver1340 2 місяці тому

    While this does work, doesn't it expose your program to Python's recursion limits?
    Originally I was scripting in CMD and made heavy use of 'goto' commands, then switched to Python, did the exact same thing as in this video, but realized that Python does remember which functions were called, and if you continue to call, without ever using "return" or the like, you will hit recursion limit.

  • @bariraaz6505
    @bariraaz6505 3 роки тому

    Thank u sir

  • @ZachStarAttack
    @ZachStarAttack 3 роки тому

    You just made this assignment less awful.

  • @3uz
    @3uz 3 роки тому

    thanks very helpfull appreciate it ( share done)

  • @kalengsarden3493
    @kalengsarden3493 2 роки тому

    thank sir

  • @itsdezman
    @itsdezman 2 роки тому

    Thank you for this video! I'm trying to get my script to repeat 10 times. How can I set a number for the number of times it repeats?

    • @tejaspro7128
      @tejaspro7128 Рік тому

      Copy Paste your main code 10 times
      SUPER SIMPLE

  • @xBZZZZyt
    @xBZZZZyt 3 роки тому +5

    This will crash if user repeats too many times because it is recursive.

  • @johnray854
    @johnray854 Рік тому

    and i can apply this anywhere?

  • @Ron-rd5th
    @Ron-rd5th 4 роки тому +2

    I keep getting an error saying "yes" is not defined when I enter yes for restart

  • @johnray854
    @johnray854 Рік тому

    now i have a looping calculator

  • @arwan6650
    @arwan6650 Рік тому

    print("Thank you so much!")

  • @draizertbr6352
    @draizertbr6352 3 роки тому

    What if i want multiple "yes's" (e.g. yes,ye,yep) do i have to use elif??

  • @jmm4963
    @jmm4963 4 роки тому

    Thank you!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • @mrvideo6703
    @mrvideo6703 Місяць тому

    It's not working

  • @azhanisyahputra9867
    @azhanisyahputra9867 Рік тому

    This would only works if you were using only one def function. Otherwise it will loop like forever 😢

  • @WhooseAGoose
    @WhooseAGoose 4 роки тому +2

    Doesn’t work 😐

    • @skillerx79
      @skillerx79 3 роки тому

      it does. watch out for indent. its important

  • @lukeliu4226
    @lukeliu4226 3 роки тому +2

    sheesh moment

  • @VinayGhate
    @VinayGhate 3 роки тому

    Bro If you want to get more subscriber then just hide the subscriber, people don't follow channel which have low subscribers

  • @MunjakGTK
    @MunjakGTK Рік тому +1

    Thank you for a clear and useful tutorial with no superficial talk only relevant stuff