“deviner le jeu Python” Réponses codées

faire du jeu de deviner par Python

from random import randint
num = int(input("Enter a number = "))
ran = randint(1, 10)
if num == ran:
    print("Winner!")
    print("You pressed - ", num, "and random number is - ", ran)
Excited Earthworm

deviner le jeu Python

import random

num = random.randint(1, 9)

while True:

    try:
        guess = int(input("\nPlease enter a guess from 1-9: "))

        if 0 < guess < 10:

            if guess > num:
                print("\nYou guessed too high")

            elif guess < num:
                print("\nYou guessed too low")

            elif guess == num:
                print("\nYou guessed correctly")

                while True:
                    u_input = input("\nWould you like to play again? y/n: ")

                    if u_input == 'n':
                        exit()

                    elif u_input == 'y':
                        num = random.randint(1, 9)
                        break

                    elif u_input != 'y' and u_input != 'n':
                        print("\nError: Please select a valid option")

        elif guess < 1 or guess > 9:
            print("\nError: Please enter a number from 1-9")

    except ValueError:
        print("\nError: Please enter a number")
Amused Aardvark

Réponses similaires à “deviner le jeu Python”

Questions similaires à “deviner le jeu Python”

Plus de réponses similaires à “deviner le jeu Python” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code