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

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ต.ค. 2024
  • A quick tutorial on how to loop your code back to the middle or beginning using a procedure. This is useful if you want to reload / re-run the script, module or code block.

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

  • @sadgallington7850
    @sadgallington7850 3 ปีที่แล้ว +18

    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 ^^

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

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

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

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

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

    Thank you, this really helped me out!

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

    thanks for this helpful information

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

    thanks so much bro, saved me so much time

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

    thank u bro, u helped me a lot

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

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

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

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

    Useful video! Thanks

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

    earned urself a sub

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

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

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

    Thanks you, very helpful script to know

  • @thatsawesome.
    @thatsawesome. 2 ปีที่แล้ว

    thank you!

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

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

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

    Thanks so much!

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

    Simple and Great... (Y)

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

    Thank you...Gooooodd!!!!

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

    thank sir

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

    sheesh moment

  • @silver1340
    @silver1340 8 วันที่ผ่านมา

    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.

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

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

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

    Thank you very helpful appreciate it 💖 🙏🏾👊🏾

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

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

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

    Doesn’t work 😐

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

      it does. watch out for indent. its important

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

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

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

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

    now i have a looping calculator

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

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

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

    print("Thank you so much!")

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

    Thanks a lot for the help 👍🏾😊

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

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

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

    and i can apply this anywhere?

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

    Thank you very much bro❤❤❤

  • @Yibilliboo-rq1ey
    @Yibilliboo-rq1ey ปีที่แล้ว

    Thank You very much!!

  • @ThunderBhai-y6r
    @ThunderBhai-y6r 9 หลายเดือนก่อน

    Thanks a lot bro!!

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

    THANK YOU SO MUCH BRO

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

    Thank you very much for this tutorial!

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

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

  • @Ron-rd5th
    @Ron-rd5th 4 ปีที่แล้ว +2

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

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

      you have to write
      if restart=="yes"
      main()

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

      u cannot code noob

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

      just like your dp u dumbfuck

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

      put "yes" in a variable

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

      Unleash your Tech ????

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

    This is nice

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

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

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

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

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

    You just made this assignment less awful.

  • @gabriel-accetta
    @gabriel-accetta 3 ปีที่แล้ว

    thanks, nice IDE bro

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

    Thank you this is exactly what I needed! Subbed

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

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

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

    thanks very helpfull appreciate it ( share done)

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

    Thank you you’re a legend good sir

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

    Thanks man, Appreciated

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

    you are a god!!

  • @65senshi
    @65senshi 2 ปีที่แล้ว

    VERY Good explanation and helped me a lot!

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

    i absolutely love you

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

    Thank u sir

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

    helped me alot! thank you!

  • @Charlie-ci7xn
    @Charlie-ci7xn 4 ปีที่แล้ว

    Thanks mate it worked!

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

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

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

    very clear, very cool

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

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

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