0% found this document useful (0 votes)
6 views4 pages

Python Lab Questions

The document contains a list of 30 Python programming tasks aimed at enhancing coding skills. Tasks include number format conversions, mathematical calculations, string manipulations, and data structure operations. Each task specifies the expected input and output, providing a comprehensive guide for practice.

Uploaded by

Prashant Rathore
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)
6 views4 pages

Python Lab Questions

The document contains a list of 30 Python programming tasks aimed at enhancing coding skills. Tasks include number format conversions, mathematical calculations, string manipulations, and data structure operations. Each task specifies the expected input and output, providing a comprehensive guide for practice.

Uploaded by

Prashant Rathore
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

Python Lab Questions

1. Write a program to read numbers in one format and convert them into other formats
as shown below.
Input > output
a. Integer > binary, octal, and hexadecimal
b. Binary > int, octal, and hexadecimal
c. octal > binary, int, and hexadecimal
d. hexadecimal > binary, integer, and octal
2. Write a program to define two variables radius and height to calculate the area of a
right cylinder.
3. Write a program to print the Fibonacci Series up to length n (read the length form input).
4. Write a program to check whether the number entered is an Armstrong Number.
5. Write a program to print the following pattern for a given n.
Ex: Enter n value: 4

1
01
101
0101
6. Read a character from input and find out its type(don’t use inbuilt functions)
a. Alphabet or not
i. Lower case or Upper case
ii. Vowel or consonant
b. digit or not
i. even or odd
c. Special character or not
7. Write a program to swap two numbers using the bitwise XOR operator.
8. Write a program to read a value from input and perform following operations using
bitwise operators.
a. Identify the value of last two bits (whether 1 or 0)
b. Reverse the bits in the binary representation
c. shift last 3 bits to the right
d. shift last 2 bits to the left
e. count total zeros and ones in a binary number
9. Write a program to demonstrate following in-built functions
abs(), pow (), min (), max (), divmod(x, y), round (),bin(), oct(), hex()
10. Write a program to read the weight of the check-in luggage and calculate the charges for
overweight that exceeds the permissible limit 25kg at the rate of 2,500/- per 5 kg
thereafter. The weight is rounded off to the next multiple of 5 if the fraction is more than
2.5 kg or to the previous multiple of 5 if the fraction is less than 2.5 kg.
Sample Test Cases:
Enter the luggage weight: 27kg
Overweight charges are: 0/-
Enter the luggage weight: 29kg
Overweight charges are: 2,500/-
Enter the luggage weight: 56kg
Overweight charges are: 15000/-
11. Write a program to read a person’s work hours for the week and regular hourly wage,
calculate the total pay for a given week. Hours worked over 35 are considered as
overtime and paid at 1.5 times the normal rate.
12. Write a program to mimic bank transactions as described below.
a. Read account initial balance from the user and save in the account(declare a
variable ‘balance’).
b. Perform any three of the following operations (read three unique choices and
prompt the user for respective inputs and display the balance after each
transaction). If choices are not unique, prompt the user and abort the execution.
i. Show balance
ii. Add money
iii. Withdraw money
iv. Credit the interest (2%)
v. Deduct maintenance charges (0.05% subject to maximum of 250/-)
Sample test case:
Enter initial balance: 1000
Choose any 3 operations from the list given below
1. Show balance
2. Add money
3. Withdraw money
4. Credit the interest (2%)
5. Deduct maintenance charges (0.15% subject to maximum of 250/-)
2
3
5
Performing add money transaction
Enter the amount to be added: 500
Updated balance is 1500/-
Performing withdraw money transaction
Enter the amount to be withdrawn: 300
Updated balance is 1200/-
Performing Deduct maintenance charges transaction
Calculated charges are: 60/-
Deducted charges are: 60/-
Updated balance is 1140/-
13. Write a program to read a number and print the multiplication table.
Ex: Enter the number: 5
5*1=5
5 * 2 = 10

5 * 10 = 50
14. Write a program to find the sum of given numbers until the user enters 0.
15. Write a program to read a value n (n > 1) and print whether the number is a perfect
number, an abundant number, or a deficient number.
a. A perfect number is one where the sum of its proper divisors equals the number.
b. An abundant number is one where the sum of its proper divisors exceeds the
number.
c. A deficient number is one where the sum of its proper divisors is less than the
number.

Example:
Perfect Number: 28 (1 + 2 + 4 + 7 + 14)
Abundant Number: 12 (1 + 2 + 3 + 4 + 6)
Deficient Number: 16 (1 + 2 + 4 + 8)
16. Write a program to find the Greatest Common Divisor (GCD) and Least Common
Multiple (LCM) of two given numbers.
17. Write a program to read a string and 3 words from input and perform following

a. Check if all three words exist in the given string

b. If all are present and word1 precedes word2, replace all occurrences of word2
with word3.

c. If all are present and word2 precedes word1, replace all occurrences of word1
with word3.

d. If any one word is not available, replace all occurrences of word1 with word2 and
word2 with word1.
18. Write a program to count the number of vowels, consonants and special characters in a
given string.
19. Write a program to check whether a given string is a pangram or not.
Note: A string is a pangram if it contains all 26 English alphabets(case insensitive).
20. Write a program to swap consecutive elements in a list.
Ex: Input: [1,2,3,4,5,6,7,8] Input: [1,2,3,4,5,6,7]
Output: [2,1,4,3,6,5,8,7] Output: [2,1,4,3,6,5,7]
21. Write a program to search for an element(key) in the given list using a binary search
approach.

In binary search, first we match the middle element with the key and if it founds to be
less than the middle element, search continues in the left half of the list using same
approach, otherwise in the right half until the index of the element is found or there are
no more elements left to match, whichever is earlier. Assume the the values in the array
are in increasing order.

Ex: Input: [1,2,3,4,5,6,7], key = 5

First match is with 4 (middle index 3), key > middle value
Second match is with right sub list [5,6,7], match 5 with 6[middle element], key < middle
value
Third match is with the left sub list [5], match 5 with 5, match is found and index 4 is
printed.
22. Write a program to reverse a list.
23. Write a program to accept n integers from the user, store them in a tuple and find the
second maximum and second minimum element. Note: read values into a list and
convert it into a tuple.
24. Write a program using tuples to count the number of occurrences of days in a week from
a given string.
Note: Read the input as a single line(string) without any separators and parse it.

Ex: input = MonTueTueWedThuFriFriSatMonFriWed

Output:
Mon – 2
Tue – 2
Wed – 2
Thu – 1
Fri – 3
Sat – 1
Sun – 0
25. Write a program to read text from input and build the dictionary of words(keys) and their
frequencies(value). Print the list of words that appeared more than 2 times.
26. With a given integral number n, write a program to generate a dictionary that contains (i, i*i)
such that is an integral number between 1 and n (both included). and then the program should
print the dictionary.
Suppose the following input is supplied to the program:
8
Then, the output should be:
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}
27. Write a program to Concatenate two lists into a new list such that alternate elements
from two lists are placed in the new list.
Ex-1: Input: list1 = [1,2,3,4,5,6,7,8], list2 = [11,12,13,14,15,16,17,18]
Output: [1,11,2,12,3,13,4,14,5,15,6,16,7,17,8,18]

Ex-2: Input: list1 = [1,2,3,4,5], list2 = [11,12,13,14,15,16,17,18]


Output: [1,11,2,12,3,13,4,14,5,15,16,17,18]
28. Write a program to read two strings and print a new string which contains all uncommon
characters from both the strings.
Ex: String 1: HellO
String 2: Hihello
Output: Oiho
29. Write a program to read a text and print it in reverse order (don’t use inbuilt
expressions).
30. Write a program to print the following pyramid pattern for a given n(can be even or odd).

You might also like