You are on page 1of 2

Addis Ababa institute of Technology

Center of Information Technology and Scientific Computing


Fundamentals of computer science and programming

Lab quiz

1. Number Conversion: Binary prints the binary (base 2) representation of the decimal number
typed as a function argument. It is based on decomposing a number into a sum of powers of two.
For example, the binary representation of 19 is 10011, which is the same as 19 = 16 + 2 + 1. To
compute the binary representation of N, we consider the powers of 2 less than or equal to Nin
decreasing order to determine which belong in the binary decomposition (and therefore
correspond to a 1 bit in the binary representation).

2. Dice Rolling simulator: Write a program that simulates random rolling of a fair dice given the
number of sides. If the dice is 6 sided the possible outcomes of a single roll will be between 1 and
6 with probability of 1/6.

3. Write a Python function ceil that takes a floating number and returns the next integer after the
number x, or x if x is already an integer. [NO CASTING ALLOWED]

For example,
ceil(3.7) should return 4

ceil(2.1) should return 3

ceil(4) should return 4

4. Elevator(Courtesy of Miss Sofanit)

DESCRIPTION

An elevator is given an input code which it then uses to go up or down floors:

"^" = go up one floor "v" (lower-case v) = go down one floor. The elevator starts on floor 0.

Write a generic program that determines the where the lift will end up given a string input.

Example input

"^v^^v^^vv^vv^vv^^vvv^^v^^^vv^^^vv^v^^vvv^^^^^v^v^v^v^vv^^vvv^^^^vvv^^vvv^^^^^vvvv
^^vvv^vv^^vv^vv^v^^^"
5. Write a function that accepts a number and moves the last digit of n to the first digit.

For example:

exchange_digit(126)=612

exchange_digit (2017)=7201

6. Write a program that finds an integer between 1 and 10000 that has the largest number of
divisors, and how many divisors does it have?
7. An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is
equal to the number itself. For example, 371 is an Armstrong number
Since 33 + 73 + 13 = 371.
Write a program to find all Armstrong number in the range of 0 and 999

You might also like