281935 (2) [Avatar] Offline
#1
Just for completeness I would like to ask the question,
which Python version is targeted here and in which version the code samples are written?
Is it Python3 or Python 2.7, or a mixture of that?
283878 (1) [Avatar] Offline
#2
This book teaches python 3.5 as stated in lesson 2.
281935 (2) [Avatar] Offline
#3
Thanks for the fast reply.
Good to know in advance.
Unfortunately lesson 2 is not free, so it might be a usefully information for people before they buy the product.
Ana Bell (31) [Avatar] Offline
#4
Thanks for the feedback! I'll add this info in the Chapter 1 intro, and see if they can also put it in the description. Though even if you can't see the content of Ch 2, the subheadings of Lesson 2 say that you will download Python 3.5
Shaurya (1) [Avatar] Offline
#5
Why can't the Chapter 2 Python be free? Few more brief details would help if not whole chapter.
274544 (2) [Avatar] Offline
#6
My copy of the book arrived today. I currently have 3.6.5 installed on my system, do I need to backstep to 3.5?
Ana Bell (31) [Avatar] Offline
#7
Nope, you won't need to go back to 3.5. Everything in the book will work with all subversions of Python 3!
274544 (2) [Avatar] Offline
#8
OK. Thank you.
574761 (2) [Avatar] Offline
#9
Question regarding Q13.3
name1 = input('Enter a string: ')
space = name1.find(" ")
if name1 == space:
print('Your string has a space.')
if name1 != space:
print('Your string has no spaces.')

When entering Hello World string prints "Your string has no space."
When entering Hello string prints "Hello".

How do you set script to address situations with or without space?
Ana Bell (31) [Avatar] Offline
#10
I will walk you through how I debugged your code. First of all, print statements can be used for debugging purposes as well as for interaction with the user. So, you can add a print statement right before the if statements to see the values of name1 and space.

name1 = input('Enter a string: ') 
space = name1.find(" ") 
print("name1 is: ", name1)
print("space is: ", space)
if name1 == space: 
    print('Your string has a space.') 
if name1 != space: 
    print('Your string has no spaces.') 


With this, I think you could be able to figure out what the problem is if you run it. The value of space is a number, but name1 is whatever the user entered. So unless the user enters a number, they will never be equal.

Instead, you should be comparing the value of the space location with the number -1. If there is no space in the string, the find command gives you -1. If there is a space in the string, the value will be a number greater or equal to 0. So, the code that works will be:

name1 = input('Enter a string: ') 
space = name1.find(" ") 
if space != -1: 
    print('Your string has a space.') 
if space == -1: 
    print('Your string has no spaces.') 
574761 (2) [Avatar] Offline
#11
Thank you Dr for your rapid and infromarive response. This is a great book.