0% found this document useful (0 votes)
64 views10 pages

1st Year Python Assignment

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)
64 views10 pages

1st Year Python Assignment

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/ 10

WEEK 1

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:

less than 18.5 - Underweight


BMI between 18.5 and 24.9 - Normal weight
BMI between 25 and 29.9 - Overweight
BMI 30 or greater - Obesity
WEEK 2
1. Write a Python program that prompts the user to input a number from 1 to 7. The program
should display the corresponding day for the given number. For example, if the user types 1,
the output should be Sunday. If the user types 7, the output should be Saturday.
2. Write a Python program that prompts the user to input the number of calls and calculate the
monthly telephone bills as per the following rule:
Minimum Rs. 200 for up to 100 calls.
Plus Rs. 0.60 per call for the next 50 calls.
Plus Rs. 0.50 per call for the next 50 calls.
Plus Rs. 0.40 per call for any call beyond 200 calls.
3. Write a program in Python to calculate the factorial of a number.
4. Write a program in Python to calculate the Fibonacci sequence till a specific no. of terms.
5. Write a program in Python to calculate the factors of numbers.
6. Write a program in Python to calculate the magic square based on a given number.
7. Write a program in Python to check if a number is a palindrome.
8. Write a program in Python to check if a number is an Armstrong number.
9. Write a program in Python to check if a number is Krishnamurthy number.
10. Write a program in Python to find the sum of digits of a number.
11. Write a program in Python to reverse a given number.
12. Write a program in Python to find the sum of squares of the first n natural numbers.
13. Write a program in Python to convert a decimal number to a binary number.
14. Write a program in Python that prompts the user to input a number and prints its
multiplication table.
15. Write a Python program to print the first 6 terms of a geometric sequence starting with 2 and
having a common ratio of 3.
WEEK 3
1. Print the series upto N terms: 1, 4, 9, 16, 25, 36…
2. Print the series up to N terms: 2, 4, 8, 16, 32, 64…
3. Print the series upto N terms: 1, 3, 7, 13, 21, 31…..
4. Print the series upto N terms: 1, 2, 4, 8, 16, 23, 28, 38, 49, 62 …
5. Print the series upto N terms: 1,2,6,24,120,720 …
6. write a program that takes a positive integer N as input and calculates the sum of the
reciprocals of all numbers from 1 up to N. The program should display the final sum.
7. Write a Python program that prompts the user to enter a base number and an exponent, and
then calculates the power of the base to the exponent. The program should not use the
exponentiation operator (**) or the math.pow() function.
8. Write a Python program that prompts the user to enter a positive integer. Your program should
display all the factors of the number. Additionally, calculate and display the sum of its factors.
9. Write a python program that uses a loop to repeatedly ask the user to enter integers. The loop
will come to an end when zero is entered. After collecting all the integers, the program will
compute and display the average of all the entered numbers.
10. Write a python program to enter the numbers till the user wants and at the end it should
display the count of positive, negative and zeros entered.
11. Write a python program that prompts the user to input two numbers and display its HCF.
12. Write a python program to add first seven terms of the following series using a for loop:

13. Compute the sum up to n terms in the series


1 - 1/2 + 1/3 - 1/4 + 1/5 -... 1/n where n is a positive integer and input by user.
14. Write a program to compute sin x for given x. The user should supply x and a positive integer
n. We compute the sine of x using the series and the computation should use all terms in the
series up through the term involving xn
sin x = x - x3/3! + x5/5! - x7/7! + x9/9! ........
15. Write a program to compute cosine of x. The user should supply x and a positive integer n.
We compute the cosine of x using the series and the computation should use all terms in the
series up through the term involving xn
cos x = 1 - x2/2! + x4/4! - x6/6! ....
WEEK 4
1. Print the pattern upto N Lines:

. . .
/_\ /\ /\
/___\ / \
/_____\

N=2 N=3 N=4

2. Print a number as a 8 segment display N Lines:

_ _
_| _| |_|
|_ _| |

N=2 N=3 N=4


3. Print the pattern upto N lines:

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

4. Print the following pattern upto N lines:


1
11
121
1331
14641
1 5 10 10 5 1 …
5. Print the shape for Height = N

*** **** *****


** * * * *
*** * * * *
**** * *
*****
N=3 N=4 N=5
6. Floyd's triangle is a right-angled triangular array of natural numbers as shown below:

Write a program to print the Floy'd triangle.

7. Write programs to print following patterns :

**********
**********
**********
**********

8.

*
**
***
****
*****
9.

*
**
***
****
*****
10.

*
***
*****
*******
*********
11.

1
222
33333
4444444
555555555
12.
1
212
32123
4321234
543212345

13. Write a program that prints the following diamond pattern:


1
123
12345
123
1
14. Write a program that takes an integer input n and prints a pattern using the multiplication table
from 1 to n. Each cell in the pattern should contain the product of its row and column numbers. Here
is a sample output:

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

7. Write a program that determines whether the string is a palindrome.


8. Write a program that display following output:
SHIFT
HIFTS
IFTSH
FTSHI
TSHIF
SHIFT
9. Write a program in python that accepts a string to setup a passwords. Your entered password
must meet the following requirements:

● The password must be at least eight characters long.


● It must contain at least one uppercase letter.
● It must contain at least one lowercase letter.
● It must contain at least one numeric digit.

Your program should should perform this validation.

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'.

Word Word length


A 1
fat 3
cat 3
is 2
on 2
the 3
mat 3
The content of dictionary should be {1:1, 3:4, 2:2}

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.

You might also like