Tobias Putz
Tobias Putz

Reputation: 3

Endless-Loop of Numbers

i'm new in Python and this time i'm working on a "Lotto, 6 out of 45" Gen. This is german gambling. So the problem is:

import random
print("Willkommen im 6 aus 45 - Lotto Generator")


def Gen():
    for i in range(0,7):
        print(random.randint(0,45))
Gen()

v = input("Willst du einen neuen Versuch? Ja/Nein: ")

while True:
    if v == "Ja":
        Gen()
    elif v == "Nein":
        exit()

The Problem is: If you type in "Ja" at the End, there is an endless loop of numbers. I would be very glad if someone can help me.

I'm from Austria. I'm sorry for my bad english.

Upvotes: 0

Views: 52

Answers (2)

Lentian Latifi
Lentian Latifi

Reputation: 132

Exit() or break in order to stop infinite loop

Upvotes: 0

inspectorG4dget
inspectorG4dget

Reputation: 114035

The issue is that you ask the question once, and then you loop forever. Instead, ask the question every time you loop:

while True:
    v = input("Willst du einen neuen Versuch? Ja/Nein: ")
    if v == "Ja":
        Gen()
    elif v == "Nein":
        exit()

Upvotes: 3

Related Questions