Skip to content
← Back to Community
Beginner - ending a game
Profile icon
edimoo

Hi! I can't figure out how to make it so that the game ends when the user types "no" into the restart()) section under my code.
I'm a beginner, and I am quite frustrated :(

Voters
Profile icon
BenjaminOBrien
Profile icon
edimoo
Comments
hotnewtop
Profile icon
Bookie0

To end a game, just first do import sys
Then place sys.exit() where you want it to stop.
I wouldn’t recommend doing sleep(999) because then the user might not know if the repl is done or not.

Hope this helps!

Profile icon
edimoo

Thanks guys! Planning on doing a rick and morty prequel story thing so trying to figure out the technicalities before I enter everything in and it goes sideways :)

Profile icon
myrtlec

But I'm not really certain. However, I'd like to discuss a few of the reasons for the popularity of casino movies. Click here to investigate more about my blog. To minimize unwanted interruptions, the majority of these films were shot at night. As a result, you'll be immersed in the authenticity and natural ambiance of a casino every time you watch one of these wonderful films.

Profile icon
NicholasJohns17

zoomscopreyes cool game can you add more endings please

Profile icon
JeyAbrams

Howdy, I am sure that you have heard at any rate once in your life from a mate, an inconceivable story of winning in an online club, or winning a bet. I figure you didn't really trust in such pieces of jibber jabber, yet envision a situation wherein I uncovered to you that this happened to me also, and it essentially totally transformed me, when assistant asked me this site - https://nieuwecasinos-nl.com/ it is truly trustworthy and doesn't obstruct customers who sound money win.

Profile icon
NeelYang

@JeyAbrams Thanks a lot dude for this details, play crazy time free to win lots of money and be able to live amazing life!

Profile icon
BenjaminOBrien

By the way, all of your code has an extra indent for some reason.

Profile icon
Coder100

Hello, I'm sure that's because their tab size is different than yours @BenjaminOBrien

Profile icon
BenjaminOBrien

@Coder100 I don't think so, but it doesn't matter anymore, edimoo fixed it. :|
image

Profile icon
Coder100
Profile icon
BenjaminOBrien

First off, you dont need print(restart()), restart() will work as well. Second, make sure you place your restart() function calls in the right place, or else your game will continue to play even though you attempted to restart.

Also, if you just want the game to hang if the user types no, then just setup a while True loop like so:

while True: pass

You could also do this:

from time import sleep sleep(999) # or any amount of seconds to cause an infinite loop

Hope that helped. :D

Profile icon
edimoo

@BenjaminOBrien hey! thanks so much! It definitely did help :)

Profile icon
BenjaminOBrien

@edimoo No problem. :)

Profile icon
[deleted]

I think you just put return in there. Im not completely sure though.