1st Year Python Assignment
1st Year Python Assignment
1. Write a Python program that asks the user for his name and then welcomes him.
2. Write a Python program that accepts principle, rate, and time from the user and
prints the simple interest.
3. Write a Python program that prompts the user to input principle, rate, and time
and calculate compound interest.
4. Write a program in Python to calculate the area and perimeter of various
polygons such as triangles, rectangles, and circles.
5. Write a program in Python to input 3 numbers separated by comma, and find the
largest and smallest among them.
6. Write a program in Python to find the roots of a quadratic equation using Python.
7. Write a program in Python to print all prime numbers inside a range of numbers
provided by the user.
8. Write a program in Python to print the mean and standard deviation of 5 scores
input by the user.
9. Write a program in Python to create a calculator that can perform basic
arithmetic operations.
10. Write a program in Python to convert temperatures between Celsius and
Fahrenheit.
11. Write a program in Python to check whether an input is even or odd.
12. Write a program in Python to check whether an input is leap year or not.
13. Write a python program that prompts the user to enter a number and determines
whether it is positive, negative, or zero.
14. Write a program that prompts the user to enter their age and prints the
corresponding age group. The program should use the following age groups:
0-12: Child
13-19: Teenager
20-59: Adult
60 and above: Senior Citizen
15. Write a program that prompts the user to enter their weight (in kilograms) and
height (in meters). The program should calculate the Body Mass Index (BMI)
using the formula: BMI = weight / (height * height). The program should then
classify the BMI into one of the following categories:
. . .
/_\ /\ /\
/___\ / \
/_____\
_ _
_| _| |_|
|_ _| |
1 2 1 2 3 1 2 3 4
4 3 8 9 4 12 13 14 5
7 6 5 11 16 15 6
10 9 8 7
N=2 N=3 N=4
**********
**********
**********
**********
8.
*
**
***
****
*****
9.
*
**
***
****
*****
10.
*
***
*****
*******
*********
11.
1
222
33333
4444444
555555555
12.
1
212
32123
4321234
543212345
Enter a number: 5
12 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
15. Write a program that takes an integer input n and prints all prime numbers from 2 to n using
nested loops. Here is a sample output:
Enter a number: 20
2 3 5 7 11 13 17 19
WEEK 5
1. Write a python program that accepts a string from user. Your program should count and
display number of vowels in that string.
2. Write a python program that reads a string from the keyboard and display:
* The number of uppercase letters in the string
* The number of lowercase letters in the string
* The number of digits in the string
* The number of whitespace characters in the string
3. Write a Python program that accepts a string from user. Your program should create and
display a new string where the first and last characters have been exchanged.
For example if the user enters the string 'HELLO' then new string would be 'OELLH'
4. Write a Python program that accepts a string from user. Your program should create a new
string in reverse of first string and display it.
For example if the user enters the string 'EXAM' then new string would be 'MAXE'
5. Write a Python program that accepts a string from user. Your program should create a new
string by shifting one position to left.
For example if the user enters the string 'examination 2021' then new string would be 'xamination
2021e'
6. Write a program that asks the user to input his name and print its initials. Assuming that the
user always types first name, middle name and last name and does not include any
unnecessary spaces.
For example, if the user enters Ajay Kumar Garg the program should display A. K. G. Note:
Don't use split() method
10. Write a python program to check whether an input of an arithmetic expression is correct or
not.
WEEK 6
1. Write a program to Insert and Delete elements from list based on a given position.
2. Find out Mean, Median and Mode of a list of numbers.
3. Sort a list of numbers without using a user defined function.
4. Use a dictionary to count the frequency of words in a string input by the user.
5. Given a list of numbers return the indices in which a specific number occurs.
6. Find and display the largest number of a list without using built-in function max().
7. Write a program that accepts a list from user and print the alternate element of list.
8. Write a program that rotates the element of a list so that the element at the first index
moves to the second index, the element in the second index moves to the third index,
etc., and the element in the last index moves to the first index.
9. Write a program that input a string and ask user to delete a given word from a string.
10. Write a program that reads a string from the user containing a date in the form
mm/dd/yyyy. It should print the date in the form March 12, 2021.
11. Write a program with a function that accepts a string from keyboard and create a new
string after converting character of each word capitalized. For instance, if the
sentence is "stop and smell the roses." the output should be "Stop And Smell The
Roses"
12. Find the sum of each row of matrix of size m x n. For example for the following
matrix output will be like this :
Sum of row 1 = 32
Sum of row 2 = 31
Sum of row 3 = 63
13. Write a program to add two matrices of size n x m.
14. Write a program to multiply two matrices.
15. Write a program to sort a matrix.
WEEK 7
1. Write a program to create a text file as per the path and filename provided by the user and add
text as input by the user.
2. Write a program to copy the content of a text file to another file but while copying convert all
capital letters to small letters.
3. Create a text file to append N lines such that each line displays the Fibonacci sequence upto
the term corresponding to specific line number separated by ‘-’. For N = 5 the text file should
read.
1
1-1
1-1-2
1-1-2-3
1-1-2-3-5
4. Take input four values from user with respect to number of books, pens, bags and total price
as follows. 36, 116, 23, 4649 and save it as a text file
Books: 36
Pens: 116
Bags : 23
Price : Rs. 4649
5. Write a program to create a dictionary by reading records from the text file output in program
4th
Dictionary : {“Books”:36, “Pens”: 116, “Bags”:23, “Price”: “4649”}
6. Write a program to take inputs from user to create a dictionary for storing and displaying
student data.
7. Store the dictionary data as a CSV file and write a function to display the data from the CSV
file.
8. Write a function to update or delete a specific record in student database csv file.
9. Write a program to print all elements in a list those have only single occurrence.
10. Write a program to read 6 numbers and create a dictionary having keys EVEN and ODD.
Dictionary's value should be stored in list. Your dictionary should be like: {'EVEN':[8,10,64],
'ODD':[1,5,9]}.
11. Write a program that reads string from user. Your program should create a dictionary having
key as word length and value is count of words of that length. For example, if user enters 'A
fat cat is on the mat'.
12. Write a program to input roll numbers and their names of students of your class and store
them in the dictionary as the key-value pair. Perform the following operations on the
dictionary:
a) Display the Roll numbers and name for all students.
b) Add a new key-value pair in this dictionary and display the modified dictionary
c) Delete a particular student's record from the dictionary
d) Modify the name of an existing students.