简体   繁体   中英

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.

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()

Exit() or break in order to stop infinite loop

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM