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.
Пікірлер: 79
@aloshie1 Жыл бұрын
crystal clear and helpful no 15minutes of messing with my head, straight to the point, thank you so much
@TuanTungTranDuc4 жыл бұрын
Thank you for a clear and useful tutorial with no superficial talk only relevant stuff
@enternamehere6686 Жыл бұрын
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
@myge_ Жыл бұрын
I HAVE BEEN LOOKIN FOR THIS FOR HOURS THANK YOU!!
@amendez7213 жыл бұрын
Thank you very much for this tutorial!
@tigana3 жыл бұрын
Thank you this is exactly what I needed! Subbed
@65senshi Жыл бұрын
VERY Good explanation and helped me a lot!
@Kryptonite0992 жыл бұрын
Nice man, I got a task and thanks to you I did it!
@abukmoha50924 жыл бұрын
Thank you very helpful appreciate it 💖 🙏🏾👊🏾
@sadgallington78503 жыл бұрын
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.
@billal27313 жыл бұрын
Good luck for your work ^^
@seherjabar48765 жыл бұрын
Useful video! Thanks
@PlantLover008 Жыл бұрын
Thank you, this really helped me out!
@debadeepdas12 жыл бұрын
Thanks a lot for the help 👍🏾😊
@doko_bhai15 күн бұрын
Bro you deserve more subs than you have you saved my life
@zrhn41272 жыл бұрын
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.
@Subaka_2 жыл бұрын
Very helpful had to make some changes to match my needs but was still very helpful
@djalone84459 ай бұрын
thanks for this helpful information
@Charlie-ci7xn3 жыл бұрын
Thanks mate it worked!
@zx74c2 жыл бұрын
helped me alot! thank you!
@BizzaroBrainBoi4 жыл бұрын
very clear, very cool
@likhomaki6203 Жыл бұрын
WOW... THANKS DAMN YOU GOOD. I HAVE BEEN STRUGGLING FOR DAYS AND YOU JUST MADE MY LOFE SIMPLE AS HELL.
@godman11173 жыл бұрын
Thanks you, very helpful script to know
@lordbloxmans43586 ай бұрын
thanks so much bro, saved me so much time
@Mujiboy3 жыл бұрын
Thanks man, Appreciated
@Yibilliboo-rq1ey11 ай бұрын
Thank You very much!!
@jorgemarinjaramillo221 Жыл бұрын
Justo lo que necesitaba gracias!! // exactly what I needed thanks!!
@razday8490 Жыл бұрын
THANK YOU SO MUCH BRO
@im_jst_tired4280 Жыл бұрын
Thank you you’re a legend good sir
@NotMuj2 жыл бұрын
Thanks so much!
@user-jt8ty5vx9b7 ай бұрын
Thanks a lot bro!!
@thatsawesome.2 жыл бұрын
thank you!
@MovieMinds_ Жыл бұрын
thank u bro, u helped me a lot
@omargaming8988 Жыл бұрын
Thank you very much bro❤❤❤
@wsaid_7912 Жыл бұрын
earned urself a sub
@acid33673 жыл бұрын
i absolutely love you
@renieronronshi71203 жыл бұрын
thank you so much you're a lifesaver thank you thank you thank youuuuuuuuuuuuuuu
@danielpo57713 жыл бұрын
Thank you...Gooooodd!!!!
@gabriel-accetta2 жыл бұрын
thanks, nice IDE bro
@chickinuggit4487 Жыл бұрын
This is nice
@bariraaz65053 жыл бұрын
Thank u sir
@3uz3 жыл бұрын
thanks very helpfull appreciate it ( share done)
@ricardoduplessis71272 жыл бұрын
you are a god!!
@kalengsarden3493 Жыл бұрын
thank sir
@jmm49633 жыл бұрын
Thank you!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@jogeshnanda770411 ай бұрын
Simple and Great... (Y)
@zachstarattack73203 жыл бұрын
You just made this assignment less awful.
@arwan6650 Жыл бұрын
print("Thank you so much!")
@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 Жыл бұрын
and i can apply this anywhere?
@xBZZZZyt3 жыл бұрын
This will crash if user repeats too many times because it is recursive.
@tejaspro7128 Жыл бұрын
yeah!
@itsdezman2 жыл бұрын
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 Жыл бұрын
Copy Paste your main code 10 times SUPER SIMPLE
@florinalexandruciovica25263 жыл бұрын
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_minister54263 жыл бұрын
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.
@Counterstrikeenjoyer3 жыл бұрын
@@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()
@johnray854 Жыл бұрын
now i have a looping calculator
@draizertbr63523 жыл бұрын
What if i want multiple "yes's" (e.g. yes,ye,yep) do i have to use elif??
@puddyy70103 жыл бұрын
use the or state mant
@hian773 жыл бұрын
Yes
@lukeliu42263 жыл бұрын
sheesh moment
@azhanisyahputra986710 ай бұрын
This would only works if you were using only one def function. Otherwise it will loop like forever 😢
@Ron-rd5th4 жыл бұрын
I keep getting an error saying "yes" is not defined when I enter yes for restart
@deeptiadval7283 жыл бұрын
you have to write if restart=="yes" main()
@bynishant96163 жыл бұрын
u cannot code noob
@bynishant96163 жыл бұрын
just like your dp u dumbfuck
@deeptiadval7283 жыл бұрын
put "yes" in a variable
@hamsahali47533 жыл бұрын
Unleash your Tech ????
@WhooseAGoose3 жыл бұрын
Doesn’t work 😐
@skillerx793 жыл бұрын
it does. watch out for indent. its important
@VinayGhate3 жыл бұрын
Bro If you want to get more subscriber then just hide the subscriber, people don't follow channel which have low subscribers
@MunjakGTK Жыл бұрын
Thank you for a clear and useful tutorial with no superficial talk only relevant stuff