Ask coding questions

← Back to all posts
If Statements
Pepper100 (6)

My code is a random number generator that takes an indented ridiculously long time to use. https://repl.it/@Pepper100/RNG2-Backup#main.py I have tried to edit it so if you use the right," Authorization code," it will skip the time and give you your random number there and then. It is coming up as an error in line 17 and I can't figure out why. Can anyone help me with this? code is https://repl.it/@Pepper100/Random-Number-Generator-2#main.py

Answered by Coder100 (4393) [earned 5 cycles]
View Answer
Commentshotnewtop
Coder100 (4393)

Ohh!! On line 16 you forgot closing parentheses!!
Really small mistake happens to the best of us!
Working repl:
https://repl.it/@Coder100/Random-Number-Generator-2-sol-for-pepper

Pepper100 (6)

@Coder100 oh my you are a life saver!

Coder100 (4393)

yay np! mark as correct answer? @Pepper100

Pepper100 (6)

@Coder100 I will but first after line 16 do you know how I can tell my code to stop there? There are other parts of the code that it is doing that I don’t want it to. If so what is the command please?

CodeLongAndPros (963)

@Pepper100 exit(0) to indicate success and exit(1) or exit({x}) to indicate errors, where x is any int greater than one.

Pepper100 (6)

@CodeLongAndPros tried both of those. They didn’t work. Just to be clear, I am looking for something I can put into my code. I think I said command before and I think I got mixed up. Looking for something to put in my code. Thanks!

CodeLongAndPros (963)

@Pepper100 Where did you put them?

Edit:
Oh, wait, you're supposed to replace {x} with a integer greater than one. Like 2, 3, 4.

Pepper100 (6)

@CodeLongAndPros in the wrong place lol. Moved them to the right place but it comes up with reply process died unexpectedly. Any way to get rid of it?

edit: it works, but it comes up with repl died unexpactedly in red, as if it was an error message. Do you know how to stop this from happening?

CodeLongAndPros (963)

@Pepper100 That's there because it did not go out the way repl expected. It left the party though the backdoor.

You could also put all your code in a main function and use return to break out.

Pepper100 (6)

@CodeLongAndPros how do I do that, I am not very good at python!

P.s. thanks for the help so far! I know this is taking up your time so I am very grateful!

Coder100 (4393)

To do that, just do:

def main():
  # Code here
  if "i want to exit" == True:
    return
main()

@Pepper100

Pepper100 (6)

@CodeLongAndPros Thanks for all the help, i have finished the code now!