Practice Questions
Practice Questions
Programming Questions
2
Python Q
1. Consider the block of code below, where variables Athlete , beautician and
carpenter each have integer values.
a) Under which condition will the value in variable Athlete be printed?
3
Python Q
2 Write Program to evaluate below situation:
• We are in trouble if the parrot is talking and the hour is between 8pm and 7am, both
inclusive. If we are in Trouble then Return True else return False
4
Python Q
3. Outline a program that will prompt a user to enter a temperature as an
integer. Your program will print:
a) "it is hot" if the temperature is over 99,
b) "it is cold" if the temperature is under 60, and
c) "it is just right" if the temperature is between 60 and 99 inclusive.
5
Python Q
4. Create a program which will ask for your recent exam score out of 100.
a) The program should print what grade you got and how many more marks you
would have needed to get the next possible higher grade.
b) Grade Boundaries:
>=70 “Distinction”
>=60 <70 “First Class”
>=50 < 60 “Second Class”
>=35 <50 “Pass Class”
<35 “Fail”.
c) Test the program for all possible conditions at least once.
6
Python Q
5. Accept date in DD/MM/YYYY format, as a string.
a) Write two functions to convert it to:
MM/DD/YYYY string format
YYYY/MM/DD string format.
And print the new date
7
Python Q
6. Create a program that will allow the user to enter a line/quote.
a) Output this quote in uppercase, lowercase, capitalize and title formats.
8. Represent a 2x3 matrix using List. Write a program to find the biggest
number and its index.
8
Python Q
9. Write a program to Accept a String from the User using relevant keyboard
input method, and count the number of lower case letters in that string, and
print the count.
a) Test the program for three different input strings.
10. Given a String as parameter, write a function to reverse the string and
return the reversed string. Print the return value
a) Test the function
9
Python Q
11. Write a function to Print Multiplication Tables of 1 to 10.
a) 1x1 to 10x10 using relevant loop keywords.
b) Test the function
12. Write a Program to create a List which has Squares of Numbers from n1 to
n2
10
Python Q
13. Write a function to print odd numbers from num1 to num2 and return
count.
14. Write a function to print Even numbers from num1 to num2 and return
count.
15. Write a function to check if a given number is a prime number or not.
16. Write a function to print Prime numbers from num1 to num2 and return
count.
17. From a list containing int’s, string’s and float’s, make three lists to store
them separately.
18. Write a Python program that prints all the numbers from 0 to 100 except
multiple of 3 and 5.
19. Write a Python program to get the Fibonacci series between 0 to 50.
20. Write a python program to count the number of vowels in a user input
string.
11
Python Q
21. Create a program that will keep track of items for a shopping list.
a) The program should keep asking for new items until “endshopping” is entered.
b) The program should then display the full shopping list.
c) Test the above program for 5,8 and 10 items.
22. Create a function that will ask the user for a number and then print out a
list of numbers from 1 to the number entered and the square of the number.
a) For example, if the user entered '3' then the program would output:
b) 1 squared is 1.
c) 2 squared is 4.
d) 3 squared is 9
14
Python Q
29. Write a program that accepts a sequence of whitespace separated words as
input and prints the words after removing all duplicate words and sorting
them alphanumerically.
“hello world and practice makes perfect and hello world again”
15
Python Q
30. Game Rock, Paper Scissors is as described in the diagram.
2 players play the game.
Accept their names as input.
The game is in a loop for Num1 number of times.
Num1 is accepted by the user
The Player’s choice is within below range.
a) 0 for Rock
b) 1 for Paper
c) 2 for Scissor
The Results are:
a) Tie or one player would win.
b) Display the player’s name and choice
c) Display winners name.
Write Truth Table and Program for the game. 16
Python Q
31. Banking Functions
a) acnum = Create_account(acname, idnum)
b) balance=doCredit(acnum,amount)
c) balance=doDebit(acnum,amount)
d) balance=getBalance(acnum)
e) details=getAccountDetails(acnum)
17