-1

So I am new to coding, so I'm doing Python but I'm having this issue. (BTW sorry if I don't know the names for this stuff :3) So you know when you print and you put commas to have words and variables? Well I'm doing that and its putting spaces in between. Here's my code.

import time
import random


print("Dice rolling simulator!")
time.sleep(1.5)
a = int(input("Enter your first number: "))
b = int(input("Enter your second number: "))
print("Rolling..")
time.sleep(1)
print ("You rolled a",random.randint(a, b),"!")

Its printing "You rolled a (blank) !" Its putting a space between the number and the exclamation point. Please help!

Jayson
  • 3
  • 2

3 Answers3

0

Simply add sep="" in your print line:

print ("You rolled a ",random.randint(a, b),"!", sep="")

If you're interested in reading out more on arguments for print, here you go.

Deep Mehta
  • 116
  • 7
0

You can use placeholders in the string to have more control over the output:

>> print ("You rolled a {}!".format(random.randint(a, b)))
You rolled a 10!
Daniel Labbe
  • 1,979
  • 3
  • 15
  • 20
0

print insert a space separators between its parameters, you can remove it but might be just wanting to append a message and there is some better ways to do this:

Using format (python 3 only):

print ("You rolled a {}!".format(random.randint(a, b)))

Using format string (python 3 only):

print (f"You rolled a {random.randint(a, b)}!")

Python 2 style:

print ("You rolled a %d!" % random.randint(a, b))
gariel
  • 687
  • 3
  • 13