[Tutor] Help with 'if' statement and the concept of None

marat murad min786a at googlemail.com
Tue May 31 11:16:21 EDT 2016


Hi
I'm learning how to code with python an I have purchased the book 'Python
Programming for the absolute beginner,third edition' by Michael Dawson.
There is one concept that is confusing me in chapter 3 page 71 there is a
program  whose code I have pasted below. The author introduced a new way of
coding the Boolean NOT operator with the 'if' statement I have highlighted
the relevant area,apparently this if statement actually means if money !=
0,which I understood,but the program below this one which introduces the
idea of slicing also has a if statement similar to the first one,except the
second one accepts  0 value but the first one doesn't.

print("Welcome to the Chateau D'food")
print("It seems we are quit full today.\n")

money = int(input("How many dollars do you slip the Maitr D'? "))

*if money:*
    print("Ah I think I can make something work")
else:
    print("Please sit ,it may be a while")


input("\nPress enter to exit")


The slicing program

word = "existential"

print("Enter the beginning and ending index for the word existential")
print("press he enter key at 'Start' to exit")

start= None
while start != "":
    start=input("\nStart: ")

   * if start:*
        start=int(start)

        finish=int(input("Finish: "))

        print ("word[",start, ":",finish, "]is " , end="")
        print(word[start:finish])

input("\nPress enter to exit")

I hope i made sense.

Thankyou


More information about the Tutor mailing list