Python Programming Practice Exam 1: Questions and Answers, Exams of Advanced Education

A set of practice exam questions and answers for python programming. It covers various topics, including data structures, sorting, variable declarations, data types, conditional statements, loops, functions, file handling, and error handling. The questions are designed to test the understanding of python syntax, concepts, and problem-solving skills. This resource is useful for students and developers preparing for python exams or looking to improve their python proficiency. It includes code snippets, explanations, and examples to aid in comprehension and application of python programming principles. The document also touches on unit testing and random number generation.

Typology: Exams

2024/2025

Available from 11/16/2025

guidedexam
guidedexam 🇺🇸

2.5

(2)

6.9K documents

1 / 12

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ITS Python Programming Practice
Exam 1 Questions and Answers
A developer needs to build a data structure with animals and then sort the
structure. Using drag and drop, drag the following lines of code into the
correct order to produce this output:
Bears
Jaguars
Lions
Panthers - ANSWERS-animals=["Bears","Panthers","Lions"]
animals.append("Jaguars")
animals.sort()
for animal in animals:
print(animal)
x=5
y=3
z=x+y> and x*y<15 or x-y>2 - ANSWERS-z=
pieces=["king", "queen", "rook", "bishop", "knight, "pawn"]
pieces.sort() - ANSWERS-print(pieces[5])
print(pieces[-1])
a == 90 - ANSWERS-Yes
b == 2.5 - ANSWERS-No
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Python Programming Practice Exam 1: Questions and Answers and more Exams Advanced Education in PDF only on Docsity!

ITS Python Programming Practice

Exam 1 Questions and Answers

A developer needs to build a data structure with animals and then sort the structure. Using drag and drop, drag the following lines of code into the correct order to produce this output: Bears Jaguars Lions Panthers - ANSWERS-animals=["Bears","Panthers","Lions"] animals.append("Jaguars") animals.sort() for animal in animals: print(animal) x= y= z=x+y> and x*y<15 or x-y>2 - ANSWERS-z= pieces=["king", "queen", "rook", "bishop", "knight, "pawn"] pieces.sort() - ANSWERS-print(pieces[5]) print(pieces[-1]) a == 90 - ANSWERS-Yes b == 2.5 - ANSWERS-No

c == -9 - ANSWERS-Yes if grade __ 100: print ("Outstanding") elif grade __ 90: print ("Great") elif grade __ 70: print("Study hard") else: print("You are doing well. Strive to improve") - ANSWERS-==

= <= a__b= a__b= a__b=3. a__b= a__3=1 - ANSWERS-+

/ // % a == b - ANSWERS-Yes a is b - ANSWERS-Yes b == 3 - ANSWERS-No c is b - ANSWERS-No

number down to the nearest integer. The ceil function will raise the number to 20. The correct code is as follows: - ANSWERS-int Drag the lines of code into the correct order to accomplish the following: The messages "Great month" and "Keep it going" are printed for month sales of over 10000. Not all lines of code will be used. - ANSWERS-if month_sales>10000: print("Great month") print("Keep it going") Choose the correct lines of code to satisfy the needs of the following function: Students with scores of 90 or higher get an A. Students with scores from 80 to 89 get a B. Students with scores from 70 to 79 get a C. Everyone else gets an F. - ANSWERS-score >== 90: score >= 80: score >= 70: grade = "F" Analyze the following code: x == 7 y == 4 print(x>y and x-y>=2 or x+y==11 and not xy>25) Using drag and drop, arrange the sequence of execution order for the print statement. - ANSWERS-not xy> x>y and x-y>= x+y==11 and not x*y>

x>y and x-y>=2 or x+y==11 and not x*y> You are trying to loop through some values retrieved from a list. You want the list to keep printing these values, but if the list sees a value of "end of day", then the printing should stop. Select the missing code examples to finish writing this code block. - ANSWERS-while break scheduledEvent += The following code examples needs to print the number of minutes per day to walk, starting with 10 minutes a day in week 1 and ending with 50 minutes a day in week 5. Choose the correct line of code to start this iteration and finish this code example. - ANSWERS-for week in range(1,6) A developer needs to add, to an existing app, code that will print a message a set number of times. However, the developer does not yet know the message but the variables used in the loop for a message are used elsewhere in the app. Which keyword, when added to the end of the code, will serve as a placeholder for future text? Here is the code example: for x in range(1,5): - ANSWERS-Pass Complete the code examples to build a function that does the following: Its name is calcSubtotal The function takes an amount and a sales tax rate and calculates a subtotal The new subtotal is returned - ANSWERS-def calcSubtotal (amount, salesTaxRate): return subtotal

Using drag and drop, drag over the lines of that will accomplish the follwoing: Open the shirts file in a mode to where it cannot be written to Read the contents of the entire file Print the contents of the entire file Not every line of code will be used - ANSWERS-shirtFile=open("shirts.txt","r") shirtFileContents=shirtFile.read() print(shirtFileContents) A developer is starting to build a unit test and needs help figuring out the build-in module that is needed for the test, the way to check to see if the unit test is run as the main module, and the actual unit test to run to see if two values are equal to each other. Using the dropdown arrows, fill in the code needed to finish building the unit test. - ANSWERS-TestCase assertEqual name_ In the following code example, add the necessary code to tell python to read and print the text file being opened, if the file already exists. If the file does not exist, print a message indicating as such. - ANSWERS-exists workFile.read() A junior Python programmer wants to have a user input a location and then have the location print on the screen. In addition, the developer wants to tell the user to enter North, South, East, or West for a location. Using drag and drop, drag over the lines of code necessary to accomplish this. Not every line of code will be used. - ANSWERS-location=["North","South","West","East"] response=input["North,South,West, or East for a location."] while response not in location: print("Try again.")

response=input["North,South,West, or East for a location."] Using the dropdown arrow, add the symbol needed to get the number of items to print instead of {items}. The following code example, as is, prints "You have {items} items in stock" instead of the number of items in stock. - ANSWERS-f Evaluate the following code that writes a message to an existing log file at the start of each day: with open('log.txt','w') as file: file.write('Daily Log') file.close() - ANSWERS-The close function is not needed. The log file is overwritten each time it is opened. When using the sys.argv[0] command as part of running a Python app in a command prompt, what does the 0 represent in sys.argv? - ANSWERS-The file name Take a look at the following code example: carLoan= intRate=1. licenseFee= totalLaon=carLoan+licenseFeeintRate - ANSWERS- totalLoan=(carLoan+licenseFee)intRate Evaluate the following anatomy of a unit test, part of a larger block of code. deftest_memory(self): a= b=a

A game developer is testing some random number generators. The results should be as follows: result1 should have a random country from a list of countries result2 should display the list in a random order result3 should display two random countries from a list of countries Using the dropdown arrows, fill in the code needed to generate the proper random numbers for each variable. - ANSWERS-import random choice(countries) shuffle(countries) sample(countries,2) A new Python developer is a learning build-in modules and the methods used in those modules. Specifically, the developer needs to know the modules used to open text files, find the mean from a series of test scores, make directories within Python, and exit a gaming app when the game is over. Using drag and drop, match each method with the built-in module used. - ANSWERS-io math os sys Using the snippets of code below, use the drag-and-drop method to build code that will do the the following: Store the actual value of pi in a variable called pi Use pi to calculate the area of a circle and store it in a variable called area. A user will enter the radius of the circle and needs an option to have the radius be carried out to decimal places. Print the result (the area), formatted to two decimal places. Not every line of code will be used. - ANSWERS-import math pi=math.pi

radius=flat(input("Enter a radius for a circle.")) area=piradius* print(f"A circle with a radius of {radius} will have an area of %.2f."%area) A developer is building a code block to log a current date and time for app activity. Which code snippet will replace the #current date and time comment with the correct date and time? import datetime log_time = #current date and time print("entry time: ", log_time) - ANSWERS-datetime.datetime.now() Evaluate the following partial code snippet: cities=['Anchorage','Juneau','Fairbanks','Ketchikan','Sitka','Wasilla'] for city in range(cities): print(f'{city} is a famous Alaskan city.') if city == 'Ketchikan': break - ANSWERS- Analyze the following code: a= b= c= a*=b b=c a//=b For each statement regarding the values of these variables, indicate Yes if the statement is false. c==