Q1 Write a program to convert Celsius to Fahrenheit.
Q2 Write a program to take marks of the students as input and convert it into grades.
17.08.23
Q1 Write a program to print the following:
(a) 1 2 3 4 5 6 7…n terms
(b) 1 3 5 7 9…n terms
(c) 1 -3 5 -7 9…n terms
(d) Result of 1+2+3+4+5…n terms
(e) Result of 1+3+5+7+9…n terms
(f) Result of 1-3+5-7+9…n terms
(g) 10 9 7 8 6 5 4 3 2 1 for n terms
Q2 Print the following patterns:
(a)
11
111
1111
for n terms
(b)
12
123
1234
For n terms
(c)
12345
1234
123
12
For n terms
Q1 Find the sum of the digits of a number
Q2 Check the given number is Armstrong number or not.
Q3 Find the prime factors of a given number.
Q4 You have three numbers. Find the second largest number.
Q5 Print the following series:
(1/(2*3))-(2/(3*4))+(3/(4*5))-(4/(5*6))…
List programs
Q1 Write a program to create a list of even numbers from 1 to 100.
Q2 Answer the following questions for the list created in Q1. Use inbuilt methods to perform these
operations.
(a) Insert 12 at position 2 in the list.
(b) Add 155 at the end of the list.
(c) Count the number of 12 in the list.
(d) Remove element at location 3.
(e) Remove 6 from the list.
(f) Add the elements [12,24,36] at the end of the list.
(g) Clear the list.
Q3 Write a program to add two matrices.
Q4 Create a list of the factors of 100.
Q5 Perform the following using list comprehension:
(a) Create a list of 1 to 100.
(b) Create a list of factors of 2,3 and 5.
(c) Create the following list [[1,2,3],[1,2,3],[1,2,3],[1,2,3]]
(d) You have a list [1,0,0,0,1,1,1,1,1,1,0,0,0]
Create a list s.t if 1 is there then “True” else if 0 is there then “False” is entered in the list.
(e) You have a list of marks of students. Get the list of grades from the marks.
100<=marks<=90 A
90<marks<=70 B
70<marks<=50 C
50<marks<=30 D
30<marks<=0 E
Rest of the cases “NA”
Q1 Write a program to sort a list of numbers without using sort method.
Note: Go through all the dictionary methods in w3schools.
Q3 Create a dictionary “First_year” containing the key:name and value:enrollment. Insert three
records in this list.
(a) Print all the keys present in this list.
(b) Print all the values present in this list.
(c) Delete a record from the list.
(d) Update a record in the list.
Q4 Create a dictionary “NU” containing two sub dictionaries “A3” and “A4”. Take then name, section
and enrollment number as input from user. If the student is from A4 section then insert the details in A4
dictionary else insert in A3 dictionary.
Questions for practice
Python Program to Print all Prime Numbers in an Interval
Python Program to Find the Factorial of a Number
Python Program to Display the multiplication Table
Python Program to Print the Fibonacci sequence
Python Program to Check Armstrong Number
Python Program to Find Armstrong Number in an Interval
Python Program to Find the Sum of Natural Numbers
Python Program to Display Powers of 2 Using Anonymous Function
Python Program to Find Numbers Divisible by Another Number
Python Program to Convert Decimal to Binary, Octal and Hexadecimal
Python Program to Find ASCII Value of Character
Python Program to Find HCF or GCD
Python Program to Find LCM
Python Program to Find the Factors of a Number
Python Program to Make a Simple Calculator
Python Program to Shuffle Deck of Cards
Python Program to Display Calendar
Python Program to Display Fibonacci Sequence Using Recursion
Python Program to Find Sum of Natural Numbers Using Recursion
Python Program to Find Factorial of Number Using Recursion
Python Program to Convert Decimal to Binary Using Recursion
Python Program to Add Two Matrices
Python Program to Transpose a Matrix
Python Program to Multiply Two Matrices
Python Program to Check Whether a String is Palindrome or Not
Python Program to Remove Punctuations From a String
Python Program to Sort Words in Alphabetic Order
Python Program to Illustrate Different Set Operations
Python Program to Count the Number of Each Vowel
Python Program to Access Index of a List Using for Loop
Python Program to Flatten a Nested List
Python Program to Slice Lists
Python Program to Iterate Over Dictionaries Using for Loop
Python Program to Sort a Dictionary by Value
Python Program to Check If a List is Empty
Python Program to Catch Multiple Exceptions in One Line
Python Program to Copy a File
Python Program to Concatenate Two Lists
Python Program to Check if a Key is Already Present in a Dictionary
Python Program to Split a List Into Evenly Sized Chunks
Python Program to Parse a String to a Float or Int
Python Program to Print Colored Text to the Terminal
Python Program to Convert String to Datetime
Python Program to Get the Last Element of the List
Python Program to Get a Substring of a String
Python Program to Print Output Without a Newline
Python Program Read a File Line by Line Into a List
Python Program to Randomly Select an Element From the List
Python Program to Check If a String Is a Number (Float)
Python Program to Count the Occurrence of an Item in a List
Python Program to Append to a File
Python Program to Delete an Element From a Dictionary
Python Program to Create a Long Multiline String
Python Program to Extract Extension From the File Name
Python Program to Measure the Elapsed Time in Python
Python Program to Get the Class Name of an Instance
Python Program to Convert Two Lists Into a Dictionary
Python Program to Differentiate Between type() and isinstance()
Python Program to Trim Whitespace From a String
Python Program to Get the File Name From the File Path
Python Program to Represent enum
Python Program to Return Multiple Values From a Function
Python Program to Get Line Count of a File
Python Program to Find All File with .txt Extension Present Inside a Directory
Python Program to Get File Creation and Modification Date
Python Program to Get the Full Path of the Current Working Directory
Python Program to Iterate Through Two Lists in Parallel
Python Program to Check the File Size
Python Program to Reverse a Number
Python Program to Compute the Power of a Number
Python Program to Count the Number of Digits Present In a Number
Python Program to Check If Two Strings are Anagram
Python Program to Capitalize the First Character of a String
Python Program to Compute all the Permutation of the String
Python Program to Create a Countdown Timer
Python Program to Count the Number of Occurrence of a Character in String
Python Program to Remove Duplicate Element From a List
Python Program to Convert Bytes to a String
Strings programs
Q1 Take a string as input from user. Use string methods to perform the following:
(a) Capitalize the first character of the string.
(b) Check that the string begins with “The”.
(c) Check that the string ends with “big.”.
(d) Count the number of occurrences of “apple” in the string.
(e) Convert the string to lowercase.
(f) Convert the string to uppercase.
(g) Count the number of words in the string. Hint:use split().
(h) Check that the first two characters are alphabets and the last two characters are digits.
(i) Replace all “cats” with “dogs”.
(j) Replace “i” with “j”, “l” with “m”. Hint: use maketrans() and translate().
Q2 Write a program to check the given string is a palindrome or not.
Q3 Write a program to count the vowels and consonants in the string.
Q4 Write a program to take two words as input. Check whether these words are anagram or not.
Functions:
Q1 Find the sum of the series 1,2,..n using recursion. Pass n as argument to the function add().
Q2 Create a function prime(n). It returns true if n is prime else returns false.
Q3 Create a function primefactors() to return the prime factors of a given number. Call the function
prime(n) in Q2 to check the number is prime or not.
Q3 Create a function factors(n=4) [default arguments] which takes a number as argument and returns
the list of factors of the number n. If no arguments are passed then it returns the factors of 4.
Q5 Create a function add() to return the summation of arbitrary or any number of arguments.
Q6 Create a function str(a1,a2). Where a1 and a2 are two strings. The function returns the list of
common words in a1 and a2.
Files:
Q1 Create a file “abc.txt” in a specific drive or folder. Write the following content in the file:
I am great.
I am intelligent.
I love my family.
Close the file.
Q2 Count the number of vowels and “.” In the file “abc.txt”
Q3 Append the following content in the file “abc.txt”.
I am happy.
Q4 Demonstrate the difference between w+ mode and r+ mode with the help of a code.
Q5 Write some bytes in the binary file “bin”. Close the file. Append some contents in the file. Then close
the file. Thereafter read the contents of the file and then close the file.
Q6 Take file path (of a text file) as argument from the user, pass this argument in function rd(). Function
rd() reads the content of the text file and returns the first four characters of the file.