Python Forum
py4e book exercise not working when compiled
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
py4e book exercise not working when compiled
#11
Solved!
Problem with spaces inside the string, probably from a copy/ paste from the book.
Once I re-spaced the entire string, it all worked.
Reply
#12
(Jun-09-2018, 12:22 PM)adriand Wrote: Hi,

this exercise in the Py4E course should print: 21, 31, uct.ac.za.
When I run the program (python3 filename), my results are: 21, -1, uct.ac.za Sat Jan  5 09:14:16 2008.
Can someone tell me why is this happening?
Thanks.

data = 'From [email protected] Sat Jan  5 09:14:16 2008'
atpos = data.find('@') 
# the atpos variable will have the position of the @ sign

print (atpos)

spos = data.find(' ',atpos) 
# look for a space starting from the position of the @ sign
print (spos)

host = data[atpos+1 : spos]
print (host)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  John Guttag Book - Finger Exercise 4 - need help to make the code better pritesh 12 10,523 May-06-2020, 05:10 PM
Last Post: riteshp
  Book exercise in lists sonedap 17 6,863 Feb-03-2019, 08:37 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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