0% found this document useful (0 votes)
136 views

Python Labsheet

Write functions to: 1) Calculate the maximum of two numbers. 2) Print a table of powers up to a given number. 3) Calculate the average of a series of marks entered until 0 is entered. 4) Prevent negative or out of range marks from being entered. 5) Calculate the middle value of a sorted list of student heights. 6) Extract and print email addresses from a string separated by semicolons. 7) Print prizes a customer is entitled to based on the number of new members introduced.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
136 views

Python Labsheet

Write functions to: 1) Calculate the maximum of two numbers. 2) Print a table of powers up to a given number. 3) Calculate the average of a series of marks entered until 0 is entered. 4) Prevent negative or out of range marks from being entered. 5) Calculate the middle value of a sorted list of student heights. 6) Extract and print email addresses from a string separated by semicolons. 7) Print prizes a customer is entitled to based on the number of new members introduced.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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 = [email protected]; [email protected]; [email protected]; [email protected]

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

You might also like