0% found this document useful (0 votes)
32 views17 pages

Practice Questions

Uploaded by

shruti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views17 pages

Practice Questions

Uploaded by

shruti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

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?

If athlete < beautician:


if beautician < carpenter:
print (carpenter)
1) Athlete is 1, beautician is 2 and carpenter is 3
else :
2) Athlete is 1, beautician is 3 and carpenter is 2
print (beautician)
3) Athlete is 3, beautician is 2 and carpenter is 1
elif athlete < carpenter: 4) Athlete is 2, beautician is 1 and carpenter is 3
print (carpenter) 5) Under no circumstances, because variable
else : Athlete’s value can never be printed by this code
print (athlete)

3
Python Q
2 Write Program to evaluate below situation:

• We have a loud talking parrot.


• The "hour" parameter is the current hour time in the range 0..23.
• The ‘talking’ parameter indicates if Parrot is talking or not.

• 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

• Write the required function.


• Test the function for all possible conditions.

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.

7. Write a function called countUp that accepts two integer parameters.


a) The function will print out all integers between the two parameters (excluding both
parameters!), from lower parameter to higher parameter in ascending order.
b) Write using While loop
c) Write using For Loop

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

23. Define a function called fnStringMirror:


a) This function will get an input string as a parameter and returns its mirror image.
b) For e.g if input string is “blue”, the mirror image is “blueeulb” 12
Python Q
24. Write a program that accepts a sentence and calculate the number of letters
and digits.
25. Write a program to compute the frequency of the words from the input
sentence. Display the frequency of each word from the sentence.
26. Write a function which will:
a) Create a list of 10 random integers.
b) Then find the largest of the list of numbers, using a loop.

27. A palindrome is a word, phrase, number, or other sequence of characters


which reads the same backward or forward. E.g “MALAYALAM”.
a) Write a program to accept a string as input.
b) Check if the String is a Palindrome and print relevant messages.
c) The Program is in loop, and will end if user input string is “end”
13
Python Q
28. Extract Title from below strings

a) Dev, Mr Kapil. 60, Delhi


b) Roy,Mrs Saina. 30,Kolkata
c) Wodeyar, His-Excellency Yaduveer. 30, Mysore
d) Anand, Dr Ramanath. 45, Chennai

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.

Suppose the following input is supplied to the program:

“hello world and practice makes perfect and hello world again”

Then, the output should be:


“again and hello makes perfect practice world”

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)

Write Python Programs for above requirements.


Think through the process for above requirements and make your own
programming assumptions.

17

You might also like