A
A
Andrey Godunko2021-06-03 17:02:30
Python
Andrey Godunko, 2021-06-03 17:02:30

How to run code again in Python?

I wanted to make a simple game in Python. But here's the problem. I don't know what command to run the code again. I went to Google and there were such questions ... But the answers to them did not help me. I need some kind of PiP, or a function to run the code again. Let's not use the method of creating a function))

If this is the code, I agree it's simple, but I'm still learning))

import random
import time

#ask

random = ( random.randint(1, 2) )
number = float( input( 'Enter the number 1 or 2. If you guess right, you'll get a prize!' ))

#guessed
if random == number:
a = str( input( 'You guessed it!! Give me your elect wallet number and we'll get the money. :' ))
print( 'Excellent!! The money will come in 5 minutes.' )
exit = input( 'The program is finished! The Trojan will exit in 15 seconds.\n To exit the program press f\n Thank you for watching to the end))) ' )
time.sleep(15)

elif exit == 'f':
SystemExit(1 .

_
_
_

_
_

_ ' or b == 'yes':
print( 'd' )
###########here I need to run the code again################# #########################################

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
WolfInChains, 2021-06-03
@Noy-name-boy

Judging by the description, you want to loop it, not restart it. You can add a loop after the imports, then after the code is executed, it will return to the beginning and "launch the code again", and so on ad infinitum, or until you stop it yourself by closing the window / adding a condition with to the code. while True:break

S
Sergey Gornostaev, 2021-06-03
@sergey-gornostaev

You need it in the frontend, it is considered normal to install a module there to supplement the line with indents.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question