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.
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
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?
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.
@@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()
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.
crystal clear and helpful no 15minutes of messing with my head, straight to the point, thank you so much
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.
Good luck for your work ^^
I HAVE BEEN LOOKIN FOR THIS FOR HOURS THANK YOU!!
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
Thank you for a clear and useful tutorial with no superficial talk only relevant stuff
WOW... THANKS DAMN YOU GOOD. I HAVE BEEN STRUGGLING FOR DAYS AND YOU JUST MADE MY LOFE SIMPLE AS HELL.
Thank you, this really helped me out!
Thanks a lot for the help 👍🏾😊
thanks so much bro, saved me so much time
Bro you deserve more subs than you have you saved my life
That's what i'm looking for. Thanks for your efforts. Nice video.
thanks for this helpful information
Thank you very much for this tutorial!
thank u bro, u helped me a lot
Thank you very helpful appreciate it 💖 🙏🏾👊🏾
Useful video! Thanks
Nice man, I got a task and thanks to you I did it!
Thank you you’re a legend good sir
THANK YOU SO MUCH BRO
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.
Thanks a lot bro!!
Very helpful had to make some changes to match my needs but was still very helpful
Thank you very much bro❤❤❤
earned urself a sub
VERY Good explanation and helped me a lot!
thanks, nice IDE bro
Thanks you, very helpful script to know
Thank you this is exactly what I needed! Subbed
helped me alot! thank you!
Thanks man, Appreciated
Thanks mate it worked!
thank you!
Thanks so much!
Simple and Great... (Y)
thank you so much
you're a lifesaver
thank you
thank you
thank youuuuuuuuuuuuuuu
This is nice
very clear, very cool
The indent all is ruining all the the former indents I made, how do I prevent that?
Hello ye I tried this and when i run the program nothing gets printed out? please help I have no clue whats wrong
you are a god!!
Justo lo que necesitaba gracias!! // exactly what I needed thanks!!
Thank you...Gooooodd!!!!
i absolutely love you
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?
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.
@@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()
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.
Thank u sir
You just made this assignment less awful.
thanks very helpfull appreciate it ( share done)
thank sir
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?
Copy Paste your main code 10 times
SUPER SIMPLE
This will crash if user repeats too many times because it is recursive.
yeah!
and i can apply this anywhere?
I keep getting an error saying "yes" is not defined when I enter yes for restart
you have to write
if restart=="yes"
main()
u cannot code noob
just like your dp u dumbfuck
put "yes" in a variable
Unleash your Tech ????
now i have a looping calculator
print("Thank you so much!")
What if i want multiple "yes's" (e.g. yes,ye,yep) do i have to use elif??
use the or state mant
Yes
Thank you!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
It's not working
This would only works if you were using only one def function. Otherwise it will loop like forever 😢
Doesn’t work 😐
it does. watch out for indent. its important
sheesh moment
Bro If you want to get more subscriber then just hide the subscriber, people don't follow channel which have low subscribers
Thank you for a clear and useful tutorial with no superficial talk only relevant stuff