ENGR 102 Fall 2021 Exam 2 Practice Questions ELMS-1

pdf

School

University of Texas, Arlington *

*We aren’t endorsed by this school

Course

2425

Subject

Mathematics

Date

Apr 3, 2024

Type

pdf

Pages

5

Uploaded by PresidentValor9321

Report
ENGR 102 Fall 2021 Exam 2 Practice Questions ELMS 1.) A function stub is: A.) A method of calling a function. B.) A short string describing what the function does. C.) The return provided by the function. D.) A placeholder for a function when coding. E.) A parameter that has been assigned a default value. 2.) Which of the following will not read the entire file?: A.) x = my_file.readline() B.) x = my_file.read() C.) x = my_file.readlines() D.) x = list(my_file) 3.) howdy() def howdy(): print ( "Howdy Ags!" ) print ( "Gig'em" ) howdy() The code snippet above will result in the following being printed to the console: A.) Howdy Ags! Gig’em! Howdy Ags! B.) Gig’em! Howdy Ags! C.) Error Gig’em! Howdy Ags! D.) Error E.) Gig’em! F.) Gig’em! Error 4.) The correct way to access data from a function is to pass in the data via arguments/parameters. T/F 5.) By default, files are created in the same directory as the .py file that creates them. T/F
6.) def number_fun(n): n += 12 print (n) k = 10 print (k) number_fun(k) print (k) The code snippet above will result in the following being printed to the console: A.) 10 12 10 B.) 10 22 22 C.) 10 10 10 D.) 10 22 10 7.) When using a Top-Down design approach, the resulting code can become too specialized. T/F 8.) def peanut(): x = 4 y = 9 z = x + y def butter(z): jelly(z) x = 10 peanut() butter(x) The code snippet above will result in the following being printed to the console: A.) 10 B.) 13 C.) 13 Error D.) Error E.) 10
9.) Below are the contents of the file green.txt: 2,4,6,8 10,12,14,16 18,20,22,24 Below is a code snippet: with open ( 'green.txt' , 'r' ) as specialFile: with open ( 'blue.txt' , 'w' ) as funFile: for green_line in specialFile: color = green_line.split( ',' ) funFile.write(color[ 2 ] + color[ 0 ]) What will the contents of blue.txt be after the snippet above is executed? A. 8 24 40 B. 82440 C. 8,24,40 D. 62 1410 2218 E. 6214102218 F. 6,2,14,10,22,18 10.) def ol_sarge(a, b = "maroon" , c): print (a, b, c) ol_sarge( 'Aggies' , b = 'white' , 'maroon' ) The code snippet above will result in the following being printed to the console: A.) Aggies white maroon B.) Aggies maroon maroon C.) Error D.) Aggies, white, maroon E.) Aggies, maroon, maroon
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
11.) def kyle_field(a, b = "Texas" , c = "Aggies" ): print (a, b, c) a = "Gig'em" kyle_field() The code snippet above will result in the following being printed to the console: A. Gig’em Texas Aggies B. Texas Aggies C. A blank line D. Error 12.) With respect to try and except blocks, execution jumps to an except block only if an error occurs in the preceding try block. T/F 13.) Free Response Question: Complete the tasks below: Write a function called fan_analysis() that does the following: 1.) Prompts entry of the following information from the user: i. A person’s name . ii. Asks if the person likes Star Wars, requiring an answer of Y for yes, N for no. iii. Asks if the person likes Star Trek, requiring an answer of Y for yes, N for no. 2.) If the person likes both Star Wars and Star Trek, the function writes that person’s name to a file named Both_Fans.txt. 3.) If the person only likes Star Wars, the function writes that person’s name to a file named Star_Wars_Fans.txt. 4.) If the person only likes Star Trek, the function writes the person’s name to a file named Star_Trek_Fans.txt. 5.) The function should allow for entry of as many sets of data (the 3 items in 1.) as the user wants. 6.) Each name written to any of the files should be on a separate line. 7.) All information contained in the 3 files should not be overwritten. 8.) The function returns the total count of how many people like both Star Wars and Star Trek, only Star Wars, and only Star Trek (in that order) contained in the 3 files, to including any names that were already in the files when the function was called. For each of the following problems, please provide a short answer. 14.) What is the difference between the Python IO functions read() , readline() , and readlines() ? 15.) Explain why one would use functions in developing larger, complex programs.
16.) What is the difference between a list, a tuple, and a numpy array? 17.) Other than answering that the Top-Down process starts at the top and the Bottom-Up process starts at the bottom, describe at least two differences in the approach to programming, between the Top-Down Design Process and the Bottom-Up Design process. 18.) Explain how try and except blocks handle exceptions. For each of the following problems, determine the output produced by the code snippet. If an error is produced, explain the cause of the error. 19.) for i in [1, 1.5, 2, 2.5]: i *= 2 for j in range(i): print(j) break 20.) num = [1, 2, 3, 4, 5] for i in range(2, len(num)): if num[i] % 2 != 0: num[i] = 0 elif num[i] % 3 != 0: num[i] = 1 21.) for j in range(3): i = j + 1 while (i < 5): if(i %2 == 0): i *= 2 else: i *= 2 i -= -1 print(i, end=' ') 22.) def dosomething(a): a[1] = 6 a = [2, 4, 6] x = [1, 5, 7] dosomething(x) print(x[1])