I Haz Codes
if |
a |
< |
0 |
and |
a |
> |
10 |
: |
|
print |
'True block' |
||||||
else |
: |
|||||||
|
print |
'False block' |
||||||
Binary logic uses AND, OR and NOT to link together conditions in if statements and loops. Understanding binary logic is crucial if you want to use if statements effectivly.
Below is the sample code from the video.
age = int(raw_input("Enter your age")) if age >0 and age <120: print "age OK" else: print "not ok"
Binary logic – Using true and false statements to control a program.
PWNict logic in python and further logic
1. To ensure a number is between 1 and 10 you can use the code below. What should replace the ???
num = int(raw_input("enter a number - ")) if num >=1 ???? num <=10: print "ok"
2. Write a simple program, using just print, to display the logic tables for and, or and not.
3. Write a single if statement which will say “game on” if the user has more than 1 life left and has not won, otherwise it will say “stop game”. Use the variables below to get started –
gameWon = False lives = 10
Leave a Reply