Sunteți pe pagina 1din 2

NIE Teacher Training - Python Lab sheet

1.

2.

Write a python function to calculate the maximum of two numbers.


e.g.
>> max(89,67)
>> 89
Write a python function to print a table that contains the power of a given number e.g.
e.g. >> printPower(2,12)
2^1 = 2
2^2 = 4
2^3 = 8

2^12 = 4096
Note : to calculate 2^5 in python we need to use the following expression 2**5

3.

Write a program to input a series of marks from the keyboard. Calculate and find the Average of
the numbers. The user can stop entering values by entering 0.

4.

Modify the above program to prevent users from entering negative or marks above 100 by
making use of the continue statement.

6.

A list called heightList has the heights of the students in a class. If you assemble the students
according to the height, write a program to calculate the height of the student who is exactly in
the middle of the line.
Hint : You may need to use the sort function.
e.g heightList = [5.3, 4.2, 4.8, 5.1, 4.9]

7.

A string called emailstring has a list of email addresses separated by semi colons. Write a
program to extract the email addresses and print them.
Hint : store them into a list and then print them.
e.g. emailString = jkrow@gmail.com; opatha@gmail.com; joeperera@yahoo.com; saumi@hotmail.com

NIE Teacher Training - Python Lab sheet

8.

A certain credit card company has a promotion for existing customers to introduce new
members.
Prizes are given to the customers depending on the number of new members they introduce.
For example if a customer has introduced 6 people. Then he/she is entitled to a Wrist Watch,
Umbrella and a bag.
New Member
1
3
5
10
15

Prize
Wrist Watch
Umbrella
Bag
Mini TV Set
DVD Player

Write a program to input the number of new members a customer has introduced and print the
prizes the customer is entitled to.
Sample Dialog
Enter number of customers introduced : 6
Your prizes are a Wrist Watch, Umbrella, Bag

S-ar putea să vă placă și