“menebak game python” Kode Jawaban

Buat Game Menebak oleh 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

menebak game 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

Jawaban yang mirip dengan “menebak game python”

Pertanyaan yang mirip dengan “menebak game python”

Lebih banyak jawaban terkait untuk “menebak game python” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya