173 solutions available
Question 1Boolean data type is internally treated as integer data type.
Question 2Two forms of floating-point numbers are: fractional form and exponent notation.
Question 3Python's floating point numbers have precision of 15 digits.
Question 4Three mutable types of Python are lists, dictionaries and sets.
Question 5The floor division of two integers yields a result of integer type.
Question 6The division of two integers yields a result of floating-point type.
Question 7The set sequence type cannot store duplicate values.
Question 8The tuple datatype is like lists but is not mutable.
Question 9The id of an object gives the memory location of the object.
Question 10To check if two objects reference the same memory address, is operator is used.
Question 11To use function fabs( ), math module should be imported.
Question 12To generate a random floating number in the range 0 to 100, random() or random.random() function is used.
Question 13To generate a random integer in a range, randint() or random.randint() function is used.
Question 14To generate a random number in a sequence of values where two values have a difference a step value, randrange() or random.randrange()...
Question 15To use mean() function, statistics module is to be imported.
Question 1Which of the following are valid Python data types ?NumericNone ✓Mappingslist ✓Sequenceset ✓tuple ✓dictionary ✓
Question 2Which of the following are datatypes considered as Numbers in Python.Integer ✓Boolean ✓complex ✓floating point ✓listNone
Question 3Consider the following sequence of statements:a = 35m = aFollowing the execution of these statements, Python has created how many objects...
Question 4Which Python built-in function returns the unique number assigned to an object?identity( )id( ) ✓refnum( )ref( )
Question 5The operator used to check if both the operands reference the same object memory, is the .......... operator.inis ✓id==
Question 6For two objects x and y, the expression x is y will yield True, if and only ifid(x) == id(y) ✓len(x) == len(y)x == yall of these
Question 7Which of the following is not an immutable type in Python ?StringTuplesSet ✓dictionary ✓
Question 8Python operator always yields the result of .......... datatype.integerfloating point ✓complexall of these
Question 9What is the value of the expression 100 / 25 ?44.0 ✓2.5none of these
Question 10What is the value of the expression 100 // 25 ?4 ✓4.02.5none of these
Question 11In Python, a variable must be declared before it is assigned a value.TrueFalse ✓Only in FunctionsOnly in modules
Question 12In Python, a variable is assigned a value of one type, and then later assigned a value of a different type. This will yield .............
Question 13In Python, a variable may be assigned a value of one type, and then later assigned a value of a different type. This concept is known as...
Question 14Is it safe to directly use the == operator to determine whether objects of type float are equal ?YesNo ✓Yes, if the values are <...
Question 15What will the following code produce ?a = 8.6 b = 2 print ( a//b )4.34.0 ✓4compilation error
Question 16In the Python statement x = a + 5 - b : a and b are .......... .Operands ✓ExpressionoperatorsEquation
Question 17In the Python statement x =a + 5 - b : a + 5 - b is .......... .OperandsExpression ✓operatorsEquation
Question 18What will be the value of y after following code fragment is executed ?x = 10.0 y = (x < 100.0) and x >= 10110True ✓FalseError.
Question 19Which of the following literals has True truth-value ?0.000001 ✓'None' ✓0[ ]FalseTrue ✓1 ✓33 ✓None0.0
Question 20What will the following code result as ?import math x = 100 print ( x > 0 and math.sqrt( x ) )True11010.0 ✓
Question 21Which of the following operators has the lowest precedence ?not%and ✓+**
Question 22What is the value of the expression 10 + 3 ** 3 * 2?2873982964 ✓
Question 23To increase the value of x five times using an augmented assignment operator, the correct expression will bex += 5x *= 5 ✓x = x ** 5none...
Question 24What will be the result of the expression 10 or 0 ?0110 ✓1.0
Question 25What will be the result of the expression 5 or 10 ?5 ✓1100
Question 26What will be the result of the expression 5 and 10?5110 ✓0
Question 27What will be the result of the expression 15 and 10?5110 ✓0
Question 28What will be the result of the expression 10 or 0 ?0110 ✓1.0
Question 29What will be the result of the expression 'a' or " (" is an empty string) ?'a' ✓"10
Question 30What will be the result of the expression 'a' and " (" is an empty string) ?'a'" ✓10
Question 31What will be the result of the expression 'x' and 'a' ?'a' ✓"'x'1
Question 32What will be the result of the expression 'a' and 'x' ?'a''''x' ✓1
Question 33What will be the result of the expression 'a' and 'None' ?'a''''None' ✓1
Question 34What will be the result of the expression 'None' and 'a' ?'a' ✓'''None'1
Question 35What will be the result of the expression 'false' and False ?falseFalse ✓'false''False'
Question 36What will be the result of the expression 'false' or False ?falseFalse'false' ✓'False'
Question 1List is an immutable data type.False
Question 2Set is a mutable data type.True
Question 3A set can contain duplicate values in it.False
Question 4A Boolean value is internally treated as an integer value.True
Question 5'' (an empty string) has truth value as False.True
Question 6' ' (a space) has truth value as False.False
Question 7Value false is a legal literal value in Python.False
Question 8Value False is a legal literal value in Python.True
Question 9Value 'False' is a legal literal value in Python.True
Question 10Value 'false' is a legal literal value in Python.True
Question 11None and 'None' are the same.False
Question 12None has the truth value as False.True
Question 13'None' has the truth value as False.False
Question 14The result of bool(0) is False.True
Question 15The result of bool('None') is False.False
Question 16Dividing two integers results in an integer.False
Question 17Floor division of two integers results in an integer.True
Question 18Two floating point numbers should not be compared for equality using ==True
Question 19In implicit conversion, all operands' data types are converted to the datatype of the largest operand.True
Question 20Explicit type conversion involves the use of a function to convert datatype of a value.True
Question 1What are data types in Python? How are they important?AnswerData types are used to identify the type of data a memory location can hold and...
Question 2How many integer types are supported by Python? Name them.AnswerTwo integer types are supported by Python. They are:Integers...
Question 3How are these numbers different from one another (with respect to Python)? 33, 33.0, 33j, 33 + jAnswerThe number 33 is an integer whereas...
Question 4The complex numbers have two parts : real and imaginary. In which data type are real and imaginary parts represented ?AnswerIn Python, the...
Question 5How many string types does Python support? How are they different from one another?AnswerPython supports two types of strings — Single-line...
Question 6What will following code print?str1 = '''Hell o''' str2 = '''Hell\ o''' print(len(str1) > len(str2))AnswerThis code will print:True...
Question 7What are Immutable and Mutable types in Python? List immutable and mutable types of Python.AnswerMutable types are those whose values can...
Question 8What are three internal key-attributes of a value-variable in Python ? Explain with example.AnswerThe three internal key-attributes of a...
Question 9Is it true that if two objects return True for is operator, they will also return True for == operator?AnswerYes, if is operator returns...
Question 10Are these values equal? Why/why not?20 and 20.020 and int(20)str(20) and str(20.0)'a' and "a"AnswerThe type of 20 is int whereas the type...
Question 11What is an atom in Python? What is an expression?AnswerIn Python, an atom is something that has a value. Identifiers, literals, strings,...
Question 12What is the difference between implicit type conversion and explicit type conversion?AnswerImplicit Type ConversionExplicit Type...
Question 13Two objects (say a and b) when compared using == ,return True. But Python gives False when compared using is operator. Why? (i.e., a == b...
Question 14Given str1 = "Hello", what will be the values of:(a) str1[0](b) str1[1](c) str1[-5](d) str1[-4](e) str1[5]Answer(a) H(b) e(c) H(d) e(e)...
Question 15If you give the following for str1 = "Hello", why does Python report error?str1[2] = 'p'AnswerPython reports error because strings are...
Question 16What will the result given by the following?(a) type (6 + 3)(b) type (6 -3)(c) type (6 *3)(d) type (6 / 3)(e) type (6 // 3)(f) type (6 %...
Question 17What are augmented assignment operators? How are they useful?AnswerAugmented assignment operators combine the impact of an arithmetic...
Question 18Differentiate between (555/222)**2 and (555.0/222)**2.AnswerIn the first expression, 555 is of int type whereas in the second expression...
Question 19Given three Boolean variables a, b, c as : a = False, b = True, c = False. Evaluate the following Boolean expressions:(a) b and c(b) b or...
Question 20What would following code fragments result in? Given x = 3.(a) 1 < x(b) x >= 4(c) x == 3(d) x == 3.0(e) "Hello" == "Hello"(f)...
Question 21Write following expressions in Python:(a) 13b2h\dfrac{1}{3} b^2 h31b2hAnswer1 / 3 * b * b * h(b) πr2h\pi r^2 hπr2hAnswermath.pi * r * r *...
Question 22int('a') produces error. Why ?Answerint() converts its argument into an integer. As 'a' is a letter, it cannot be converted into a valid...
Question 23int('a') produces error but following expression having int('a') in it, does not return error. Why?len('a') + 2 or int('a')AnswerThe or...
Question 24Write expression to convert the values 17, len('ab') to (i) integer (ii) str (iii) boolean valuesAnswer(i) int(17), int(len('ab'))(ii)...
Question 25Evaluate and Justify:(i) 22 / 17 = 37 / 47 + 88 /83(ii) len('375')**2Answer(i) It produces an error as LHS value in this case is an...
Question 26Evaluate and Justify:(i) 22.0/7.0 - 22/7(ii) 22.0/7.0 - int(22.0/7.0)(iii) 22/7 - int (22.0)/7Answer(i) 22.0/7.0 - 22/7 ⇒ 0As values of...
Question 27Evaluate and Justify:(i) false and None(ii) 0 and None(iii) True and None(iv) None and NoneAnswer(i) This produces an error as false is an...
Question 28Evaluate and Justify:(a) 0 or None and "or"(b) 1 or None and 'a' or 'b'(c) False and 23(d) 23 and False(e) not (1 == 1 and 0 != 1)(f)...
Question 29Evaluate the following for each expression that is successfully evaluated, determine its value and type for unsuccessful expression, state...
Question 30Write an expression that uses exactly 3 arithmetic operators with integer literals and produces result as 99.Answer9 * 10 + 21 % 12
Question 31Add parentheses to the following expression to make the order of evaluation more clear.y % 4 == 0 and y % 100 != 0 or y % 400 ==...
Question 32A program runs to completion but gives an incorrect result. What type of error would have caused it?AnswerLogical errors can make a...
Question 33In Python, strings are immutable while lists are mutable. What is the difference?AnswerIn Python, strings are immutable means that...
Question 34How does the // operator differ from the / operator? Give an example of where // would be needed.AnswerThe Division operator (/) divides...
Question 35MidAir Airlines will only allow carry-on bags that are no more than 22 inches long, 14 inches wide, and 9 inches deep. Assuming that...
Question 36What are main error types? Which types are most dangerous and why?AnswerThe types of errors are:Compile Time Errors (Syntax errors and...
Question 37Correct any false statements:(a) Compile-time errors are usually easier to detect and to correct than run-time errors.(b) Logically errors...
Question 38Differentiate between a syntax error and a semantics error.AnswerSyntax ErrorSemantics ErrorSyntax errors occurs when the rules of the...
Question 39Differentiate between a syntax error and a logical error in a python program. When is each type of error likely to be found?AnswerSyntax...
Question 40What is the difference between an error and exception?AnswerAn Error is a bug in the code that causes irregular output or stops the...
Question 1What is the result produced by (i) bool (0) (ii) bool (str(0))? Justify the outcome.Answer(i) bool (0)The result is False as truth value of...
Question 2What will be the output, if input for both the statements is 5 + 4/2.6 == input ("Value 1:")6 == int(input ("value 2:"))AnswerOutput of...
Question 3Following Python code has an expression with all integer values. Why is the result in floating point form?a, b, c = 2, 3, 6 d = a + b * c/b...
Question 4aWhat will following code print?a = va = 3 b = va = 3 print (a, b)AnswerThis Python code prints:3 3
Question 4bWhat will following code print?a = 3 b = 3.0 print (a == b) print (a is b)AnswerThis Python code prints:True False As values of a and b...
Question 5aWhat will be output produced by following code? State reason for this output.a, b, c = 1, 1, 2 d = a + b e = 1.0 f = 1.0 g = 2.0 h = e + f...
Question 5bWhat will be output produced by following code? State reason for this output.a = 5 - 4 - 3 b = 3**2**3 print(a) print(b)...
Question 5cWhat will be output produced by following code? State reason for this output.a, b, c = 1, 1, 1 d = 0.3 e=a+b+c-d f=a+b+c == d print(e)...
Question 6aWhat will be the output of following Python code?a = 12 b = 7.4 c = 1 a -= b print(a, b) a *= 2 + c print(a) b += a * c...
Question 6bWhat will be the output of following Python code?x, y = 4, 8 z = x/y*y print(z)AnswerOutput4.0 Explanation z = x/y*y⇒ z = 4/8*8⇒ z =...
Question 7Make change in the expression for z of previous question so that the output produced is zero. You cannot change the operators and order of...
Question 8Consider the following expression:x = "and" * (3 + 2) > "or" + "4"What is the data type of value that is computed by this...
Question 9Consider the following code segment:a = input() b = int(input()) c = a + b print(c)When the program is run, the user first enters 10 and...
Question 10Consider the following code segment:a = input("Enter the value of a:") b = input("Enter the value of b:") print(a + b)If the user runs the...
Question 11Find out the error and the reason for the error in the following code. Also, give the corrected code.a, b = "5.0", "10.0" x = float(a/b)...
Question 12Consider the following program. It is supposed to compute the hypotenuse of a right triangle after the user enters the lengths of the...
Question 13Consider the following program. It is supposed to compute the hypotenuse of a right triangle after the user enters the lengths of the...
Question 14Which of the following expressions will result in an error message being displayed when a program containing it is run?(a) 2.0/4(b) "3" +...
Question 15aFollowing expression does not report an error even if it has a sub-expression with 'divide by zero' problem:3 or 10/0What changes can you...
Question 15bWhat is the output produced by following code?a, b = bool(0), bool(0.0) c, d = str(0), str(0.0) print (len(a), len(b)) print (len(c),...
Question 16Given a string s = "12345". Can you write an expression that gives sum of all the digits shown inside the string s i.e., the program...
Question 17Predict the output if e is given input as 'True':a = True b = 0 < 5 print (a == b) print (a is b) c = str (a) d = str (b) print (c ==...
Question 18aFind the errors(s)name = "HariT" print (name) name[2] = 'R' print (name) AnswerThe line name[2] = 'R' is trying to assign the letter...
Question 18bFind the errors(s)a = bool (0) b = bool (1) print (a == false) print (b == true)Answerfalse and true are invalid literals in Python....
Question 18cFind the errors(s)print (type (int("123"))) print (type (int("Hello"))) print (type (str("123.0")))AnswerIn the line print (type...
Question 18dFind the errors(s)pi = 3.14 print (type (pi)) print (type ("3.14")) print (type (float ("3.14"))) print (type (float("three point...
Question 18eFind the errors(s)print ("Hello" + 2) print ("Hello" + "2") print ("Hello" * 2) AnswerThe line print ("Hello" + 2) causes an error as...
Question 18fFind the errors(s)print ("Hello"/2) print ("Hello" / 2)AnswerBoth the lines of this Python code will give an error as strings cannot be...
Question 19aWhat will be the output produced?x, y, z = True, False, False a = x or (y and z) b = (x or y) and z print(a,...
Question 19bWhat will be the output produced?x, y = '5', 2 z = x + y print(z)AnswerThis code produces an error in the line z = x + y as operands of...
Question 19cWhat will be the output produced?s = 'Sipo' s1 = s + '2' s2 = s * 2 print(s1) print(s2)AnswerOutputSipo2 SipoSipo Explanations1 = s...
Question 19dWhat will be the output produced?w, x, y, z = True , 4, -6, 2 result = -(x + z) < y or x ** z < 10 print(result)AnswerOutputFalse...
Question 20Program is giving a weird result of "0.50.50.50.50.50.50..........". Correct it so that it produces the correct result which is the...
Question 21Consider the code given below:import random r = random.randrange(100, 999, 5) print(r, end = ' ') r = random.randrange(100, 999, 5)...
Question 22Consider the code given below:import random r = random.randint(10, 100) - 10 print(r, end = ' ') r = random.randint(10, 100) - 10 print(r,...
Question 23Consider the code given below:import random r = random.random() * 10 print(r, end = ' ') r = random. random() * 10 print(r, end = ' ') r =...
Question 24Consider the code given below:import statistics as st v = [7, 8, 8, 11, 7, 7] m1 = st.mean(v) m2 = st.mode(v) m3 = st.median(v) print(m1,...
Question 1Write a program to obtain principal amount, rate of interest and time from user and compute simple interest.Solutionp = float(input("Enter...
Question 2Write a program to obtain temperatures of 7 days (Monday, Tuesday ... Sunday) and then display average temperature of the week.Solutiond1 =...
Question 3Write a program to obtain x, y, z from user and calculate expression : 4x4 + 3y3 + 9z + 6πSolutionimport math x = int(input("Enter x: "))...
Question 4Write a program that reads a number of seconds and prints it in form : mins and seconds, e.g., 200 seconds are printed as 3 mins and 20...
Question 5Write a program to take year as input and check if it is a leap year or not.Solutiony = int(input("Enter year to check: ")) print(y % 4 and...
Question 6Write a program to take two numbers and print if the first number is fully divisible by second number or not.Solutionx = int(input("Enter...
Question 7Write a program to take a 2-digit number and then print the reversed number. That is, if the input given is 25, the program should print...
Question 8Try writing program (similar to previous one) for three digit number i.e., if you input 123, the program should print 321.Solutionx =...
Question 9Write a program to take two inputs for day, month and then calculate which day of the year, the given date is. For simplicity, take 30 days...
Question 10Write a program that asks a user for a number of years, and then prints out the number of days, hours, minutes, and seconds in that number...
Question 11Write a program that inputs an age and print age after 10 years as shown below:What is your age? 17In ten years, you will be 27 years...
Question 12Write a program whose three sample runs are shown below:Sample Run 1:Random number between 0 and 5 (A) : 2Random number between 0 and 5...
Question 13Write a program that generates six random numbers in a sequence created with (start, stop, step). Then print the mean, median and mode of...
Question 14Write a program to generate 3 random integers between 100 and 999 which is divisible by 5.Solutionimport random a = random.randrange(100,...
Question 15Write a program to generate 6 digit random secure OTP between 100000 to 999999.Solutionimport random otp = random.randint(100000,...
Question 16Write a program to generate 6 random numbers and then print their mean, median and mode.Solutionimport random import statistics a =...
Question 17Write a program to find a side of a right angled triangle whose two sides and an angle is given.Solutionimport math a =...
Question 18Write a program to calculate the radius of a sphere whose area (4πr2) is given.Solutionimport math area = float(input("Enter area of...
Question 19Write a program that inputs a string and then prints it equal to number of times its length, e.g.,Enter string : "eka"Result...
Question 20Find the volume of the cylinder (πr2h) as shown:Radius = 8 cmHeight = 15 cmSolutionimport math r = 8 h = 15 v = math.pi * r * r * h...
Question 21Write a program to calculate the area of an equilateral triangle. (area = (√3 / 4) * side * side).Solutionimport math side =...
Question 22Write a program to input the radius of a sphere and calculate its volume (V = 4/3πr3)Solutionimport math r = float(input("Enter radius of...
Question 23Write a program to calculate amount payable after simple interest.Solutionp = float(input("Enter principal: ")) r = float(input("Enter...
Question 24Write a program to calculate amount payable after compound interest.Solutionp = float(input("Enter principal: ")) r = float(input("Enter...
Question 25Write a program to compute (a + b)3 using the formula a3 + b3 + 3a2b + 3ab2Solutiona = int(input("Enter a: ")) b = int(input("Enter b: "))...