Tyler Dunkle
Tyler Dunkle

Reputation: 11

How to get rid of space between period

import datetime
from datetime import date
today = date.today()
user_name = input('What is your name? ')
user_age = int(input('How old are you? '))

print('Hello ' + user_name + '! You were born in', today.year - user_age, '.')

What is your name? Tyler How old are you? 31 Hello Tyler! You were born in 1991 .

Process finished with exit code 0

how do i get rid of the space between the period at the end?

I tried using + but it wont work because its an integer

Upvotes: 1

Views: 137

Answers (4)

iiSpidey
iiSpidey

Reputation: 21

Use an f string, just like this!

import datetime
from datetime import date
today = date.today()
user_name = input('What is your name? ')
user_age = int(input('How old are you? '))
print(f"Hello {user_name}! You were born in {today.year - user_age}.")

Upvotes: 2

Chris
Chris

Reputation: 36611

Use an f-string to print for greater control. By default print uses a space as a separator between seperate items.

print(f"Hello {user_name}! You were born in {today.year - user_age}.")

Upvotes: 0

Virt
Virt

Reputation: 13

print() adds spaces and new lines by default. You can utilize the sep argument to prevent spaces being injected:

print('Hello ' + user_name + '! You were born in ', today.year - user_age, '.', sep='')

See here:

How do I keep Python print from adding newlines or spaces?

Upvotes: 0

Phillips Olagunju
Phillips Olagunju

Reputation: 1

You can convert the year into a string by wrapping it in the str() function and then use + to concatenate.

Upvotes: 0

Related Questions