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

  Рет қаралды 62,360

Bonsaibrain

Bonsaibrain

5 жыл бұрын

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
@aloshie1 Жыл бұрын
crystal clear and helpful no 15minutes of messing with my head, straight to the point, thank you so much
@TuanTungTranDuc
@TuanTungTranDuc 4 жыл бұрын
Thank you for a clear and useful tutorial with no superficial talk only relevant stuff
@enternamehere6686
@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_
@myge_ Жыл бұрын
I HAVE BEEN LOOKIN FOR THIS FOR HOURS THANK YOU!!
@amendez721
@amendez721 3 жыл бұрын
Thank you very much for this tutorial!
@tigana
@tigana 3 жыл бұрын
Thank you this is exactly what I needed! Subbed
@65senshi
@65senshi Жыл бұрын
VERY Good explanation and helped me a lot!
@Kryptonite099
@Kryptonite099 2 жыл бұрын
Nice man, I got a task and thanks to you I did it!
@abukmoha5092
@abukmoha5092 4 жыл бұрын
Thank you very helpful appreciate it 💖 🙏🏾👊🏾
@sadgallington7850
@sadgallington7850 3 жыл бұрын
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 ^^
@seherjabar4876
@seherjabar4876 5 жыл бұрын
Useful video! Thanks
@PlantLover008
@PlantLover008 Жыл бұрын
Thank you, this really helped me out!
@debadeepdas1
@debadeepdas1 2 жыл бұрын
Thanks a lot for the help 👍🏾😊
@doko_bhai
@doko_bhai 15 күн бұрын
Bro you deserve more subs than you have you saved my life
@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.
@Subaka_
@Subaka_ 2 жыл бұрын
Very helpful had to make some changes to match my needs but was still very helpful
@djalone8445
@djalone8445 9 ай бұрын
thanks for this helpful information
@Charlie-ci7xn
@Charlie-ci7xn 3 жыл бұрын
Thanks mate it worked!
@zx74c
@zx74c 2 жыл бұрын
helped me alot! thank you!
@BizzaroBrainBoi
@BizzaroBrainBoi 4 жыл бұрын
very clear, very cool
@likhomaki6203
@likhomaki6203 Жыл бұрын
WOW... THANKS DAMN YOU GOOD. I HAVE BEEN STRUGGLING FOR DAYS AND YOU JUST MADE MY LOFE SIMPLE AS HELL.
@godman1117
@godman1117 3 жыл бұрын
Thanks you, very helpful script to know
@lordbloxmans4358
@lordbloxmans4358 6 ай бұрын
thanks so much bro, saved me so much time
@Mujiboy
@Mujiboy 3 жыл бұрын
Thanks man, Appreciated
@Yibilliboo-rq1ey
@Yibilliboo-rq1ey 11 ай бұрын
Thank You very much!!
@jorgemarinjaramillo221
@jorgemarinjaramillo221 Жыл бұрын
Justo lo que necesitaba gracias!! // exactly what I needed thanks!!
@razday8490
@razday8490 Жыл бұрын
THANK YOU SO MUCH BRO
@im_jst_tired4280
@im_jst_tired4280 Жыл бұрын
Thank you you’re a legend good sir
@NotMuj
@NotMuj 2 жыл бұрын
Thanks so much!
@user-jt8ty5vx9b
@user-jt8ty5vx9b 7 ай бұрын
Thanks a lot bro!!
@thatsawesome.
@thatsawesome. 2 жыл бұрын
thank you!
@MovieMinds_
@MovieMinds_ Жыл бұрын
thank u bro, u helped me a lot
@omargaming8988
@omargaming8988 Жыл бұрын
Thank you very much bro❤❤❤
@wsaid_7912
@wsaid_7912 Жыл бұрын
earned urself a sub
@acid3367
@acid3367 3 жыл бұрын
i absolutely love you
@renieronronshi7120
@renieronronshi7120 3 жыл бұрын
thank you so much you're a lifesaver thank you thank you thank youuuuuuuuuuuuuuu
@danielpo5771
@danielpo5771 3 жыл бұрын
Thank you...Gooooodd!!!!
@gabriel-accetta
@gabriel-accetta 2 жыл бұрын
thanks, nice IDE bro
@chickinuggit4487
@chickinuggit4487 Жыл бұрын
This is nice
@bariraaz6505
@bariraaz6505 3 жыл бұрын
Thank u sir
@3uz
@3uz 3 жыл бұрын
thanks very helpfull appreciate it ( share done)
@ricardoduplessis7127
@ricardoduplessis7127 2 жыл бұрын
you are a god!!
@kalengsarden3493
@kalengsarden3493 Жыл бұрын
thank sir
@jmm4963
@jmm4963 3 жыл бұрын
Thank you!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@jogeshnanda7704
@jogeshnanda7704 11 ай бұрын
Simple and Great... (Y)
@zachstarattack7320
@zachstarattack7320 3 жыл бұрын
You just made this assignment less awful.
@arwan6650
@arwan6650 Жыл бұрын
print("Thank you so much!")
@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 Жыл бұрын
and i can apply this anywhere?
@xBZZZZyt
@xBZZZZyt 3 жыл бұрын
This will crash if user repeats too many times because it is recursive.
@tejaspro7128
@tejaspro7128 Жыл бұрын
yeah!
@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
@florinalexandruciovica2526
@florinalexandruciovica2526 3 жыл бұрын
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 жыл бұрын
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.
@Counterstrikeenjoyer
@Counterstrikeenjoyer 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()
@johnray854
@johnray854 Жыл бұрын
now i have a looping calculator
@draizertbr6352
@draizertbr6352 3 жыл бұрын
What if i want multiple "yes's" (e.g. yes,ye,yep) do i have to use elif??
@puddyy7010
@puddyy7010 3 жыл бұрын
use the or state mant
@hian77
@hian77 3 жыл бұрын
Yes
@lukeliu4226
@lukeliu4226 3 жыл бұрын
sheesh moment
@azhanisyahputra9867
@azhanisyahputra9867 10 ай бұрын
This would only works if you were using only one def function. Otherwise it will loop like forever 😢
@Ron-rd5th
@Ron-rd5th 4 жыл бұрын
I keep getting an error saying "yes" is not defined when I enter yes for restart
@deeptiadval728
@deeptiadval728 3 жыл бұрын
you have to write if restart=="yes" main()
@bynishant9616
@bynishant9616 3 жыл бұрын
u cannot code noob
@bynishant9616
@bynishant9616 3 жыл бұрын
just like your dp u dumbfuck
@deeptiadval728
@deeptiadval728 3 жыл бұрын
put "yes" in a variable
@hamsahali4753
@hamsahali4753 3 жыл бұрын
Unleash your Tech ????
@WhooseAGoose
@WhooseAGoose 3 жыл бұрын
Doesn’t work 😐
@skillerx79
@skillerx79 3 жыл бұрын
it does. watch out for indent. its important
@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 Жыл бұрын
Thank you for a clear and useful tutorial with no superficial talk only relevant stuff
#20 Python Tutorial for Beginners | While Loop in Python
12:43
Telusko
Рет қаралды 1,6 МЛН
All Python Syntax in 25 Minutes - Tutorial
24:59
Beau
Рет қаралды 32 М.
DAD LEFT HIS OLD SOCKS ON THE COUCH…😱😂
00:24
JULI_PROETO
Рет қаралды 16 МЛН
Secret Experiment Toothpaste Pt.4 😱 #shorts
00:35
Mr DegrEE
Рет қаралды 34 МЛН
Clowns abuse children#Short #Officer Rabbit #angel
00:51
兔子警官
Рет қаралды 79 МЛН
Python 101: Learn the 5 Must-Know Concepts
20:00
Tech With Tim
Рет қаралды 1,1 МЛН
25 nooby Python habits you need to ditch
9:12
mCoding
Рет қаралды 1,7 МЛН
Make Menus In Python with While True Loop | Choose an Option in Python
13:54
Fabio Musanni - Programming Channel
Рет қаралды 29 М.
5 Useful F-String Tricks In Python
10:02
Indently
Рет қаралды 286 М.
While loops in Python are easy ♾️
6:58
Bro Code
Рет қаралды 332 М.
Python Decorators in 15 Minutes
15:14
Kite
Рет қаралды 433 М.
3 PYTHON AUTOMATION PROJECTS FOR BEGINNERS
17:00
Internet Made Coder
Рет қаралды 1,6 МЛН
The Fastest Way to Loop in Python - An Unfortunate Truth
8:06
mCoding
Рет қаралды 1,4 МЛН
Nested while Loop in Python
12:49
Neso Academy
Рет қаралды 11 М.