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

Name :_______________________

NPM :_______________________

Multiple Choices

1. What gets printed when Python execute 5. What will be the output after the
the following program? following statements?

a) [‘July’, ‘September’, ‘December’]


b) July
c) September
a) Yes d) December
b) No
c) True 6. What will be the output after the
d) False following statements?

2. What gets printed when Python execute


that program?
a) 2534
b) 59
c) 104
d) 3470

a) 3 7. What will be the data type of m after the


b) 3.0 following statement?
c) b
d) SyntaxError

a) List
3. What will Python produce if the following b) String
line is executed? c) Dictionary
d) Tuple

8. Which block of the code will never get


a) 2 executed (regardless of the value of a
b) 2.0 which is obtained from the user)?
c) 2.75
d) 3.0

4. What will Python produce if the following


line is executed?

a) Result is: 2.0


b) Result is: 4.0
a) BlockA
c) Result is: 6.0 b) BlockB
d) Result is: 8.0
Name :_______________________
NPM :_______________________

c) BlockC Answer:
d) BlockD
1.

2.
9. What is the output of the following
program? 3.

4.

5.

6.

7.

a) 0 8.
1
9.
2
3 10.
b) 0
2
1
3
c) 0
1
2
4
d) 0
2
1
4

10. What will be the output after the


following statements?

a) 67
b) 678
c) 679
d) 6789
Name :_______________________
NPM :_______________________

Short Essays

1. Trace the output of the following


programs:
2. Given the following program:
a.

Answer:

10

11

12 What will it produce if we input:


13 a. x = 2
b. x = 49
14 c. x = 50
d. x = 51

b. Answer:

a.

It’s an even prime number.

It’s small.

b.
Answer:
It’s an odd number.
5:0
It’s small.
5:1
c.
5:2
It’s an even number.
6:0
It’s medium
6:1
d.
6:2
It’s an odd number.

It’s big.

It’s medium.
Name :_______________________
NPM :_______________________

Long Essays

1. In a particular jurisdiction, taxi fares consist of a base fare of $4.00 for the first distance of 0-2
kilometers, and $0.25 for every 140 meters traveled afterwards. Write a program that takes the
distance traveled (in kilometers) as its only parameter and returns the total fare as its only

Answer:

#InputSection

distance = float(input("Please input distance in km:"))

cap = 2

base_fare = 4

rate = 0.25

dis_rate = 140

convert = 1000

#ComputationSection

if distance <= cap:

total_fare = base_fare

else:

if ((distance-cap)*convert)%dis_rate == 0:

total_fare = base_fare + rate*(int((distance-cap)*convert/dis_rate))

else:

total_fare = base_fare + rate*(int((distance-cap)*convert/dis_rate)+1)

#OutputSection

print("The total taxi fare is:", total_fare)

result.

2. You have just started a sales job in a department store. Your pay consists of a base salary plus a
commission. The base salary is $1,000. The following scheme shows how to determine the
commission rate:

Sales amount Commission rate


$0.00 - $5,000 8 percent
Name :_______________________
NPM :_______________________

$5.000,01 - $10,000 10 percent


$10.000,01 and above 12 percent

Write a program that returns your total pay if you input the sales amount.

Answer:

#InputSection

sales = float(input("Please input total sales:"))

base_salary = 1000

cap_1 = 5000

cap_2 = 10000

rate_1 = 0.08

rate_2 = 0.10

rate_3 = 0.12

#ComputationSection

if sales <= cap_1:

total_pay = base_salary + (rate_1*sales)

elif sales < cap_2:

total_pay = base_salary + (rate_1*cap_1) + (rate_2*(sales-cap_1))

else:

total_pay = base_salary + (rate_1*cap_1) + (rate_2*(cap_2-cap_1)) + (rate_3*(sales-cap_2))

#OutputSection

print("Your total pay is", total_pay)


Name :_______________________
NPM :_______________________

3. Suppose that the tuition for a university is $X this year and increases r% every year. Write a
program that determines the doubling time (minimum number of years that the tuition would
have doubled). Note: X and r are inputs in float.

Answer:

#InputSection

tuition_beg = float(input("Please input tuition fee this year:"))

rate = float(input("Please input tuition increase rate:"))

year = 0

tuition_end = tuition_beg

#ComputationSection

while tuition_end < 2*tuition_beg:

year += 1

tuition_end = tuition_end*(1+rate)

#OutputSection

print("Tuition will be doubled in", year, "years.")

You might also like