Python Forum
Write two statements to read in values for my_city followed by my_state. Assign log_e
Thread Rating:
  • 2 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Write two statements to read in values for my_city followed by my_state. Assign log_e
#1
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.
Reply
#2
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}'
likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Get an average of the unique values of a column with group by condition and assign it klllmmm 0 270 Feb-17-2024, 05:53 PM
Last Post: klllmmm
  python Read each xlsx file and write it into csv with pipe delimiter mg24 4 1,429 Nov-09-2023, 10:56 AM
Last Post: mg24
Question Special Characters read-write Prisonfeed 1 612 Sep-17-2023, 08:26 PM
Last Post: Gribouillis
  How do I read and write a binary file in Python? blackears 6 6,512 Jun-06-2023, 06:37 PM
Last Post: rajeshgk
  Read text file, modify it then write back Pavel_47 5 1,589 Feb-18-2023, 02:49 PM
Last Post: deanhystad
  how to read txt file, and write into excel with multiply sheet jacklee26 14 9,906 Jan-21-2023, 06:57 AM
Last Post: jacklee26
  Write Null values as 0.0 (float) type in csv mg24 3 1,365 Dec-07-2022, 09:04 PM
Last Post: deanhystad
  Read JSON via API and write to SQL database TecInfo 5 2,189 Aug-09-2022, 04:44 PM
Last Post: TecInfo
  Write and read back data Aggie64 6 1,865 Apr-18-2022, 03:23 PM
Last Post: bowlofred
  UART Serial Read & Write to MP3 Player Doesn't Work bill_z 15 5,796 Jul-17-2021, 04:19 PM
Last Post: bill_z

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020