Python Forum

Full Version: Write two statements to read in values for my_city followed by my_state. Assign log_e
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
You can't edit lines 1-4 and line 11. This is what I have:
current_time = '2014-07-26 02:12:18:'
my_city = ''
my_state = ''
log_entry = ''

my_city = input("")
my_state = input("")
log_entry = (current_time + my_city + my_state)


print(log_entry)
The output I get is:
Output:
2014-07-26 02:12:18:HoustonTexas
Expected output is:
Output:
2014-07-26 02:12:18: Houston Texas
Not sure how to get those spaces. I've tried using commas instead of + but then I just get this:
Output:
('2014-07-26 02:12:18:', 'Houston', 'Texas')
Also tried
my_city = input("")
my_state = input("")
log_entry = print(current_time , my_city , my_state)
but then I get this"
Output:
2014-07-26 02:12:18: Houston Texas None
help plz.
One option is to manually add a space in between your data:
log_entry = current_time + ' ' + my_city + ' ' + my_state

A different (and better) solution would be to use string formatting:
log_entry = f'{current_time} {my_city} {my_state}'