Python Assignment Answers
Python Assignment Answers
ANSWER: b. 162.89
Q2. In a given string format operation, how will you print the given string. A =
10
B = 20
Str = "There are {} students in the class, with {} who play at least one sport."
a. print(string.format(a,b))
b. print(string+a+b)
c. print(string.format(b,a))
d. None of the above
Q3. In a given sample string, How do you print a double quoted string in between a regular
string using the escape character?
Sample output = It goes without saying, “Time is Money”, and none can deny it.
a. print(“It goes without saying, \“Time is Money\”, and none can deny it.”)
b. print(“It goes without saying, \Time is Money\, and none can deny it.”)
c. print(“It goes without saying” + “Time is Money” + “and none can deny it.”)
d. None of the above.
ANSWER: a. print("It goes without saying, \"Time is Money\", and none can deny it.")
ANSWER: b. 3
ANSWER: c. Greater
a. [2 7 3 5 4 6]
b. TypeError
c. NameError: name 'numpy' is not defined
d. None of the above
Q7. Create a string called ‘string’ with the value as “Machine Learning”. Which code(s) is/are
appropriate to slice the substring “Learn”?
a. string[slice(13,8,1)]
b. string[slice(1,8,1)]
c. string[8:14]
d. string[slice(8,13,1)]
ANSWER: d. string[slice(8,13,1)]
Q8. Create a sequence of numbers from 10 to 25 and increment by 4. What is the index of the
value 18?
a. 3
b. 2
c. 0
d. 1
ANSWER: b. 2
Q9. Which of the following is true with respect to the below codes?
a. num1 = num2
b. num1 ≠ num2
c. num1 < num2
d. num1 > num2
ANSWER: a. num1 = num2
Q11.What type of exception will be raised for the code given below?
a. NameError
b. KeyError
c. ValueError
d. AttributeError
ANSWER: c. ValueError
ANSWER: b. A file or directory is requested but does not exist in the working directory
ANSWER: b. Character
Q14.Which of the following variable(s) are character data type? a.
K= “4”
b. J= “Welcome”
c. L= “?”
d. All of the above
ANSWER: d. #
Q16.Create a dictionary ‘Country’ that maps the following countries to their capitals
respectively:
Country India China Japan Qatar France
State Delhi Beijing Tokyo Doha Marseilles
a. sum(tuple_1)
b. len(tuple_2)
c. tuple_2 + tuple_1
d. tuple_1[3] = 45
Q19.Write a function which finds all pythagorean triplets of triangles whose sides are no greater
than a natural number N.