Python
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:
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:
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:
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.
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.
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.