Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

number guessing game python

from random import randint
from pcinput import getInteger

answer = randint(1, 200)
count = 0

while True:
    guess = getInteger("What is your estimate? ")
    if guess < 1 or guess > 200:
        print("Your estimate must be between 1 and 200")
        continue
    count += 1
    if guess < answer:
        print("Higher")
    elif guess > answer:
        print("lower")
    else:
        print("You guessed it!")
        break

if count == 1:
    print("Wow first try !!.")
else:
    print("You estimated it in", count, "times.")
Comment

python number guessing game

import random

def instructions():
    print("Welcome to the number guessing game.")
    print("Guess a number between 1 and 10.")
    print("You only have 3 guesses.")

def game():
    # Guess limit so the user can only guess three times
    guess_limit = 1
    # The random guess
    actual_number = random.randint(1, 10)
    # What user can type and see
    guessed_number = int(input("What is the number?: "))
    # In case you guessed it right at the first time
    if actual_number == guessed_number:
        print("You guessed it right! The number is ", actual_number) 
    # The while loop so it can go on
    while guessed_number != actual_number:
        if guessed_number > actual_number:
            print("Lower")
        elif guessed_number < actual_number:
            print("Higher")
        
        guessed_number = int(input("What is the number?: "))
        guess_limit += 1
        if guess_limit == 3 and guessed_number != actual_number:
            print("You ran out of guess, The answer was number ",  actual_number)
            break
        
        else:
            print("You guessed it right! The number is ", actual_number)    

instructions()
game()
Comment

guessing game python

import random

num = random.randint(1, 9)

while True:

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

        if 0 < guess < 10:

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

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

            elif guess == num:
                print("
You guessed correctly")

                while True:
                    u_input = input("
Would 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("
Error: Please select a valid option")

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

    except ValueError:
        print("
Error: Please enter a number")
Comment

make guessing game by 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)
Comment

PREVIOUS NEXT
Code Example
Python :: how to get azure keyvalaut values into python function app 
Python :: adding bootstrap grid dynamically django 
Python :: how to create list python 
Python :: does the queen brush her teeth 
Python :: can i save additional information with png file 
Python :: sort true 
Python :: Cloud Build Quickstart 
Python :: Berlin 
Python :: *args **kwargs together in python 
Python :: documentation on fasttext gensim python 
Python :: tkinter set widht 
Python :: anaconda pytorch depencies windows 
Python :: matplotlib 3.4.1 und csv 
Python :: Inpunt and output 
Python :: scattter_matrix pandas 
Python :: can we use python functions in node 
Python :: initial TypedMultipleChoiceField django 
Python :: ** (ArgumentError) lists in Phoenix.HTML and templates may only contain integers representing bytes, binaries or other lists, got invalid entry: 
Python :: how to check if a word is a palindrome in python 
Python :: repetition of word in python 
Python :: dataproc initialization_actions error 
Python :: Python String to array using list() method 
Python :: selenium python login instagram 
Python :: pe039 
Python :: get method to create a set of counters in python 
Python :: select series of columns 
Python :: how to open camre aopencv 
Python :: how to add 2 integers in python 
Python :: is complex datatype immutable in python 
Python :: how to filter csv file by columns 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =