Prac%ce Ques%ons
1. Write a program that asks the user to enter a non-nega%ve integer in the range [0, 255]
and prints the unsigned binary representa%on of the number in byte paCern. Hint:
calculate eight variables b0, b1, b2,...,b7 corresponding to the eight binary bits. Assume
the user will always enter a number in the range [0, 255].
2. Write a Python program that reads a length value in feet and inches and then prints the
length in meters and cen%metres.
3. The volume of a sphere is 4πr3/3 where r is the radius and the value of π is 3.14. Write a
program that reads a radius of a sphere and prints the volume.
4. Write a Python program that asks the user to input an integer n and then uses a while
loop to print the integers 1,2,3,...n. Assume the user input is always posi%ve.
5. Write a Python program that makes use of a while loop to print the integers 10, 9, 8, ..., 1.
6. Write a Python program that asks the user to input a number n. Then use a loop to add all
the numbers 1 + 2 + 3 + ... + n and print the sum. Assume the user input n is always
greater than 0.
7. Recall that the solu%ons to the general quadra%c equa%on 𝑎𝑥 ! + 𝑏𝑥 + 𝑐 = 0 are given by
Write a Python program that takes the coefficients a, b, and c as input and outputs the
solu%on to the quadra%c equa%on. Your program should also indicate how many unique
solu%ons the quadra%c equa%on has.
8. Write a function named successiveSum that takes one integer argument n and
returns the sum of the first n positive integers; that is 1+2+3+....+n. What does your
function return if the value of n is less than 1?
9. Write a function named successiveProduct that takes one integer argument n and
returns the product of the first n positive integers; that is 1*2*3*....*n.
10. Write a function named equal that takes two list arguments and returns True if the
two lists have the same length and elements of the two lists at the same indexes are
equal; otherwise return False. For example the list [1, 2, 4, 6] is equal to the list [1, 2,
4, 6]. But the list [1, 2, 4, 6] is not equal to [1, 2, 5, 6]. Write a main program to test
your function.
11. Write a Python function named isPalindrome that takes a List as argument and
returns True if the argument is a Palindrome List; otherwise it returns False. Write a
test main program to test the correctness of your function.