Python Questions
Python Questions
Operator
The two numbers between which the operator is applied
All the results will be correct, except for these few:
45 * 3 = 555
56+9 = 77
56/6 = 4
14. "Number Guessing Game," in which a winning number is set to some
integer value. The Program should take input from the user, and if the
entered number is less than the winning number, a message should
display that the number is smaller and vice versa.
Instructions:
1. You are free to use anything we've studied till now.
2. The number of guesses should be limited, i.e (5 or 9).
3. Print the number of guesses left.
4. Print the number of guesses he took to win the game.
5. “Game Over” message should display if the number of guesses
becomes equal to 0.
*
**
***
****
You have to follow certain instructions, which are as follows:
You have to take an integer type variable, and the input of the variable
will define the length of the triangle.
You have to declare another Boolean variable.
When the value of Boolean is 1 i.e. True, the pattern will be printed as
shown above.
But if the value of Boolean is 0 or false, then the triangle will be printed
upside down.
16. The task is to create a "Health Management System." Suppose you
are a fitness trainer and nutritionist. You have to deal with three clients,
i.e., (Harry, Rohan, Hammad). For each client, you have to design their
exercise and diet plan.
Instructions:
Create a food log file for each client
Create an exercise log file for each client.
Ask the user whether they want to log or retrieve client data.
Write a function that takes the user input of the client's name. After the
client's name is entered, it will display a message as "What you want to
log- Diet or Exercise".
Use function
def getdate():
import datetime
return datetime.datetime.now()
The purpose of this function is to give time with every record of food or
exercise added in the file.
Write a function to retrieve exercise or food file records for any client.
17. Assume that a programmer works at the office from 9am-5 pm. We
have to take care of his health and remind him three things,
To drink a total of 3.5-liter water after some time interval between 9-5
pm.
To do eye exercise after every 30 minutes.
To perform physical activity after every 45 minutes.
Instructions:
The task is to create a program that plays mp3 audio until the
programmer enters the input which implies that he has done the task.
Challenge:
You will have to manage the clashes between the reminders such that no
two reminders play at the same time.
Use pygame module to play audio
18. The task is to create an “Online Library Management System”. For
this, you have to create a library class that includes the following
methods:
HarryLibrary=Library(listofbooks, library_name)
After that, create a main function and run an infinite while loop that asks
the users for their input that whether they want to display, lend, add or
return a book.
Optional:-
Maintain a dictionary for the users who own a book. Dictionary should
take book name as a key and name of the person as a value. Whenever
you lend a book to a user, you should maintain a dictionary
19. The task you have to perform is "Oh Soldier, Prettify my Folder."
Suppose you have a folder, and its path is also given. You have to create a
function that takes three input arguments, which are:
First, it will check all the files present in the folder whose paths are given
as an input argument.
Then it will capitalize the first letter of each file. If the file's name is
present in a dictionary file, then it will not capitalize the first letter. It will
only capitalize the first letter of the files, which are not present in the
dictionary file.
The function renames the file names to numbers in the range of 1 to100
whose format is the same as mentioned in the input parameter like 1.jpg.
20. When you go to a website and click on the contact section, by
pressing CTRL+A, all the website's content gets added to the clipboard.
Paste the data in your python file or in a string. Extract an email from the
above data, and after extracting the email, write it into a file with a new
line character. Your text file after writing data should look similar to this:
abc123@gmail.com
cdf456@gmail.com
21. Take age or year of birth as an input from the user. Store the input in
one variable. Your program should detect whether the entered input is
age or year of birth and tell the user when they will turn 100 years old. (5
points).
Do not use any type of module like DateTime or date utils. (-5 points)
Users can optionally provide a year, and your program must tell their age
in that particular year. (3points)
Your code should handle all sorts of errors like : (2 points)
You are not yet born
You seem to be the oldest person alive
You can also handle any other errors, if possible!
22. Harry Potter has got the “n” number of apples. Harry has some
students among whom he wants to distribute the apples. These “n”
number of apples is provided to harry by his friends, and he can request
for few more or few less apples.
Input:
Take input n, mn, and mx from the user.
Output:
Print whether the numbers between mn and mx are divisor of “n” or not.
If mn=mx, show that this is not a range, and mn is equal to mx. Show the
result for that number.
Example:
If n is 20 and mn=2 and mx=5
2 is a divisor of20
3 is not a divisor of 20
…
5 is a divisor of 20
23. You visited a restaurant called CodeWithHarry, and the food items in
that restaurant are sorted, based on their amount of calories. You have to
reserve this list of food items containing calories.
You have to use the following three methods to reserve a list:
Inbuild method of python
List name [::-1] slicing trick
Swap the first element with the last one and second element with second
last one and so on like,
[6 7 8 34 5] -> [5 34 8 7 6]
Input:
Take a list as an input from the user
[5, 4, 1]
Output:
[1, 4, 5]
[1, 4, 5]
[1, 4, 5]
You have to take a number as an input from the user. You have to find
the next palindrome corresponding to that number. Your first input
should be the number of test cases and then take all the cases as input
from the user.
Input:
3
451
10
2133
Output:
Next palindrome for 451 is 454
Next palindrome for 10 is 11
Next palindrome for 2311 is 2222
26. You are given a list that contains some numbers. You have to print a
list of the next palindromes only if the number is greater than 10;
otherwise, you will print that number.
Input:
[1, 6, 87, 43]
Output:
[1, 6, 88, 44]
27. Generate a random integer from a to b. You and your friend have to
guess a number between two numbers, a and b. a and b are inputs taken
from the user. Your friend is player 1 and plays first. He will have to keep
choosing the number, and your program must tell whether the number is
greater than the actual number or less than the actual number. Log the
number of trials it took your friend to arrive at the number. You play the
same game, and then the person with the minimum number of trials
wins! Randomly generate a number after taking a and b as input and
don’t show that to the user.
Input:
Enter the value of a
4
Enter the value of b
13
Output:
Player1 :
Please guess the number between 4 and 13
5
Wrong guess a greater number again
8
Wrong guess a smaller number again
6
Correct, you took 3 trials to guess the number
Player 2:
Correct, you took 7 trials to guess the number
Player 1 wins!
28. You are given few sentences as a list (Python list of sentences). Take a
query string as an input from the user. You have to pull out the sentences
matching this query inputted by the user in decreasing order of relevance
after converting every word in the query and the sentence to lowercase.
The most relevant sentence is the one with the maximum number of
matching words with the query.
Sentences = [“Python is cool”, “python is good”, “python is not python
snake”]
Input:
Please input your query string
“Python is”
Output:
3 results found:
python is not python snake
python is good
Python is cool
Your function should be able to find out the wrong values in Rohan’s
table and expose Rohan Das as a fraud.
30. It's result day at school and not everyone is happy. You decided to
make your friends laugh by jumbling their names to come up with some
funny names.
Your program should take the number of names and the names
separated by space as input. Output should be funny names in the same
order.
Input:
Enter number of friends:
Rohan Das
Shubham Agarwal
Ritesh Arora
Output:
Ritesh Das
Shubham Arora
Rohan Agarwal