Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

The examination of computer programming by Python

Instruction:
For each test below, it should be saved in a single .py
file, which should be named by its test number, such as
“test1”, “test2”, and so forth.

Test1:
1. a=123.456, print out its int type.
2. b=123, print out its float type.

Test2:
a = ‘abcdefghijklmnopqrstuvwxyz’
1. print out the first letter, the fifth letter, the last
letter, by its offset.

Test3:
1. There are five separated strings as ‘Now’, ’I’, ‘am’,
‘writing’, ‘Python’. Print it out as a single complete
sentence.

Test4:
Build up a list named “list1” with six elements as ‘aa’,
’bb’, ‘cc’, ‘dd’, ‘ee’, ‘ff’;
1. print out the second element, the fourth element of
the list by its offset.
2. print out the elements from the third to the firth,
sequentially, by its offset.
3. Build up a new list named “list2” with an element as
‘gg’, and combine it into list1.

Test5:
,
1. print out all elements in this list whose value is
greater or equal to 5, by using “if condition”, and
“while loop”.

Test6:
Use the conditional of ”if” to finish the following
purpose:
1. if the input number is less than 10, print out “The
input is less than 10”;
2. if the input number is equal to 10, print out “The
input is 10”;
3. if the input number is greater than 10, print out “The
input is greater than 10”

Test7:
1. Define a function as functionA(x,y), and whose
purpose is to print out the sum of x and y;
2. Define a function as functionB(x,y), and whose
purpose is to print out the subtraction of x from y;
3. Define a function as functionC(x,y), and whose
purpose is to print out the accumulation from x to y.
(Notice: the sum means adding two numbers, while the
accumulation means adding all numbers together)

Test8:
Define a functionA(d) to calculate and print out the
green area; the input d is the width of the rectangle.
(Notice: the rectangle is a square, whose width is equal
to its height; and the radius of the inner circle is a half
long of the square’s width.
The area of rectangle = d*d;
The are of circle = r*r*3.14;
The r of circle: r = d/2;
)

Test9:
Use loop of “for” to print out a star pattern with x rows,
and the number of stars of each line is one less than the
previous line.
For example,
if the input x = 5; the pattern is like:
*****
****
***
**
*
if the input x = 3; the pattern is like:
***
**
*

You might also like