Latest Awards
Complete 10 python programs which focus on loops.

morgan

Score over 100 points in total

vincebanter10

Complete any 5 python programs

vincebanter10

Complete 3 python list based tasks

vincebanter10

Complete 5 python list based tasks

vincebanter10

Complete 10 python list based tasks

dman12

Score over 1000 points in total

april-logan

Complete any pygame task

april-logan

Complete any 3 pygame tasks

april-logan

You have to complete 5 pygame tasks

april-logan

Score over 500 points in total

sam-edmund

Complete any pygame task

sam-edmund

Complete any 3 pygame tasks

sam-edmund

You have to complete 5 pygame tasks

sam-edmund

Complete any pygame task

12wrigleyf

Complete any 3 pygame tasks

12wrigleyf

You have to complete 5 pygame tasks

12wrigleyf

Score over 500 points in total

jhoughton12

Complete any 10 python prograns

jhoughton12

Complete 10 python programs which focus on loops.

jhoughton12

Python Score
tasks = 0
achivements = 0
freestyle = 0
Total = 0
Top 5 Scores
114gilo 3500
2joss-nolan-2 2530
3alexdawkins 2515
4byrnebrian 2080
512wattsl 1750
Click to view all scores
Who else completed this task?
No one has completed this task yet. Be the first!

ELIF

Syntax

if
a
>
59
:
 
print 'True block'
elif
a
>
80
:
 
print 'runs only if the second condition evaluates to true'
else
:
 
print 'False block'

About elif

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"

Helpful links

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

Test your skill

1. Try the grade calculator task on the HackIT website.

Task 1: Hint SelectShow

2. Try the leap year task on HackIT.

Task 2: Hint SelectShow

Leave a Reply

You must be logged in to post a comment.