3

I have a question about How to delete a space in my guessing game.

Here is my source code:

import random
print ("I’m thinking of an integer, you have three guesses.")

def tovi_is_awesome():

    random_integer = random.randint (1, 10)
    chances = 3



    for i in [1,2,3]:
        print ("Guess", i, ": ", end=" ")
        guess = eval(input("Please enter an integer between 1 and 10:  "))

        if guess < random_integer:
            print ("Your guess is too small.")

        elif guess > random_integer:
            print ("Your guess is too big.")

        else:
            print ("You got it!")
            break


    if guess != random_integer:
        print ("Too bad.  The number is:  ", random_integer)

tovi_is_awesome ()

When I run it, I got this: I’m thinking of an integer, you have three guesses. Guess 1 : Please enter an integer between 1 and 10:

How can I delete that space after "Guess 1"? Or are there any better ways to avoid that space?

Thank you! This is my first question in SOF lol

2 Answers 2

2
print ("Guess", i, ": ", end=" ")

You could write it like;

print ("Guess {}: ".format(i), end=" ")

So you can avoid from that space. You could check this one for examples.

Here is a simple guess game, check it carefully please. It may improve your game. You dont' have to use eval().

random_integer = random.randint (1, 10)
chances = 3
gs=1
while 0<chances:
    print ("Guess {}".format(gs))
    guess = int(input("Please enter an integer between 1 and 10:  "))

    if guess<random_integer:
        print ("Your guess is too small.")
        chances -= 1 #lost 1 chance
        gs += 1 #increase guess number

    elif guess > random_integer:
        print ("Your guess is too big.")
        chances -= 1
        gs +=1

    else:
        print ("You got it!")
        break

It's really simple, just showing you some basic logic. You may consider in the future catching errors with try/except etc.

Sign up to request clarification or add additional context in comments.

Comments

0

print ("Guess %d:" % (i) )

Writing this way will delete the space.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.