0% found this document useful (0 votes)
9 views3 pages

Python

Quiz

Uploaded by

sahkarwalvikram
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
9 views3 pages

Python

Quiz

Uploaded by

sahkarwalvikram
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 3

ITFC0101: Problem Solving using Python

Assignment
Note: The assignment has to be submitted in a single folder zipped as your roll no.s and
uploaded as .py file, each named with the question number.

1. You have a table with 10 chairs, and there are 5 friends who need to sit. Each
friend has specific preferences:

● Friend A wants to sit next to Friend B.


● Friend C does not want to sit next to Friend D.
● Friend E wants to sit at the head of the table.

How would you arrange the seating to meet all the constraints?write step by step
process to satisfy all conditions. Also write partial output after each step.

2. You have 4 boxes labeled A, B, C, and D. One box contains a prize. Each box has
a clue:

● Box A says, "The prize is not in Box B."


● Box B says, "The prize is in Box C."
● Box C says, "The prize is not in Box D."
● Box D says, "The prize is not in Box A."

Which box contains the prize? Justify your answer.

3. Design an algorithm (in the form of pseudocode) for a toll booth system that
calculates the fee for different types of vehicles. The system should distinguish
between cars, trucks, and motorcycles, with different toll rates for each type.

4. Design a flowchart for a simple banking system that allows users to check their
account balance, deposit money, or withdraw money. Ensure that withdrawals are
only allowed if there is enough balance. Make separate functions for each operation
(check balance, deposit, or withdraw). These functions will execute periodically
based on user inputs and terminate when the user responds as “NO”.

5. Create a flowchart for solving the Towers of Hanoi problem with 4 pegs (4 tower)
instead of 3 (Four Peg Hanoi problem). The flow chart should utilize the concept of
functions.

6. Write a program that prints the numbers from 1 to 100. But for multiples of three
print “Fizz” instead of the number and for the multiples of five print “Buzz”. For
numbers which are multiples of both three and five print “FizzBuzz”.

7. Write a Python program to count the number of even and odd numbers in a series
of numbers
Sample numbers : numbers = (1, 2, 3, 4, 5, 6, 7, 8, 9)
Expected Output :
Number of even numbers : 5
Number of odd numbers : 4
8. Write a program to calculate the sum of series up to n terms. For example, if n = 5
the series will become 2 + 22 + 222 + 2222 + 22222 = 24690

9. Write a program to print the following start pattern using the for loop
*
**
***
****
*****
****
***
**
*

10. Use nested loops, Write a program to print the following output:
111111111
222222222
...
888888888
999999999

11. Write a function that takes a year as a parameter and returns True if the year is a
leap year, False otherwise.

12. Write a program that continues to take in a number from the user until the number
given is NOT even. For example, the user might enter 4, 10, 42, 5. The program
would only stop when the non-even number 5 is entered.

13. Write a function slope(x1, y1, x2, y2) that returns the slope of the line
through the points (x1, y1) and (x2, y2). Be sure your implementation of slope can
pass the following doctests:

def slope(x1, y1, x2, y2):


"""
>>> slope(5, 3, 4, 2)
1.0
>>> slope(1, 2, 3, 2)
0.0
>>> slope(1, 2, 3, 3)
0.5
>>> slope(2, 4, 1, 2)
2.0
"""
Then a call to slope in a new function named intercept(x1, y1, x2, y2)
that returns the y-intercept of the line through the points (x1, y1) and (x2, y2).

def intercept(x1, y1, x2, y2):


"""
>>> intercept(1, 6, 3, 12)
3.0
>>> intercept(6, 1, 1, 6)
7.0
>>> intercept(4, 6, 12, 8)
5.0
"""

intercept should pass the doctests above.

14. Write a program to split a string based on criteria other than spaces.

15. Write a Python program to check if a string is a valid email address or a valid URL.

16. Write a Python program to split a list every Nth element.

Sample list: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n']
Expected Output: [['a', 'd', 'g', 'j', 'm'], ['b', 'e', 'h', 'k', 'n'], ['c', 'f', 'i', 'l']]

17. Write a Python program to replace the last value of tuples in a list.

Sample list: [(10, 20, 40), (40, 50, 60), (70, 80, 90)]
Expected Output: [(10, 20, 100), (40, 50, 100), (70, 80, 100)]

18. Write a Python program for a given Binary Tuple representing binary representation
of a number, convert to integer and vice versa.

Input: input_tuple=(1,1,0)
Output: 6
Explanation: 4+2=6

19. Write a Python program to convert a Tuple to List by adding the given string after
every element using list comprehension.

Input : test_tup = (5, 6, 7), K = "Gfg"


Output : [5, 'Gfg', 6, 'Gfg', 7, 'Gfg']
Explanation : Added "Gfg" as succeeding element.

20. Define a function called information that takes as input, the variables name,
birth_year, fav_color, and hometown. It should return a tuple of these variables in
this order.

You might also like