Reputation: 11
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
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
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
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
Reputation: 1
You can convert the year into a string by wrapping it in the str()
function and then use + to concatenate.
Upvotes: 0