Questions
ayuda
option
My Daypo

ERASED TEST, YOU MAY BE INTERESTED ONpython basic

COMMENTS STATISTICS RECORDS
TAKE THE TEST
Title of test:
python basic

Description:
python basic test

Author:
AVATAR
Smart Tech Juinor
(Other tests from this author)


Creation Date:
09/04/2021

Category:
Others

Number of questions: 36
Share the Test:
Facebook
Twitter
Whatsapp
Share the Test:
Facebook
Twitter
Whatsapp
Last comments
No comments about this test.
Content:
Consider the following expression result=8//6%5+2**3-2 print(result) What is the result? 8 9 7 6.
Consider the code s='AB CD' list=list(s) list.append('EF') print(list) What is the result? ['A','B','C','D','E','F'] {'A','B',' ','C','D','EF'} ['A','B','C','D','EF'] ['A','B',' ','C','D','EF'] ('A','B',' ','C','D','EF').
You are writing a Python program to read two int values from the keyboard and print the sum. x=input('Enter First Number:') y=input('Enter Second Number:') #Line-1 Which of the following code we have to write at Line-1 to print the sum of given numbers? print('The Result:'+str(int(x+y))) print('The Result:'+(int(x)+int(y))) print('The Result:'+str(int(x)+int(y))) print('The Result:'+(int(x+y))).
Consider the code a=2 a += 1 # Line-1 To make a value as 9,which expression required to place at Line-1 a**=2 a*=2 a+=2 a-=2.
Consider the following code segments: # Code Segment-1 a1='10' b1=3 c1=a1*b1 # Code Segment-2 a2=10 b2=3 c2=a2/b2 # Code Segment-3 a3=2.6 b3=1 c3=a3/b3 After executing Code Segments 1,2 and 3 the result types of c1,c2 and c3 are: c1 is of str type,c2 is of int type ,c3 is of int type c1 is of str type,c2 is of float type ,c3 is of float type c1 is of str type,c2 is of int type ,c3 is of float type c1 is of str type,c2 is of str type ,c3 is of str type.
Consider the code a=15 b=5 print(a/b) What is the result ? 3 3.0 0.0 0.
Consider the following lists: n1=[10,20,30,40,50] n2=[10,20,30,40,50] print(n1 is n2) print(n1 == n2) n1=n2 print(n1 is n2) print(n1 == n2) What is the result? False True False True False True True True False False True True True False True False.
Consider the following code x= 'Larry' y= 'Larry' result=condition print(result) For which of the following condition True will be printed to the console? x is not y x < y x != y x is y .
Consider the list list=['Apple','Banana','Carrot','Mango'] Which of the following are valid ways of accessing 'Mango': list[4] list[3] list[0] list[-1].
You have the following code: a=bool([False]) b=bool(3) c=bool("") d=bool(' ') Which of the variables will represent False: d a c b.
Which of the following is valid python operator precedence order? Parenthesis Exponents Unary Positive, Negative and Not Addition and Subtraction Multiplication and Division Parenthesis Exponents Unary Positive, Negative and Not Multiplication and Division Addition and Subtraction Exponents Unary Positive, Negative and Not Multiplication and Division Addition and Subtraction And Parenthesis Exponents Parenthesis Unary Positive, Negative and Not Multiplication and Division Addition and Subtraction.
You are developing a python application for your company. A list named employees contains 500 employee names. In which cases, we will get IndexError while accessing employee names? None of the above employees[-1] employees[0] employees[500] .
Consider the code: x= 8 y= 10 result= x//3*3/2+y%2**2 print(result) What is the result? 6.0 7.0 5.0 5.
Consider the expression: result=a-b*c+d Which of the following are valid? First, b*c will be evaluated followed by subtraction and addition First, b*c will be evaluated followed by addition and subtraction The above expression is equivalent to a-(b*c)+d First, a-b will be evaluated followed by multiplication and addition.
Consider the python code a=1 b=3 c=5 d=7 In Which of the following cases, the result value is 0? result = a-b//d result = a+b*2 result = a**d-1 result = a%b-1 .
You are writing a Python program. You required to handle data types properly. Consider the code segment: a=10+20 b='10'+'20' c='10'*3 Identify the types of a,b and c? a is of int type,b and c are invalid declarations a is of int type,b is of str type, and c is of int type a is of int type,b is of int type, and c is of int type a is of int type,b is of str type, and c is of str type.
Consider the code try: print('try') print(10/0) except: print('except') else: print('else') finally: print('finally') What is the result? try except else finally try else finally try except finally try finally.
Consider the code : try: print('try') print(10/0) else: print('else') except: print('except') finally: print('finally') What is the Result? try else except finally try else finally try except finally SyntaxError: invalid syntax.
Consider the code: f=open('abc.txt') print(f.read()) f.close() We required to add exception handling code to handle FileNotFoundError.Which of the following is an appropriate code for this requirement? f=None try: f=open('abc.txt') except FileNotFoundError: print('Fild does not exist') else: print(f.read()) finally: if f != None: f.close() f=None try: f=open('abc.txt') except FileNotFoundException: print('Fild does not exist') else: print(f.read()) finally: if f != None: f.close() f=None try: f=open('abc.txt') else: print(f.read()) except FileNotFoundException: print('Fild does not exist') finally: if f != None: f.close() Answer :f=None try: f=open('abc.txt') except FileNotFoundError: print('Fild does not exist') else: print(f.read()) finally: if f != None: f.close().
Consider the code a=10 b=20 c='30' result=a+b+c What is the result? 102030 3030 TypeError ArithmeticError.
Consider the code: prices=[30.5,'40.5',10.5] total=0 for price in prices: total += price print(total) While executing this code we are getting the following error Traceback (most recent call last): File "test.py", line 4, in <module> total += price TypeError: unsupported operand type(s) for +=: 'float' and 'str' Which of the following code should be used to fix this error? total += str(price) total += int(price) total += float(price) total = total+price.
Consider the code courses={1:'Java',2:'Scala',3:'Python'} for i in range(1,5): print(courses[i]) While executing this code we are getting the following error Traceback (most recent call last): File "test.py", line 3, in <module> print(courses[i]) KeyError: 4 By using which of the following code segments we can fix this problem ? courses={1:'Java',2:'Scala',3:'Python'} for i in range(1,5): if i in courses: print(courses[i]) courses={1:'Java',2:'Scala',3:'Python'} for i in courses: print(courses[i]) courses={1:'Java',2:'Scala',3:'Python'} for i in range(1,4): print(courses[i]) All of these.
Consider the code def area(b,w): return B*w print(area(10,20)) What is the result? NameError will be raised at runtime AttributeError will be raised at runtime IdentationError will be raised at runtime 200.
Consider the following code: def get_score(total=0,valid=0): result=int(valid)/int(total) return result For which of the function calls we will get Error? score=get_score(40,4) score=get_score('40','4') score=get_score(40) score=get_score(0,10) .
Consider the code: data=[] def get_data(): for i in range(1,5): marks=input('Enter Marks:') data.append(marks) def get_avg(): sum=0 for mark in data: sum += mark return sum/len(data) get_data() print(get_avg()) For the input: 10,20,30,40 what is the result? 25 25.0 NameError is thrown at runtime TypeError is thrown at runtime.
Consider the code: a=10 b=0 try: print(a/b) Which of the following except block print the name of exception which is raised,i.e exception class name? there are two options select any one except ZeroDivisionError as e: print('Exception Type:',e.__class__.__name__) except ZeroDivisionError as e: print('Exception Type:',type(e).__name__) except ZeroDivisionError as e: print('Exception Type:',e) All of these.
Consider the Code x=int(input('Enter First Number:')) y=int(input('Enter Second Number:')) try: print(x/y) Which of the following is valid except block that handles both ZeroDivisionError and ValueError except(ZeroDivisionError,ValueError) from e: print(e) except(ZeroDivisionError,ValueError) as e: print(e) except(ZeroDivisionError | ValueError) as e: print(e) except(ZeroDivisionError, ValueError as e): print(e).
You develop a python application for your school. You need to read and write data to a text file. If the file does not exist, it must be created. If the file has the content, the content must be removed. Which code we have to use? open('abc.txt','r') open('abc.txt','r+') open('abc.txt','w+') open('abc.txt','w').
We are creating a function that reads a data file and prints each line of that file. Consider the following code: import os def read_file(file): line=None if os.path.isfile(file): data=open(file,'r') while line != '': line=data.readline() print(line) The code attempts to read the file even if the file does not exist.You need to correct the code. which lines having indentation problems? First 3 Lines inside the function Last 3 Lines inside the function Last 2 Lines inside the function There is no indentation problem.
Consider the code: import sys try: file_in=open('in.txt','r') file_out=open('out.txt','w+') except IOError: print('cannot open',file_name) else: i=1 for line in file_in: print(line.rstrip()) file_out.write(str(i)+":"+line) i=i+1 file_in.close() file_out.close() Assume that in.txt file is available, but out.txt file does not exist. Which of the following is true about this code? This program will copy data from in.txt to out.txt The code runs but generates a logical error The code will generates a runtime error The code will generates a syntax error.
Consider the file abc.txt has the following content:Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum We have to write python code to read total data and print to the console. try: f=open('abc.txt','r') //Line-1 except: print('Unable to open the file') print(data) Which code should be inserted at Line-1 to meet the given requirement ? data=f.read() data=f.readline() data=f.readlines() data=f.load().
To write 'Python Certificaton' to abc.txt file, which of the following is valid code? f=open('abc.txt','b') f.write('Python Certificaton') f.close() f=open('abc.txt','r') f.write('Python Certificaton') f.close() f=open('abc.txt') f.write('Python Certificaton') f.close() f=open('abc.txt','w') f.write('Python Certificaton') f.close().
Consider the data present in the file: abc.txt Cloudera,50,60,70,80,90 MICROSOFT,10,20,30,40,50 Which of the following is valid code to read total data from the file? with open('abc.txt','r') f: data=f.read() with open('abc.txt') as f: data=f.read() with open('abc.txt','w') as f: data=f.read() with open('abc.txt') as f: data=f.readline().
Assume that we are writing python code for some voting application.You need to open the file voters_list.txt and add new voters info and print total data to the console? with open('voters_list.txt','a+') as f: f.write('New voters info') #Line-1 data=f.read() print(data) Which Line should be inserted at Line-1 ? f.seek(0) f.flush() f.begin() f.close().
You are creating a function that manipulates a number.The function has the following requirements:A float passed to the functionThe function must take absolute value of the floatAny decimal points after the integer must be removed.Which two math functions should be used? there are two options select any one math.floor(x) math.fabs(x) math.fmod(x) math.frexp(x) math.ceil(x).
Consider the following code. import os def get_data(filename,mode): if os.path.isfile(filename): with open(filename,'r') as file: return file.readline() else: return None Which of the following are valid about this code? This function returns the first line of the file if it is available This function returns None if the file does not exist This function returns total data present in the file This function returns the last line of the file.
Report abuse Consent Terms of use