Ich bin neu im Programmieren und bin auf ein Problem gestoßen, das ich nicht verstehen kann: Ich habe dieses Programm unPython

Python-Programme
Anonymous
 Ich bin neu im Programmieren und bin auf ein Problem gestoßen, das ich nicht verstehen kann: Ich habe dieses Programm un

Post by Anonymous »

Ich habe eine Funktion namens play() erstellt und wenn ich sie separat ausführe, funktioniert alles einwandfrei, aber wenn ich sie in meinem Programm ausführe, überspringt sie einfach die Wenns und führt sie erneut aus, egal was Sie eingeben, während sie separat tut, was sie soll. Ich freue mich über jede Erklärung, warum das so ist.

Code: Select all

import random

def main():
num = random.randint(0, 100)
score = 0
print("Guess the Number")
def question_1():
global score
try:
guess_1 = int(input(""))
if  num < guess_1:
score = score + 1
print("The Number is Smaller")
question_1()
if  num > guess_1:
score = score + 1
print("The Number is Bigger")
question_1()
if  num == guess_1:
score = score + 1
print(f"Congratulations you found the Number within {score} Attempts")
play()
except:
print("please enter a Number")
question_1()
def play():
again = input("Would you like to play again? ")
if again == "Yes":
print("Guess the Number")
main()
if again == "No":
quit()
else:
print("Please use Yes or No")
play()
question_1()
main()

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post