Questions
ayuda
option
My Daypo

ERASED TEST, YOU MAY BE INTERESTED ONpython basic 5

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

Description:
python basic test

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


Creation Date:
27/04/2021

Category:
Others

Number of questions: 18
Share the Test:
Facebook
Twitter
Whatsapp
Share the Test:
Facebook
Twitter
Whatsapp
Last comments
No comments about this test.
Content:
You created the following program to locate a conference room and display room name. rooms={1:'Left Conference Room',2:'Right Conference Room'} room=input('Enter the room number:') if not room in rooms:#Line-3 print('Room does not exist') else: print('The room name is:'+rooms[room]) The team reported that the program sometimes produces incorrect results. You need to troubleshoot the program. Why does Line-3 Fail to find the rooms? Invalid Syntax Mismatched data type(s) Misnamed variable(s) None of these.
If the book is returned after 9 PM, the student will be charged an extra day. If the Book is rented on a Sunday, the student will get 50% off for as long as they keep the book. If the Book is rented on a Saturday, the student will get 30% off for as long as they keep the book. We need to write the code to meet these requirements. # XYZ Book Rented Amount Calculator ontime=input('Was Book returned before 9 pm? y or n:').lower() days_rented=int(input('How many days was book rented?')) day_rented=input('What day the Book rented?').capitalize() cost_per_day=3.00 if ontime == 'n': days_rented=days_rented+1 if day_rented=='Sunday': total=(days_rented*cost_per_day)*0.5 elif day_rented=='Saturday': total=(days_rented*cost_per_day)*0.7 else: total=(days_rented*cost_per_day) print('The Cost of Book Rental is:$',total) If the Book rented on 'Sunday', the number of days Book rented is 5 and Book returned after 9 PM, then what is the result? The Cost of Book Rental is:$ 7.0 The Cost of Book Rental is:$ 8.0 The Cost of Book Rental is:$ 9.0 The Cost of Book Rental is:$ 10.0.
You work for a company that distributes media for all ages. You are writing a function that assigns a rating based on a user's age. The function must meet the following requirements. Anyone 18 years old or older receives a rating of "A" Anyone 13 or older,but younger than 18, receives a rating of "T" Anyone 12 years old or younger receives a rating of "C" If the age is unknown ,the rating is set to "C" Which of the following code meets above requirements: def get_rating(age): if age>=18: rating="A" elif age>=13: rating="T" else: rating="C" return rating def get_rating(age): if age>=18: rating="A" if age>=13: rating="T" else: rating="C" return rating def get_rating(age): if age>18: rating="A" elif age>13: rating="T" else: rating="C" return rating def get_rating(age): if age>=18: rating="A" elif age>=13: rating="T" else: rating="C" pass rating.
Which of the following is False? A try statement can have one or more except clauses A try statement can have a finally clause without an except clause A try statement can have a finally clause and an except clause A try statement can have one or more finally clauses.
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? there are two answer select anyone...! 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.
We are writing a Python program for the following requirements: Each line of the file must be read and printed if the blank line encountered, it must be ignored when all lines have been read, the file must be closed. Consider the code: inventory=open('inventory.txt','r') eof=False while eof == False: line=inventory.readline() if XXX: if YYY: print(line,end='') else: print('End of file') eof=True inventory.close() Which of the following changes are required to perform to meet the requirements XXX should be replaced with line != '' YYY should be replaced with line!= ' ' XXX should be replaced with the line!= ' ' YYY should be replaced with the line != '' XXX should be replaced with the line != '' YYY should be replaced with the line != '' XXX should be replaced with the line!= ' ' YYY should be replaced with the line!= ' '.
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(filename): line=None if os.path.isfile(file_name): data=open(filename,'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 identation problems? First 3 Lines inside the function Last 3 Lines inside a function Last 2 Lines inside the function There is no indentation problem.
Consider the code: import sys try: file_in=open('file1.txt','r') file_out=open('file2.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 generate a runtime error The code will generate a syntax error.
You are creating a function that manipulates a number. The function has the following requirements: A float passed to the function must take the absolute value of the float. Any decimal points after the integer must be removed. Which two math functions should be used? there are two options select anyone...! math.frexp(x) math.floor(x) math.fabs(x) math.fmod(x) math.ceil(x).
You are writing code that generates a random integer with a minimum value of 18 and a maximum value of 32. Which of the following 2 functions did we require to use? there are two options select any two random.randint(18,33) random.randint(18,32) random.randrange(18,33,1) random.randrange(5,11,1).
Consider the following expression result=(2*(3+4)**2-(3**3)*3) What is result value? 17 16 18 19.
We are creating a function to calculate the addition of two numbers by using python. We have to ensure that the function is documented with comments. Consider the code(Line numbers included for reference): 01 # The calc_square function calculates exponents 02 # x is a first number 03 # y is a second number 04 # The value of x and y is added and returned 05 def calc_power(x, y): 06 comment="#Return the value" 07 return x + y # Adding x and y Which of the following statements are true? Lines 01 through 04 will be ignored for syntax checking The hash sign(#) is optional for lines 01 and 03 The String in line 06 will be interpreted as a comment.
Which of the following is True about else block? else block will be executed if there is no exception in try block Without writing except block we cannot write else block For the same try, we can write at most one else block All the above .
x='TEXT'which line of the code will assign 'TT' to the output? output=x[0]+x[-1] output=x[1]+x[1] output=x[0]+x[2] output=x[1]+x[4].
Consider the code : from sys import argv sum=0 for i in range(2,len(argv)): sum += float(argv[i]) print("The Average for {0} is {1:.2f}".format(argv[1],sum/(len(argv)-2))) Which of the following command invocations will generate the output:The Average for Test is 20.00 py test.py Test 10 py test.py Test 10 20 30 py test.py Test 10 20 py test.py 20.
Consider the Python code: a=['a','b','c','d'] for i in a: a.append(i.upper()) print(a) What is the result? ['a','b','c','d'] ['A','B','C','D'] MemoryError thrown at runtime SyntaxError.
Consider the python code: result=str(bool(1) + float(10)/float(2)) print(result) What is the output? 6.0 6 SyntaxError TypeError.
If the user enters 12345 as input, Which of the following code will not print 12346 to the console? count=input('Enter count value:') print(count+1) count=int(input('Enter count value:')) print(count+1) count=eval(input('Enter count value:')) print(count+1) count=input('Enter count value:') print(int(count)+1).
Report abuse Consent Terms of use