0% found this document useful (0 votes)
306 views2 pages

7 - DBMS Python Questions

The document contains 10 questions asking to write Python programs that take inputs from text files and perform various computations and formatting on the inputs to produce specific outputs as described. The questions involve tasks like sorting and formatting names and numbers, encoding identifiers, retrieving values from databases, and more.

Uploaded by

aditya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
306 views2 pages

7 - DBMS Python Questions

The document contains 10 questions asking to write Python programs that take inputs from text files and perform various computations and formatting on the inputs to produce specific outputs as described. The questions involve tasks like sorting and formatting names and numbers, encoding identifiers, retrieving values from databases, and more.

Uploaded by

aditya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 2

1.

write a Python program to print the names of the players and the team of each
player of all those players whose jersey number is a prime number. The list should
be ordered in reverse alphabetical order of player names. If two or more players
have the same name, then further sorting should be done on the team name, again
in reverse alphabetical order.The format of output is as given below: Name of the
player, followed by a comma (,), then a space and then the team name. For
example, if Arjun has jersey number 5 and is playing for All Stars and Pranav, with
jersey number 7, is playing for team Amigos, then the output will be:
Pranav, Amigos
Arjun, All Stars

2. write a Python program to print an encoding of the ids of the teams whose jersey
colour at home is different from the jersey colour when they play away from home.
The encoding must be using a shift cipher, which is detailed below.An alphabet is
mapped to another alphabet as follows. For a given alphabet α, let pos be the
position at which α occurs in the alphabet listing (A at 1, B at 2, …. Z at 26). Then
the encoding of α is the alphabet at the position (pos + 7) mod 26. For example, if
M is the alphabet, then the position at which M occurs in the alphabet listing is 13.
Then, the encoding of M is the alphabet at the position (13 + 7) mod 26 = 20, which
is T. For each digit β, the encoding of β is (β+7) mod 10. For example, if 3 is the
digit, then the encoding of 3 is the number (3 + 7) mod 10 = 0. The ids should be
listed in the ascending order before performing the encoding. Each line in the
output of the program must correspond to one row retrieved from the table.

3. Write a Python program to output the jersey number of the player. Player's name is
given in a file named 'player.txt' resides in the same folder as python program file.
The output of the python program is only jersey number.
For example, if the jersey number of the player is 99. Then output must be 99 only.
Note: No spaces.

4. Write a Python program to print the roll number of the student. Student's first name is
given in a file named 'name.txt' resides in the same folder as python program file.
The output of the python program is only roll number.
For example, if the first name of the student is 'Vikas'. Then output must be CS01 only.
Note: No spaces.

5. write a Python program to print the playground of the given team id. team_id is
given in a file named 'team.txt' resides in the same folder as python program file.
• The output of the python program is only playground name.
• For example, if the team_id is 'T0002' . Then output must be Villa Park only

6. Write a Python program to print the student's first name, the corresponding
department name and the respective year of date of birth, if the year is even then
print "Even" or else "Odd". Student's first name is given in a file named 'name.txt'
resides in the same folder as python program file.The output of the python
program is only student's first name, the corresponding department name and year
of date of birth, if the year is even then "Even" or else "Odd". For example, 'Suman'
and 'Computer Science' is the name and department name of the student. '2002' is
the year he was born in. '2002' is even. Then, the final output will be
Suman,Computer Science,Even only. Note: No spaces. For example, 'Vinod' and
'Electrical Engineering' is the name and department name of the student. '2003' is
the year he was born in. '2003' is not even. Then, the final output will be
Vinod,Electrical Engineering,Odd only. Note: No spaces.
7. write a Python program to output the name of the main referee for a given match
date (in yyyy-mm-dd format). The input to your program is a file named “date.txt”
that has the match date as the first word of the file. Your program must assume
that date.txt resides in the same folder as your Python program. The output name
has to be formatted as follows. The last name is displayed followed by the initials
of the first name, then a full stop, a space and then the initials of the middle name
(if the middle name exists), followed by a full stop.For example, if the name of the
main referee is “Kennedy Sapam”, the output must be ”Sapam K.” If the name of
the main referee is “Asit Kumar Sarkar”, the output must be ”Sarkar A. K.”

8. write a Python program to find the cosine of a number obtained from performing
a computation on a value retrieved from the database. Find the sum of scores of
all host teams satisfying the following conditions. host_team_score >
guest_team_score name of the host team starts with the character given in the
input file ‘parameter.txt’. You have to read the character from the file and use it in
your query to retrieve the expected sum. Your program must assume that
parameter.txt resides in the same folder as your Python program. Let this sum be
denoted by ‘S’. Compute X = S * 10. Assuming that X is a value in radians, convert
it into degrees. That is, let X_deg = X * (pi/180). Then, using the math library in
Python, find cos(X_deg) correct up to two decimal places, where cos denotes the
mathematical trigonometric function cosine. For example, if the sum of scores of
all host teams satisfying the given conditions is 5, then the output is
round(cos(5*10*(pi/180)),2).

9. Write a Python program to print the ISBN numbers of books which are published
in a given year. Here, the year is obtained as the value of function L(x) (given after
the sample output) at x. You have to read the value of x from the input file
"number.txt", and use it to find the value of L(x). Your program must assume that
the file number.txt resides in the same folder as your Python program. You have
to iterate through the list and print each value separately as shown in the output
below:
9789352921171 9789351343202 9789353333380
The line function is given below: L4(x) = 2000 + 4*x + 4

10. write a Python program to output the name of the main referee for a given match
date (in yyyy-mm-dd format). The input to your program is a file named “date.txt”
that has the match date as the first word of the file. Your program must assume
that date.txt resides in the same folder as your Python program. The output name
has to be formatted as follows. The last name is displayed followed by the initials
of the first name, then a full stop, a space and then the initials of the middle name
(if the middle name exists), followed by a full stop. For example, if the name of the
main referee is “Kennedy Sapam”, the output must be ”Sapam K.” If the name of
the main referee is “Asit Kumar Sarkar”, the output must be ”Sarkar A. K.”

You might also like