You are on page 1of 9

Session-I Assignments

1. Check the python version installed on your system through commandline.


2. WAP to print the ASCII value of a character. [Hint : ord() function]
3. WAP to find difference of two small integers (not greater than 10) without using minus (-) operator. [Hint : Use ~
operator]
4. WAP to multiply a given number by 2 without using * (multiply operator).
5. WAP to calculate and display the interest on a loan amount(Rupees).
You would need three variables to hold ‘principal’, Rate_of_interest’(%) and ‘time’ in years and can use the formula
Interest=(principal*rate_of_interest*time)/100
Note :Take user input
6. Write a Python program which accepts the radius of a circle from the user and compute the area.
7. Write a Python program that accepts an integer (n) and computes the value of n+nn+nnn
8. Take a 5 digit number as input and reverse it without using loop
9. Two numbers are input through the keyboard into two locations C and D. Write a program to interchange the contents of
C and D.
10. If a four-digit number is input through the keyboard, write a program to obtain the sum of the first and last digit of this
number.
11. In a town, the percentage of men is 52. The percentage of total literacy is 48. If total percentage of literate men is 35 of the
total population, write a program to find the total number of illiterate men and women if the population of the town is
80,000.
12. A cashier has currency notes of denominations 10, 50 and 100. If the amount to be withdrawn is input through the
keyboard in hundreds, find the total number of currency notes of each denomination the cashier will have to give to the
withdrawer.

Session-2 Assignments
13. Find maximum of three numbers
14. Check whether a number is prime.
15. Check whether a number is Armstrong
16. Find all primes between a given range
17. Write a Python program that accepts a word from the user and reverse it.
18. Write a Python program to count the number of even and odd numbers from a series of numbers
19. Write a Python program that prints all the numbers from 0 to 6 except 3 and 6.
Note : Use 'continue' statement.
20. Write a Python program to get the Fibonacci series between 0 to 50
21. Write a Python program which iterates the integers from 1 to 50. For multiples of three print "Fizz" instead of the
number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print
"FizzBuzz".
22. Write a Python program to check whether an alphabet is a vowel or consonant
23. Write a Python program to calculate the sum and average of n integer numbers (input from the user). Input 0 to finish.
24. Write a Python program to create the multiplication table (from 1 to 10) of a number.
25. Write a program to sum seven terms of given series.

[Hint: use Math. Factorial(x) by import math]

26. When interest compounds q times per year at an annual rate of r % for n years, the principle p compounds to an amount
nq
a as per the following formula a = p ( 1 + r / q )
Write a program to read 10 sets of p, r, n & q and calculate the corresponding as.

27. The policy followed by a company to process customer orders is given by the following rules:
a. (a) If a customer order is less than or equal to that in stock and has credit is OK, supply has requirement.
b. (b) If has credit is not OK do not supply. Send him intimation.
c. (c) If has credit is Ok but the item in stock is less than has order, supply what is in stock. Intimate to him
data the balance will be shipped.
Write a C program to implement the company policy.

28. A university has the following rules for a student to qualify for a degree with A as
the main subject and B as the subsidiary subject:
a. (a) He should get 55 percent or more in A and 45 percent or more in B.
b. (b) If he gets than 55 percent in A he should get 55 percent or more in B.
However, he should get at least 45 percent in A.
c. (c) If he gets less than 45 percent in B and 65 percent or more in A he is
allowed to reappear in an examination in B to qualify.
d. (d) In all other cases he is declared to have failed.
Write a program to receive marks in A and B and Output whether the student has
passed, failed or is allowed to reappear in B.
29. An Insurance company follows following rules to calculate premium.
a. (1) If a person’s health is excellent and the person is between 25 and 35 years of age and lives in a city and is
a male then the premium is Rs. 4 per thousand and his policy amount cannot exceed Rs. 2 lakhs.
b. (2) If a person satisfies all the above conditions except that the sex is female then the premium is Rs. 3 per
thousand and her policy amount cannot exceed Rs. 1 lakh.
c. (3) If a person’s health is poor and the person is between 25 and 35 years of age and lives in a village and is
a male cannot exceed Rs. 10,000.
d. (4) In all other cases the person is not insured.
Write a program to output whether the person should be insured or not, his/her premium rate and maximum amount
for which he/she can be insured.

Session 3 & 4 Self Practice Assignments


30. Write a program that accepts a sentence and calculate the number of letters and digits.
Suppose the following input is supplied to the program:
hello world! 123
Then, the output should be:
LETTERS 10
DIGITS 3
31. Write a Python program to add 'ing' at the end of a given string (length should be at least 3). If the given string already ends with 'ing' then add 'ly'
instead. If the string length of the given string is less than 3, leave it unchanged.
Sample String : 'abc'
Expected Result : 'abcing'
Sample String : 'string'
Expected Result : 'stringly'
32. Write a Python function that takes a list of words and returns the length of the longest one.
33. Write a Python program to check if a string contains all letters of the alphabet.
34. Write a Python program to count the number of characters (character frequency) in a string.
35. Write a Python program to get a string made of the first 2 and the last 2 chars from a given a string. If the string length is less than 2, return instead of
the empty string.
36. Write a Python program to get a string from a given string where all occurrences of its first char have been changed to '$', except the first char itself.
37. Write a Python program to get a single string from two given strings, separated by a space and swap the first two characters of each string.

38. Write a Python program to find the first appearance of the substring 'not' and
'poor' from a given string, replace the whole 'not'...'poor' substring with 'good'.
Return the resulting string.
39. Write a Python program to remove the nth index character from a nonempty string.
40. Write a Python program to change a given string to a new string where the first and last chars have been exchanged.
41. Write a Python program to remove the characters which have odd index values of a given string.
42. Write a Python script that takes input from the user and displays that input back in upper and lower cases.

43. Write a Python program that accepts a comma separated sequence of words as
input and prints the unique words in sorted form (alphanumerically)
44. Write a Python function to get a string made of 4 copies of the last two characters of a specified string (length must be at least 2).
45. Write a Python function to convert a given string to all uppercase if it contains at least 2 uppercase characters in the first 4 characters.
46. Write a Python program to sort a string lexicographically.
47. Write a Python program to remove a newline in Python.
48. Given a string containing uppercase characters (A-Z), compress the string using Run Length encoding. Repetition of character has to be
replaced by storing the length of that run.
Write a python function which performs the run length encoding for a given String and returns the run length encoded String. Provide different
String values and test your Program.

Sample Input Expected Output

AAAABBBBCCCCCCCC 4A4B8C

AABCCA 2A1B2C1A

49. Write a program to count and display the number of capital letters in a given string.
.
50. Write a program to check if the given string is Palindrome or not?
.
51. Write a program to count the number of each vowel in a string

52. Write a program to remove all punctuation from the string provided by the user
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~''‘
53. Write a Python program to accept a string and display the resultant string in reverse order .
The resultant string should contain all characters at the even position of accepted string ignoring blank spaces.
Accepted string: Anappleadaykeepsthedoctoraway
Resultant string: Aapedyepteotrwy
Expected_output: ywrtoetpeydepaA
54. Given a string containing both upper and lower case letters. Write a Python program to count the number of repeated characters and
display the maximum count of a character along with the character.
Sample Input: ABaBCbGc
Output:
2A
3B (three times B is repeated)
2C
1G
55. Write a Python program to print the following floating numbers up to 2 decimal
places with a sign.
56. Write a Python program to print the following floating numbers with no decimal
places.
57. Write a Python program to print the following integers with zeros on the left of
specified width.
58. Write a Python program to print the following integers with '*' on the right of
specified width.
59. Write a Python program to strip a set of characters from a string
60. Write python program to count repeated characters in a string.

Session-7
61
62

63

64

65. Write a python program to generate Fibonacci series up to ‘n’ terms store it in list and display.

66. Implement a stack using list


67. Implement a queue using list

68. Cate Hospital wants to know the medical specialty visited by the maximum number of patients. Assume that the Patient id of
the patient along with the medical specialty visited by the patient is stored in a list. The details of the medical specialties are
stored in a dictionary as follows:

“P”:”Pediatrics”,

“O”:”Orthopedics”,

“E”:”ENT”
}

Write a function to find the medical specialty visited by the maximum number of patients and return the name of the
specialty.

Note: Assume that there is always only one medical specialty which is visited by maximum number of patients.

Sample Input Expected Output

[ 101, P, 102, O, 302, P, 305, P] Pediatrics

[ 101, O, 102, O, 302, P, 305, E, 401, O,656, O] Orthopedics

[ 101, P, 102, E, 302, P, 305, P, 401, E, 656, O, 987, E] ENT

Estimated Time: 40 Minutes

69. The Road Transport Corporation(RTC) of a city wants to know whether a particular bus- route is running on profit or loss. Assume that the following
information is given:
 Price per Litre of fuel = 70
 Mileage of the bus in km/litre of fuel = 10
 Price (Rs) per Ticket = 80

The bus runs on multiple routes having different distance in kms and number of passengers.

Write a Python program to calculate and return the profit earned(Rs) in each route. Return -1 in case of loss.

70. Write a python program to find all the Strong numbers among the given list of numbers. Write a function to find and return the
factorial of a number. Use it to solve the problem.

Example of Strong number:

N=145=1!+4!+5!=1+24+120=145

Hint: Sample list can be[145, 375, 100, 2, 10]

71. Write a python program to display all the duplicate values in a list.

Example :

Sample Input: [12, 54, 68, 759, 24, 15, 12, 68, 987, 758, 25, 69]

Expected Output: [12, 68]

Estimated Time: 40 Minutes

72. Given a list Integer vale, write a python program to check whether it contains same number in subsequent position. Display
the count of such occurrences.

Estimated Time: 30 Minutes

Sample Input Sample Output

[1, 1, 5, 100, 20, 20, 6, 0, 0] 3

[10, 20, 30, 40, 30, 20] 0

[1, 2, 2, 3, 4, 4,10] 2

73. The Metro Bank provides various types of loan such as car loans, Business loans and house loans to its
account holders. Write a python program to implement the following requirements:
 Initialize the following variables with appropriate input values: Account_Number, Account_balance,
salary, loan_type, Loan_amount_expected and Customer_emi_Expected.
 The Account number should be of 4 digits and its first digit should be 1.
 The customer should have a minimum balance of Rupees 1 lakh in the account.
 If the above rules are valid, determine the eligible loan amount and the EMI that the bank can provide to
its customer based on their salary and the loan type they expect to avail.
 The bank would provide the loan, only if the loan amount and the number of EMI’s requested by the
customer is less than or equal to the loan amount and the number of EMI’s decided by the bank
respectively.

Display appropriate error message for the invalid data. If all the business rules are satisfied, the display
account number, eligble and requested loan amount and EMI’s.
Test your code by providing different values for input variables.

Salary Loan Type Eligible loan amount No. of EMI’s Required to Repay
>25000 Car 500000 36
> 50000House 6000000 60
> 75000 Business 7500000 84

74. Write a python program to find the bill amount to be paid by the customer while ordering food online from a
restaurant. The bill amount includes the amount for the food ordered based on the quantity and delivery charge
based on distance of delivery as mentioned below:

The Restaurant , home delivers the vegetarian combo costing Rs. 120 per plate and the non-vegetarian Rs. 150 per
plate. Infact the restaurant gets more order for non- vegetarian combo than the vegetarian combo.

The Customer must specify the type of food, quantity (no. of paltes) required and the approximate distance in kms
from the restaurant to the delivery point.

The below information must be use to check the validity of data provided by the customer:

 Type of food must be ‘V’ for vegetarian and ‘N’ for non-Vegetarian.
 Distance in kms must be greater than 0.
 Quantity ordered should be minimum 1

Identify the cost of food and delivery charge based on the type of food and distance provided. Then the bill amount
must be calculated as give below:

Bill amount = cost per plate* quantity ordered+ Delivery charge

Use the information provided in the table below to calculte the delivery charge. The bill amount should be returned
as -1, if any of the inputs is invalid

Distance in kms. Delivery charge in Rs per km.

For first 3 kms 0

For next 3 kms 3

For the remaining 6

Note: Initialize type of food, quantity and distance in kms with different values and test your program.

75. Harley was booking flight tickets for the vacation trip. The ticket rates mentioned
were as follows for the round-trip:
Rate per Child : 1/3rd of the rate per adult
Service Tax: 7% of the ticket amount (including all passengers)
As it was a holiday season, the airline also offered 10% discount on the final ticket
cost (after inclusion of the service tax).
Harley booked the tickets for 2 adults and 3 children. Find and display the total ticket
cost of Harley.
Test the program with different input values for number of adults and children.

76. Write a python program to find and display the product of three positive integer values (taken as input in list) based
on the rule mentioned below:

It should display the product of the three values except when one of the integer value is 7. In that case, 7 should not be
included in the product and the values to its left also should not be included.

If there is only one value to be considered, display that value itself. If no values can be included in the product, display
-1.

Note: Assume that if 7 is one of the positive integer values, then it will occur only once. Refer the sample I/O given
below

Sample Input Expected Output

1, 5, 3 15
3, 7, 8 8

7, 4, 3 12

1, 5, 7 -1

77. Write a Python program which finds the maximum number from num1 to num2
(num2 inclusive) based on the following rules.:-
1. num1 should be less than num2
2. Consider each number from num1 & num2 and add number to list iff below
conditions are satisfied: -
a. Sum of digits of the number are multiple of 3
b. Number has only two digits
c. Number is multiple of 3
78. ARS gem store sells different variety of gems to customers. The dictionary of gems
and its price[gems as key and price as value] are given below:-
Gem Emerald Ivory Jasper Ruby
Price in Rs. 1760 2119 1599 3920 3999
Write a python program to calculate and display the bill amount to be paid by the
customer based on the list of gems(gem_list) and quantity purchased(qty_list).
Quantity purchased must be greater than 0. The customers are also entitled for
discount based on gems purchased. Refer the table below for discount provide. In
case more than one discount is applicable, the total discount % should be applied on
the total bill amount.
Gems Discount
Ivory 3%
Ruby 4%
Others 6%
In case of invalid values for any of quantity purchased or gems required display bill
amount=-1.
Initialize required gem_list and qty_list containing names of gems to be purchased
and required quantity of purchase for a customer and display the bill amount.
79. Consider the scenario of processing marks of students for a course in student
management system . Given below is the list of marks scored by students. Find top
three scorers for the course and also display average marks scored by all the
students.
80. Write a Python program to get the current date time
information.
81. Write a Python program to display formatted text output of a
month and start weeks on Sunday.
82. Write a Python program to convert a string into datetime
83. Write a Python program to implement Euclidean Algorithm
to compute the greatest common divisor (gcd).
Expected Output :
304 = 2 * 150 + 4
150 = 37 * 4 + 2
4=2*2+0
gcd is 2
6=2*3+0
gcd is 3
84. Write a Python program to read last n lines of a file.
85. Write a Python program to copy the contents of a file to
another file
86. Write a Python program that takes a text file as input and
returns the number of words of a given text file.
87. Write a Python program that reads a given expression and
evaluates it. Terms and conditions:
The expression consists of numerical values, operators and
parentheses, and the ends with '='.
The operators includes +, -, *, / where, represents, addition,
subtraction, multiplication and division.
When two operators have the same precedence, they are
applied to left to right.
You may assume that there is no division by zero.
All calculation is performed as integers, and after the
decimal point should be truncated Length of the expression
will not exceed 100.
-1 ? 10 9 = intermediate results of computation = 10 9
88. You are given a string S . It consists of alphanumeric characters, spaces and symbols(+,-).

Your task is to find all the substrings of S that contains or more vowels.
Also, these substrings must lie in between consonants and should contain vowels only.

You might also like