You are on page 1of 2

Practice Set 2

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:

Find out the type of data:


6,”Welcome”,True,8.0

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

You might also like