Python 3.4 - Comments and Break

Comments won't be printed in your program. They are there for others to be able to understand your code and what you were thinking, if possible. 

magicnumber = 99 #This is the magic number, a variable I created. 
for n in range(101): #We'll be going through 100 numbers    if n is magicnumber: #I think the rest is self explanatory        print('You are it!')
    else:
        print("you are not it")

 A break will stop your program from running on that loop, if the conditions are met. This will kick you out of your loop so be careful:

magicnumber = 99
for n in range(101):
    print("you are not it")
    if n is magicnumber:
        print(n, 'You are it!')
        break

In this example the output stops once it reaches the magicnumber and doesn't print for number 100 because the break statement stops the loop. 

https://www.youtube.com/watch?v=k6rkvgQkW04

Comments

Popular posts from this blog

Pyhton 3.4 - Continue

Conversations Ongoing: Valuing Modernization in Early European History

Conversations Ongoing: A Bunch of Amateurs