PPS Practice Ques
PPS Practice Ques
Solution:
9. a. Multiply the two numbers where you take the input from user and then
print the result. b. Calculate the age in months.
Solution
Video links :
Question 1:
In this question use the print() function to print the line Hello, Python! to the screen.
• Yes single quote in place of the double quotes and run your code. Watch Python's reaction.
• Remove single quote. Watch Python's reaction.What kind of error is thrown?
• Then, remove the parentheses, put back the single quotes, and run your code again. What kind
of error is thrown this time?
• Use multiple print() functions on the same line, and then on di erent lines. See what
happens.
Question 2:
Write a one-line piece of code which give this output:
"I'm"
""learning""
“""Python"""
Question 3:
Question 4:
Find the length of the hypotenuse (i.e., the longest side of a right-angled triangle, the one
opposite of the right angle) using the Pythagorean theorem. Take the value of 2 sides through
user.
Question 5:
What do you think is the output of 8.0//5+4*9%(3+1)/6-1**2**3?
Question 6:
Modify the rst line of code in the editor, using the sep and end keywords, to match the expected
output. Use the two print() functions in the editor.
Input
fi
ff
print("Programming","Essentials","in")
print(“Python")
Expected output
Programming***Essentials***in…Python
Question 7:
Write a python program to find and display the area of a circle. Use the formula given for finding
the area of circle.
area=3.14*radius*radius
Question 8:
Miles and kilometers are units of length or distance.
Bearing in mind that 1 mile is equal to approximately 1.61 kilometers, complete the program in the
editor so that it converts:
• miles to kilometers;
• kilometers to miles.
Question 9
We strongly encourage you to play with the code we've written for you, and make some (maybe
even destructive) amendments. Feel free to modify any part of the code, but there is one
condition ‒ learn from your mistakes and draw your own conclusions.
Try to:
• minimize the number of print() function invocations by inserting the \n sequence into
the strings;
• make the arrow twice as large (but keep the proportions)
• duplicate the arrow, placing both arrows side by side; note: a string may be multiplied by
using the following trick: "string" * 2 will produce "stringstring" (we'll tell
you more about it soon)
• remove any of the quotes, and look carefully at Python's response; pay attention to where
Python sees an error ‒ is this the place where the error really exists?
• do the same with some of the parentheses;
• change any of the print words into something else, di ering only in case (e.g., Print) ‒
what happens now?
print(" *")
print(" * *")
print(" * *")
print(" * *")
print("*** ***")
print(" * *")
print(" * *")
print(" *****")
ff
Practice set 3
3. Write a program to convert an Upper case character into lower case and vice-versa.
5. Scenario
Spathiphyllum, more commonly known as a peace lily or white sail plant, is one of
the most popular indoor houseplants that filters out harmful toxins from the air. Some
of the toxins that it neutralizes include benzene, formaldehyde, and ammonia.
Imagine that your computer program loves these plants. Whenever it receives an
input in the form of the word Spathiphyllum, it involuntarily shouts to the console
the following string: "Spathiphyllum is the best plant ever!”
Write a program that utilizes the concept of conditional execution, takes a string as
input, and:
Test your code using the data we've provided for you. And get yourself a
Spathiphyllum, too!
Test Data:
Sample input:
spathiphyllum
Expected output:
No, I want a big Spathiphyllum!
Sample input:
pelargonium
Expected output:
Spathiphyllum! Not pelargonium!
Sample input:
Spathiphyllum
Expected output:
Yes - Spathiphyllum is the best plant ever!
6. Scenario
As you surely know, due to some astronomical reasons, years may be leap or
common. The former are 366 days long, while the latter are 365 days long.
Since the introduction of the Gregorian calendar (in 1582), the following rule is used
to determine the kind of year:
• if the year number isn't divisible by four, it's a common year;
• otherwise, if the year number isn't divisible by 100, it's a leap year;
• otherwise, if the year number isn't divisible by 400, it's a common year;
• otherwise, it's a leap year.
Look at the code in the editor – it only reads a year number, and needs to be
completed with the instructions implementing the test we've just described.
The code should output one of two possible messages, which are Leap year or
Common year, depending on the value entered.
It would be good to verify if the entered year falls into the Gregorian era, and output
a warning otherwise: Not within the Gregorian calendar period. Tip: use the != and
% operators.
Test your code using the data we've provided.
Test Data:
Sample input:
2000
Expected output:
Leap year
Sample input:
2015
Expected output:
Common year
Sample input:
1999
Expected output:
Common year
Sample input:
1996
Expected output:
Leap year
Sample input:
1580
Expected output:
Not within the Gregorian calendar period
8. Scenario
Pooja would like to withdraw X rs from an atm.The cash machine will only
transaction:
Helpfull Videos: