Praclist Xi Python19-20
Praclist Xi Python19-20
2. WAP to find the simple interest if principal, rate and time are given
3. Write a program to find the sum of first three multiples of a given number n
4. Write a program to read your name, age and class and display message as -
Welcome <name>
I am <age> years old and studying in class <class>
Last year I was <n> years old.
5. WAP to find the denomination of currency in Re 1,2,5,10,50,100,500 and 1000 in a given amount
entered by user.
6. WAP to make a simple calculator that reads two numbers and an operator. On selection of an
operator, perform operation and print the result as shown below-
Enter first number: 5
Enter second number: 7
Enter operator: *
Result: 5 * 7 = 35
7. A farm has chickens and rabbits. Farm owner counts number of heads and legs and wishes to find
out number of chickens and rabbits? Write a program to solve this classic ancient Chinese puzzle.If
farm owner counts 35 heads and 94 legs. Calculate and print how many rabbits and chickens he
has?
8. You are driving a little too fast and the police officer stops you and issues a ticket. Write code to
compute the result, encoded as an integer value: 0=no ticket, 1=small ticket, 2=big ticket.
If speed is 60 or less, the result is 0. If speed is between 61 and 80 inclusive, the result is 1. If
speed is 81 or more, the result is 2. Unless it is your birthday, on that day, your speed can be 5
higher in all cases.WAP to model above scenario.
1
Sample output
Input units: 150
Charges Rs. 115 [calculated as (100*.4 + 50*.50 +50)]
10. WAP that reads n digit number. After reading the number, compute and display the sum of the odd
positioned digits, multiply all even positioned digits and add these two numbers.
11. Write a program which will find all such numbers which are divisible by 7 but are not multiple of
5, between 2000 and 3200 (both included).
The numbers obtained should be printed in a comma-separated sequence on a single line.
12. Develop a program to classify students amongst various categories as per their age entered. Read
age of N students and count no of students falling in each category as described below print a
report as follows –
Group A: 12 yrs and above but less than 15 yrs - XX
Group B: 15 yrs and above but less than 17 yrs - XX
Group C: 17 yrs and above but less than 19 yrs - XX
Group D: Lesser than 12 yrs - XX
13. Every book published by an international publisher should carry an International standard book
Number(ISBN).It is 10 character 4 part number as shown below:-
0-07-041183-2
The first part denotes the region, the second represents the publisher, the third identifies the
book and fourth is the digit. The check digit is computed as follows:-
Sum=(1*first digit)+(2*second digit)+(3*third digit)+……(9*ninth digit)
Check digit is the remainder when sum is divided by 11. Write a program that reads a given
ISBN number and checks whether it represents a valid ISBN.
14. Write a program to find if a number entered is a palindrome or not.
15. A very famous numerical algorithm exists to find out the highest common factor (also called the
greatest common divisor) of two numbers. The algorithm was invented by Euclid; it is therefore
called the Euclid’s algorithm.
Here is how the algorithm works. Say you wish to find out the HCF of two numbers A and B.
Simply repeat the following steps until both numbers become equal:
If A is greater than B, change A to A-B and do not modify B
If B is greater than A, change B to B-A and do not modify A
The value of A (and B) when both become equal will be the Highest Common Factor!
Let’s try this out with two numbers, A=18 and B=42.
B is greater than A, so B becomes 24 and A remains as 18. So, we have:
A = 18, B = 24
If we repeat this process, we get:
A = 18, B = 6 A = 12, B = 6 A = 6, B = 6
Finally, both A and B become equal (both have value 6). The HCF of 18 and 42 is 6.
2
16. According to a study, the approximate level of Intelligence of a person can be calculated using the following
formula:
i=2(y+0.5x)
Write program, which will produce a table of values of i,y and xwhere y varies from 1 to 6 and for each
value of y , x varies from 5.5 to 12.5 in steps of 0.5.
17. Write a program to play the "Guess the number"-game, where the number to be guessed is
randomly chosen between 1 and 20. This is how program should work when executed
(Only three chances allowed)
Hello! What is your name?
Tanuj
Well, Tanuj, I have chosen of a number between 1 and 20.
Take a guess.
10
Your guess is too low.
Take a guess.
15
Your guess is too low.
Take a guess.
18
Good job, Tanuj! You guessed my number in 3 guesses!
21. Read two strings and check if string1 is prefix, postfix or nothing from the string2.
(Use remodule)
ForEg-
string1: ever
string2: evergreen
Output: prefix
22. Write a program to read a string and print
i)Frequency of all charactersii) Word of highest length
iii) The string in title caseiv) Read full name as a string and print only the initials.
3
Eg-
Enter name: Mohan Das Karam Chand Gandhi
Output string M D K C Gandhi.
23. Data can be represented in memory in different ways Binary, Decimal, Octal, and Hexadecimal.
Input number in decimal and desired type(Specify B for Binary O for Octal, H for Hexadecimal)
for output.
24. In Cryptography, a Caesar cipher is a very simple encryption techniques in which each letter in the
plain text is replaced by a letter some fixed number of positions down the alphabet list in a cyclic
manner. For example, with a shift of 3, A would be replaced by D, B would become E, and so on.
The method is named after Julius Caesar, who used it to communicate with his generals. ROT-13
("rotate by 13 places").
Create menu driven program to encrypt and decrypt which takes in a string and rotation (rotate by n
places) and encrypts the string then decrypts the string. The program should be menu driven. Also if
rotationis not specified then the encryption should take place by 13.
25. Write a program that takes a list of numbers prints a histogram to the screen.
****
*********
*******
Take a list of numbers and find frequency of each number and plots a histogram as shown
above.
26. Consider the following algorithm to generate a sequence of numbers and store them into a list.
Start with an integer n. If n is even, divide by 2. If n is odd, multiply by 3 and add 1. Repeat this
process with the new value of n, terminating when n = 1.
For example, the following sequence of numbers will be generated for n = 22:
22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
Now do the following on above created list-
a. Printtotal number of elements in the list
b. Delete all occurrences of multiples of 10 and printit .
4
27. Write a program to sort a given list of numbers and print the total number of operations taking
place while sorting the given list using
i) Bubble Sort
ii) Insertion Sort
28. Write a program which takes 2 digits, X, Y as input and generates a 2-dimensional array. The
element value in thei-th row and j-th column of the array should be i*j.
Note: i=0,1.., X-1; j=0,1,¡Y-1.
Example
Suppose the following inputs are given to the program:
3,5
Then, the output of the program should be:
[[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]]
29. Write a program to generate a random 6 digit secure OTP. The digits should not repeat.
30. Given below two dictionaries:
relatives ={"Lisa" : "daughter", "Bart" : "son", "Marge" : "mother","Homer" :
"father", "Santa" : "dog"}
ages = {“Lisa” : 8, “Bart”:10,”Marge”:35,”Homer”:40,”Santa”:2}
Write a code that combines the two dictionaries to generate the following output:
The Simpsons:
Homer is a father and is 40 years old
Lisa is a daughter and is 8 years old
Bart is a son and is 10 years old
Santa is a dog and is 2 years old
Marge is a mother and is 35 years old
31. Write a program that takes a list of words and creates a dictionary with word as the key andnumber
of occurrences of the word asthe value.
For example if list is given as ['the','of','an','is','an','the']
Then the dictionary should be d={'the':2,'of':1,'an':2,'is':1}
32. Write a program that takes a list of words and creates a dictionary with frequency (no of
occurrences) of word as key and list of words for that frequency as value.
For example if list is given as ['the','of','an','is','an','the']
Then dictionary should be {2:['the','an'],1:['of','is']}
32. Write a program to create a dictionary of names of flowers as keys and the colours in which
theyexist as values in tuples, for example D={'rose':('red','black','pink'),'lily':('white','violet')} .
Now write a code to print
a) The flower which exists in maximum number of colors
b) The colour in which most of the flowers exist
5
33. There are 36 possible combinations, if we throw two dice. A simple pair of loops over range (6) +1
will enumerate all combinations. The sum of the two dice is more interesting than the actual
combination. Create a dictionary of all combinations, using the sum of numbers on the two dice as the
key. Each value of dictionary will be a tuple with all possible combination.
I)Display title of all books with price between 100 and 300
Ii)Display title and author of all the books having type “Prog” and published by BPB.
iii) Display number of books and average price for each type of publisher
Iv) Display title, price in descending order of price
V) Display all the books where title starts with “D” and qty is more than 3.
Vi)Display publisher wise total stock value (Qty * price)
6
Table : Order1
Orderno Orderdate CName Cloc Orders(inRs) Payments(inRs)
Q.3. Given below a table FAMILY. Write SQL queries for the following:
TABLE: FAMILY
Family_name Female_Members Male_Members Income Occupation
RELATION: CONSIGNEE
CneeID CnorID CneeName CneeAddress CneeCity
MU05 ND01 Rahul Kishore 5, Park Avenue Mumbai
ND08 ND02 P. Dhingra 16/J, Moore Enclave New Delhi
KO10 MU15 A P Roy 2A, Central Avenue Kolkata
MU32 ND02 S. Mittal P 245, AB Colony Mumbai
ND48 MU50 B P Jain 13, Block D, A Vihar New Delhi
Q.5Create the tables Doctor and Patient by choosing the appropriate data types for all attributes. Insert the
shown records in these tables and write the required queries for 1-5
TABLE : DOCTOR
Doc_no Name Department Cons_fee
D1 Dr. Garg Cardiology 500
D3 Dr. Rakesh Jain Pediatric 250
D4 Dr. Ajay Kumar Physician 150
D6 Dr. Seema Patil Cardiology 450
D9 Dr. AbhaVerma Pediatric 300
TABLE : PATIENT
pno Name Dt_birth Doc_no
P2 Suraj 12-11-1969 D1
P4 Feroj 23-2-1980 D6
P5 Jai Prakash 3-10-1990 D4
P7 Anshul 1-6-2005 D3
P9 Zarina 4-9-2004 D9
1. List department wise number of doctors in the department along with their average
consultation fee.
2. List the name of doctors who are taking consultation fee more than the average
consultationfee.
3. List Doctor Name along with the name of patient they are treating.
4. Name the youngest patient.
5. Display patient name and their age as on today.
8
9