I Haz Codes
if |
a |
> |
59 |
: |
|
print |
'True block' |
||
elif |
a |
> |
80 |
: |
|
print |
'runs only if the second condition evaluates to true' |
||
else |
: |
|||
|
print |
'False block' |
||
elif allows you to chain together multiple if statements. It will only ever run one of the statements which is different to having separate if statements where multiple ones could be triggered.
Here is the code from the video. Try this code out for yourself.
age = int(raw_input("how old are you?")) if age < 0: print "error" elif age == 1: print "baby" elif age < 4: print "toddler" elif age < 10: print "young child" elif age < 17: print "teen" elif age < 60: print "adult" else: print "OAP"
http://www.pwnict.co.uk/webpages/python/syntax/lesson%205/lesson5.html
http://pentangle.net/python/handbook/node30.html
http://www.wellho.net/resources/ex.php4?item=y103/if4.py
1. Try the grade calculator task on the HackIT website.
2. Try the leap year task on HackIT.
Leave a Reply