






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A series of python programming questions and their corresponding correct answers, designed to test and reinforce understanding of fundamental python concepts. It covers topics such as data types, variable declarations, control flow, data structures, functions, file handling, and error handling. The questions are structured in a quiz format, making it a useful resource for students and developers looking to assess their python knowledge and improve their coding skills. Code snippets and explanations, providing a comprehensive review of python programming principles. It serves as a valuable tool for exam preparation and self-assessment in python programming.
Typology: Exams
1 / 12
This page cannot be seen from the preview
Don't miss anything!







Python makes the distinction between integers and floating variables. - CORRECT ANSWER✔✔- Yes When declaring variables in Python, a data type must be specified. - CORRECT ANSWER✔✔-No When setting a boolean variable, the value must start with a capital letter. - CORRECT ANSWER✔✔-Yes A developer wants to make sure a serial number cannot be used in a calculation and that a dollar amount entered as a whole number can have decimals. Then, a message should be displayed to tell a customer the serial number and price for the products. Using the drop-down arrows, fill in the code to use the proper functions to convert the data to the necessary data types. - CORRECT ANSWER✔✔-str float , A developer needs to write code to reverse the character output of a product code. Which variable declaration will reverse one of the product codes? - CORRECT ANSWER✔✔-[::-1] In this scenario, the number of complete units needs to be displayed, meaning that anything after a decimal point needs to not be represented. To accomplish this, the int function is needed as it extracts the whole number from a value with a floating decimal. The round function will not work because it will round the number up to 20. The floor function rounds a number down to the nearest integer. The ceil function will raise the number to 20. The correct code is as follows: - CORRECT ANSWER✔✔-int
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 - CORRECT ANSWER✔✔-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 - CORRECT ANSWER✔✔-z= pieces=["king", "queen", "rook", "bishop", "knight, "pawn"] pieces.sort() - CORRECT ANSWER✔✔-print(pieces[5]) print(pieces[-1]) a == 90 - CORRECT ANSWER✔✔-Yes b == 2.5 - CORRECT ANSWER✔✔-No c == -9 - CORRECT ANSWER✔✔-Yes
Look at the following code and then select the correct keyword to use to check to see if the word "nine" is part of the quote. If this code runs, it should return a value of True. - CORRECT ANSWER✔✔-in 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. - CORRECT ANSWER✔✔-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. - CORRECT ANSWER✔✔-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. - CORRECT ANSWER✔✔-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. - CORRECT ANSWER✔✔- 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. - CORRECT ANSWER✔✔-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): - CORRECT ANSWER✔✔-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 - CORRECT ANSWER✔✔-def calcSubtotal (amount, salesTaxRate): return subtotal
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 - CORRECT ANSWER✔✔-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. - CORRECT ANSWER✔✔-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. - CORRECT ANSWER✔✔-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. - CORRECT ANSWER✔✔- 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. - CORRECT ANSWER✔✔-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() - CORRECT ANSWER✔✔-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? - CORRECT ANSWER✔✔-The file name Take a look at the following code example: carLoan= intRate=1. licenseFee= totalLaon=carLoan+licenseFeeintRate - CORRECT ANSWER✔✔- 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 #insert assert test here
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. - CORRECT ANSWER✔✔-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. - CORRECT ANSWER✔✔-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. - CORRECT ANSWER✔✔-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) - CORRECT ANSWER✔✔-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 - CORRECT ANSWER✔✔- 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== b== a==1 - CORRECT ANSWER✔✔-Yes Yes