Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8252621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:36:30+00:00 2026-06-08T00:36:30+00:00

import random def main(): the_number = random.randint(1,100) guess = 0 no_of_tries = 0 while

  • 0
import random

def main():
    the_number = random.randint(1,100)
    guess = 0
    no_of_tries = 0
    while guess != the_number:
        no_of_tries += 1
        guess = int(input("Enter your guess: "))
        if guess < the_number:
            print "--------------------------------------"
            print "Guess higher!", "You guessed:", guess
            if guess == the_number - 1:
                print "You're so close!"
        if guess > the_number:
            print "--------------------------------------"
            print "Guess lower!", "You guessed:", guess
            if guess == the_number + 1:
                print "You're so close!"
        if guess == the_number:
            print "--------------------------------------"
            print "You guessed correctly! The number was:", the_number
            print "And it only took you", no_of_tries, "tries!"

if __name__ == '__main__':
    main()

Right now, in my random number guessing game, if a person guesses lower or higher by one number, they receive the following message:

Guess lower! You guessed: 33
You're so close!

But I want to make it one sentence.

For example:

Guess lower! You guessed: 33. You're so close!

How would I implement this in my code? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T00:36:32+00:00Added an answer on June 8, 2026 at 12:36 am

    Simply put a comma (',') after your print statement if you want to avoid it advancing to the next line. For example:

    print "Guess lower!", "You guessed:", guess,
                                               ^
                                               |
    

    The next print statement will add its output at the end of this line i.e., it will not move down to the start of the next line as you currently have.

    Update re comment below:

    To avoid the space due to the comma, you can use the print function. I.e.,

    from __future__ import print_function  # this needs to go on the first line
    
    guess = 33
    
    print("Guess lower!", "You guessed:", guess, ".", sep="", end="")
    print(" You're so close!")
    

    This will print

    Guess lower!You guessed:33. You're so close!

    This PEP also talks about the print function

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

from random import * while True: random1 = randint(1,20) random2 = randint(1,20) print(h =
from sys import exit from random import randint class Map(object): def death(): print quips[randint
Let's use the following code (conftest.py) : import random def test_val(): value = random.random()
At the Python terminal, I can run: import random random.randint(1,6) It gives a number,
here is my script: from random import * from turtle import * while True:
I have the following code: from random import randint,choice add=lambda x:lambda y:x+y sub=lambda x:lambda
import java.util.Random class Kostka { val rand = new Random(System.currentTimeMillis()) val value: List[Int] =
Heres my program so far import random def lottery(lottoNumber1,lottoNumber2,lottoNumber3): for count in range(1): lottoNumber1
I've got a fairly simple Python script: import Skype4Py from random import randint from
The following code is my attempt at simulating a lottery. import random def lottery(numbers):

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.