Python Quiz /5 Time is up!! Variables and Data Types 1 / 5 What will be the output of below code: Copy Code Copied Use a different Browser print(type(0x01)) a. int b. hex c. 01 d. number 2 / 5 What will be the output of below code: Copy Code Copied Use a different Browser var1=1 var2=2 var3=”3” print(var1+var2+var3) a. 33 b. 123 c. Error. Mixing operators between numbers and strings are not supported d. 6 ar1 and var2 are integer type whereas var3 is string type, can’t perform the addition operation in different data types 3 / 5 What will be the output of below code: Copy Code Copied Use a different Browser type(range(2)) a. range b. none c. int d. 0,1 4 / 5 What will be the output of below code: Copy Code Copied Use a different Browser print(type(10)) a. float b. none c. int d. integer 5 / 5 What will be the output of below code: Copy Code Copied Use a different Browser def myfunc(): x = 99 return x myfunc() print(x) a. NameError : name 'x' is not defined b. 0 c. 99 d. 1 Your score is The average score is 39% 0% Exit /5 Time is up!! Strings 1 / 5 Which method is used to convert string “welcome to the beautiful world” to “Welcome To The Beautiful World” a. title () b. capitalize () Explanation- title () is used to capitalize the first letter of each word of the string whereas capitalize () just makes the first letter of the full string as capital. 2 / 5 What will be the output of below code: Copy Code Copied Use a different Browser str = “my name is jack”; print (str.capitalize()) a. My Name Is Jack b. My name is jack c. TypeError:unsupported operand type(s) for * or pow(): ‘str’ and ‘int’ Explanation-capitalize () is used to make the first letter of the string as uppercase and rest all letters as lowercase. 3 / 5 What will be the output of below code: Copy Code Copied Use a different Browser str1 = “my isname isisis Jameis isis bond”; sub = ‘is’ print (str1.count(sub, 4) a. 7 b. 6 c. 5 Explanation-After indexing str1 as m=0, y=1, space=2, i=3, s=4, etc., str1.count(sub, 4) means counting the variable ‘sub’ in str1. The total number ‘is’ present in str1 is 7 but count(sub, 4), the 4 means start the counting with 4th index, therefore one ‘is’ gets reduced making it print 6. 4 / 5 What will be the output of below code: Copy Code Copied Use a different Browser str1 = “My salary is 7000”; str2 = “7000” print (str1.isdigit()) print (str2.isdigit()) a. False True b. False False c. True False Explanation-isdigit() is to check whether the given string is a digit. In the above expression, str1 is not digit as it contains spaces and letters therefore False and str2 is a digit making it print True. 5 / 5 What will be the output of below code: Copy Code Copied Use a different Browser print (“John” > “Jhon”) print (“Emma” < “Emm”) a. False False b. True False Explanation-While comparing “John” and “Jhon”, go letter by letter like J>J, o>h( which is true) as therefore the compiler won’t continue further and give the result as true. Similarly, for “Emma” and “Emm”, as there is no term to compare at the last letter, the compiler prints False. Your score is The average score is 68% 0% Exit /3 Time is up!! Input and Output 1 / 3 What will be the output of below code: Copy Code Copied Use a different Browser print (‘[%c]’ % 65) a. 65 b. [A] c. Syntax Error d. A Explanation-%c is an ASCII code, which gets replaced by A. %d is also an ASCII code, so print (‘[%d]’ % 65) would result in printing [65] i.e., %d is replaced by 65. 2 / 3 What will be the output of below code: Copy Code Copied Use a different Browser print (sep=’-- ‘, Ben’, ‘25’, California’) a. Ben 25 California b. Syntax Error c. Ben-25 California d. Ben-25-California Explanation-The correct format of print () statement is print (‘text’, sep= ‘ ‘, end= ‘ ‘) whereas the above expression contains ‘sep’ at the start of the print() statement. 3 / 3 In Python3, which functions are used to accept input from the user and whatever you enter in the function converts it into which data types? a. input () | string b. rawinput() | string c. raw_input() | int d. string () | string Explanation-input () function is used to take inputs. By using “string” any data type is converted to string data type. Your score is The average score is 50% 0% Exit /5 Time is up!! Operators 1 / 5 What will be the output of below code: Copy Code Copied Use a different Browser print (2%6) a. 0.33 b. ValueError c. 2 Explanation- 2 modules of 6 means dividing 2 by 6, and printing the remainder value. 2 / 5 What will be the output of below code: Copy Code Copied Use a different Browser print (36/4) a. 9 b. 9.0 Explanation- Division operators always return the float value. 3 / 5 What will be the output of below code: Copy Code Copied Use a different Browser print (2* 3 ** 3* 4) a. 864 b. 216 (**) operator has higher precedence than multiplication (*), making it (2 * 3^3 * 4)=(2 * 27 * 4)=216 4 / 5 What will be the output of below code: Copy Code Copied Use a different Browser print (10 - 4 *2) a. 2 b. 12 Explanation- multiplication (*) operator has higher precedence than minus (-) operator, means (10-4*2)=(10-8)=2 5 / 5 What will be the output of below code: Copy Code Copied Use a different Browser str1 = ‘Welcome’ print(str1*2) a. TypeError unsupported operand type(s) b. WelcomeWelcome Explanation-str1 value ‘Welcome’ will get printed twice. Your score is The average score is 94% 0% Exit /5 Time is up!! Loops 1 / 5 What will be the output of below code: Copy Code Copied Use a different Browser for num in range (2, -5, -1): print (num, end = “,”) a. 2, 1, 0, -1, -2, -3, -4, -5 b. 2, 1, 0 c. 2, 1, 0, -1, -2, -3, -4 Explanation- ‘For’ loop starts with 2 as mentioned in the given expression and goes till -5, excluding the last position having -1 of spacing, resulting in 2,1,0, -1, -2, -3, -4 and excluding -5 as that’s the end point of range. 2 / 5 What will be the output of below code: Copy Code Copied Use a different Browser for x in range (0.5, 5.5, 0.5): print(x) a. [0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5] b. [0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5] c. The program executed with errors Explanation-In the 'for' loop having a range, the range should only contain integer data type values, any other data type values will result in error. 3 / 5 Given the nested if-else below, what will be the value x when the code executed successfully Copy Code Copied Use a different Browser x = 0 a = 5 b = 5 if a > 0: if b < 0: x = x + 5 elif a > 5: x = x + 4 else: x = x + 3 else: x = x + 2 print(x) a. 2 b. 3 c. 0 d. 4 Explanation- The initial value of a = 5, which is greater than 0, then enters inside the if loop. if b < 0 - b (having value of 5) is not less than 0, therefore doesn’t get inside the second if loop. elif a > 5 – 5 is not less than 5, therefore doesn’t enter in the elif loop too. else – enters in this loop, therefore the value of x becomes 3. 4 / 5 What will be the output of below code: Copy Code Copied Use a different Browser for num in range (10, 14): for i in range (2, num): if num% i ==1: print(num) break a. 11 13 b. 10 11 12 13 Explanation-Break statement is used to come out of the loop and follow the loop immediately after coming out of loop 5 / 5 What will be the output of below code: Copy Code Copied Use a different Browser for i in range (10,15,1): print (i, end=’,’) a. 10, 11, 12, 13, 14, 15, b. 10, 11, 12, 13, 14, Explanation-For loop with range 10 to 15 having 1 spacing means 10, 11, 12, 13, 14 as the end point is excluded in ‘for’ loop. Your score is The average score is 46% 0% Exit /5 Time is up!! Functions 1 / 5 What will be the output of below code: Copy Code Copied Use a different Browser def add (a, b): return a+5, b+5 result = add (3, 2) print(result) a. Syntax Error b. (8,7) c. 8 d. 15 Explanation- Can return multiple values from a function. 2 / 5 What will be the output of below code: Copy Code Copied Use a different Browser def calculate (num1, num2=4): res = num1*num2 print(res) calculate (5,6) a. 30 b. The program executed with errors c. 20 Explanation –As we need to calculate (5,6), therefore the values become num1=5 and num2=6, putting the values in res=num1*num2 results in 5*6 =30. 3 / 5 What will be the correct function declaration of func1() so that we can execute the following function call successfully Copy Code Copied Use a different Browser fun1(25,75, 55) fun1(10, 20) a. No, it is not possible in Python b. def fun1(args*) c. def fun1(**kwargs) d. def fun1(*data) Explanation- To accept multiple values, we can add * before the parameter name to accept arguments 4 / 5 Please select the correct expression to reassign a global variable “x” to 20 inside a function fun1()? Copy Code Copied Use a different Browser x=50 def fun1(): #your code to assign global x=20 fun1() print(x) #it should print 20 a. global var x x=20 b. global x x=20 c. global.x = 20 d. global x=20 Explanation-To define a global variable that is used anywhere throughout the program and can be placed inside or outside the function, write global and the variable name (for example: global x) and then assign the value to x which will be assigned to variable x throughout. 5 / 5 What will be the output of below code: Copy Code Copied Use a different Browser def func1(): x = 50 Return x func1() print(x) a. NameError b. 50 c. None d. 0 Explanation- As name 'Return' is not defined Your score is The average score is 35% 0% Exit