Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # date: 2026.01.20
- # [python - I m new to coding and I ran into a problem I cant understand:I got this Programm and my funktion play doesnt work it just starts again - Stack Overflow](https://stackoverflow.com/questions/79867245/i-m-new-to-coding-and-i-ran-into-a-problem-i-cant-understandi-got-this-programm)
- import random
- def question():
- num = random.randint(0, 100)
- score = 0
- print("Guess the Number")
- while True:
- try:
- guess = int(input("> "))
- score = score + 1
- if num < guess:
- print("The Number is Smaller")
- if num > guess:
- print("The Number is Bigger")
- if num == guess:
- print(f"Congratulations you found the Number within {score} Attempts")
- return
- except ValueError as ex:
- print("Please enter a Number")
- def play_again():
- while True:
- again = input("Would you like to play again (Yes/No)? ")
- if again == "Yes":
- return True
- if again == "No":
- return False
- else:
- print("Please use Yes or No")
- def main():
- try:
- while True:
- question()
- if not play_again():
- break
- except KeyboardInterrupt: # it can catch Ctrl+C to stop program
- print("\nInterrupted by user")
- main()
Advertisement
Add Comment
Please, Sign In to add comment