NAME-Vaishnavi Panchaware
BRANCH-CSAI(D)
PYTHON ASSIGNMENT-Fundamentals
Q1. Program to Calculate the Area of a circle and triangle
Output
2. Program to swap two variables
Output
3. Program to generate a random number
output
4. Program to convert kilometers to miles
Output
5. Program to find maximum of two numbers
Output
6. Program to check if a number is even or odd
Output
7. Program to check if a number is positive, negative or zero
Output
8. Program to calculate minimum desks required
Output
9. Program to find angle of hour hand
Output
10. Program to find fourth vertex of rectangle
Output
11. Program to find the lost card
Output
Enter total cards: 5
Enter card number: 1
Enter card number: 2
Enter card number: 4
Enter card number: 5
Lost card number: 3
Operators
12. Program to find maximum of three numbers
OUTPUT
13. Program to check leap year
OUTPUT
14. Program to check valid date
OUTPUT
15. Program to find roots of quadratic equation
OUTPUT
16. Given a string. Delete from it all the characters whose indices are divisible by 3
OUTPUT
17. Given a sequence of integer numbers ending with 0. Determine the length of the widest fragment where all
the elements are equal
OUTPUT
Enter a number (0 to stop): 2
Enter a number (0 to stop): 2
Enter a number (0 to stop): 2
Enter a number (0 to stop): 5
Enter a number (0 to stop): 5
Enter a number (0 to stop): 0
Longest sequence length: 3
18. In bowling, the player starts with 10 pins at the far end of a lane. The object is to knock all the pins down.
For this exercise, the number of pins and balls will vary. Given the number of pins N and then the number of
balls K to be rolled, followed by K pairs of numbers (one for each ball rolled), determine which pins remain
standing after all the balls have been rolled. The balls are numbered from 1 to N (inclusive) for this situation.
The subsequent number pairs, one for each K represent the start to stop (inclusive) positions of the pins that
were knocked down with each role. Print a sequence of N characters, where "I" represents a pin left standing
and "." represents a pin knocked down.
OUTPUT
19. Given two timestamps, calculate how many seconds are between them
OUTPUT
Python Assignment: Flow Control and loops
20. Program to display first n numbers
21. Program to calculate factorial of a number
22. Program to display numbers in the reverse order
23. Program to check if a number is prime
24. Program to calculate sum and average of first n numbers
25. Program to display first n multiples of a number
26. Program to display first n Fibonacci numbers
27. Program to find the sum of digits of a numbe
ASSIGNMENTS ON IN-BUILT DATA STRUCTURES
28. Program to create and view elements of a list
29. Program to create and view elements of a tuple
30. Program to access list index and values
31. Program to add two lists
32. Program to check if a list is empty or not
33. Program to find the largest number in a list
34. Program to find the second largest number in a list
output
35. Program to put even and odd elements into two different lists
output
36. Program to find all numbers in a range which are perfect squares and sum of digits is less than
10
output
37. Program to generate random numbers from 1 to 20 and append them to a list
output
38. Program to remove duplicate items from a list
output
39. Program to create and view a dictionary
output
40. Program to create and view elements of a set
output
41. Program to print values of dictionary
output
42. Program to print all keys of dictionary
output
43. Program to insert and delete from dictionary
output
44. Program to sort dictionary by value (ascending and descending)
output
45. Program to concatenate dictionaries
output
46. Program to check whether a given key exists in a dictionary
output
47. Program to merge two dictionaries
output
48. Program to get maximum and minimum value in a dictionary
output
49. Program to add a list of elements to a set
output
50. Program to update first set with items not in second set
output
51. Program to return elements present in Set A or B but not both
output
52. Program to check if two sets have any elements in common
output
53. Program to remove items from set1 not common to set2
output
ASSIGNMENTS ON FUNCTIONS
54. Function to check even or odd
output
55. Function to find maximum of two numbers
output
56. Function with keyword arguments
output
57. Function with default arguments
output
58. Factorial using recursion
output
59. Function to Find the Sum of the Digits of the Number Recursively
output
60. Create a function named count_vowels that accepts a string and returns the number of vowels
in the string
output
61. Write a function greet_user that takes a user’s name as a parameter and prints a personalized
greeting message
output
62. Write a Python program that accepts a sequence of integers from the user that ends with 00.
output
63. To keep record of students’ data, manipulate files to store, update, and delete students’
information.
output
64. Write a Python program that reads the content of a text file and prints it to the console.
output
65. Create a Python program that takes user input (a string) and writes it to a new text file.
output
66. Write a Python program that reads a text file, counts the number of words in it, and writes the
word count to a new file.
output
67. Write a Python program that reads the content of one text file and writes it to another file.
output
68. Develop a Python program that counts the number of lines in a text file and displays the count.
output
69. Write a Python program that appends a user-provided string to the end of an existing text file.
output
70. To keep record of patients’ medical data, manipulate files to store, update, and delete such
information.
output
71. Write a python program to create two 3X3 random matrixes and perform following operation:
(a) Addition (b) subtraction (c) multiplication and display shape, dimensions, dtype, Rank and
flatten output of every o/p matrix.
output
Matrix A:
[[2 7 3]
[4 1 8]
[5 6 9]]
Matrix B:
[[3 5 7]
[2 4 1]
[6 2 8]]
Addition:
[[ 5 12 10]
[ 6 5 9]
[11 8 17]]
Shape: (3, 3) Dimensions: 2 Dtype: int64 Rank: 3
Flatten: [ 5 12 10 6 5 9 11 8 17]
Subtraction:
[[-1 2 -4]
[ 2 -3 7]
[-1 4 1]]
Shape: (3, 3) Dimensions: 2 Dtype: int64 Rank: 3
Flatten: [-1 2 -4 2 -3 7 -1 4 1]
Multiplication:
[[41 31 43]
[74 34 78]
[93 55 95]]
Shape: (3, 3) Dimensions: 2 Dtype: int64 Rank: 3
Flatten: [41 31 43 74 34 78 93 55 95]
72. Write a Python program to plot line chart, bar chart, pie chart, scatter chart, histogram for
taking two different arrays as input.
output