vendredi 24 septembre 2021

Getting user input in the middle of text

I want to get the users input and put in the middle of the text, so if user types 7, it will say

Sorry, 7 is too high. Guess again.

Here's my code:

import random

def guess(x):
    random_number = random.randint(1,x)
    guess = 0
    while guess != random_number:
        guess = int(input(f"Guess a number between 1 and {x}: "))
        if guess < random_number:
            a = input()
            print("Sorry, (a) is too low. Guess again.")
        elif guess > random_number:
            print("Sorry, (a) is too high. Guess again.")

    print(f"Yay, congrats! {random_number} was the right number!")


guess(10)



Aucun commentaire:

Enregistrer un commentaire