MTA Introduction to Programming Using Python Test 1 Training

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Complete the code example to build a function that does the following: - it's name is calcSubtotal - The function takes an amount and a sales tax rate and calculates a subtotal - The new subtotal is returned

[[def calcSubtotal]] [[ (amount, salesTaxRate): ]] subtotal = amount * (1 + salesTaxRate) [[return subtotal]]

The following code example needs to print, for five weeks, 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 the code example.

[[for week in range (1,6) ]] print("You should walk for ", week * 10, " minutes in ", week)

Take a look at the following code example, used to calculate a subtotal for an order: subtotal = amount + (1 * salesTax) + shipping return subtotal order1 = calcTotal(500, .07, 10) print ("Your order total is ", order1) Which line of code needs to be added to the top of this code example in order to complete the code example?

def calcTotal(amount, salesTax, shipping):

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 between 80 and 89 get a B Students with scores between 70 and 79 get a C Everyone else gets an F

def grade(score): if (score >= 90: grade = "A") elif (score >= 80: grade "B") elif (score >=70: grade = "C") else (grade = "F") return grade

Drag the appropriate function to the missing code are to convert the price variable to a value of 19. inventoryCount = 19.95 print("We have " ______ (inventoryCount)" complete units in stock.")

int

Which of the following code examples is using incorrect syntax?

onSale = true

Take a look at the following function: def subtotal(orderAmt, salesTax): subtotal = float(orderAmt) * (1 + float(salesTax)) return subtotal Which code example properly calls the function and returns a calculation?

orderTotal = subtotal(500, .07)

Which keyword is used as a placeholder for a conditional result?

pass

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" the the printing should stop. select the missing code examples to finish writing this code block.

schedule = ["Opening Comments", "Breakfast", "Breakout Session 1", "Lunch", "Breakout Session 2", "End of Day", "Opening Comments", "Breakfast"] scheduledEvent = 0 [[while]] (scheduledEvent < len(schedule)): print(schedule[scheduledEvent]) if schedule[scheduledEvent] == "End of Day": [[continue]] else: [[scheduledEvent += 1]]

In the following code example, select the snippet of code that will tell Python to read and print just the first line of the text file being opened.

workFile = open('work.txt', 'r') workFileFirstLine = [[ workFile.readline() ]] print(workFileFirstLine)

Take a look at the following code example: carLoan = 20000 intRate = .05 licenseFee = 500 totalLoan = carLoan + licenseFee * intRate A user of the app with this code is complaining that the total loan amount is far lower than what is anticipated. What kind of error is taking place here?

Logic

Look at the following code and indicate, for each area, the proper concatenating symbol. price = 18.00product = "Yellow Golf Balls"print(product [ ________ ] " are on sale for " [ _________ ] price ".")

" , " & " , " (COMMAS)

In Python, which characters(s) should be placed before text in a line of code to make that line of code a comment?

#

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.

1 - location = input("Enter North, South, West, or East") 2 - print(location)

Using drag and drop, drag over the lines of code that will accomplish the following: - 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 o code will be used

1 - shirtFile = open("shirts.txt", "r") 2 - shirtFileContents = shirtFile.read() 3 - print(shirtFileContents)

Examine the following code. What type of error could potentially occur, depending upon what a user inputs? x = float(input("Enter a number.")) y = float(input("Enter a number to divide by.")) print(f"The answer is {x/y}.")

Runtime

How many Syntax errors are there in the following code? totalSales = 100000 newCustomer = True if totalSales >= 700000 print("Gold Customer") elif totalSales >= 400000: print("Silver Customer") elif totalSales >= 100000 and newCustomer: print("Bronze Customer and first-time prize winner") elif totalSales >= 100000 print("Bronze Customer") prnit("Thank you for your business")

4

Choose the correct operator to get a print result of 4. a = 24 b = 5 print(a _____ b)

%

Drag in the correct order, lines of code that accomplish the following: The messages "Great month" and "Keep it going" are printed for month sales over 1000.

1) if monthSales > 10000 2) print("Great month") 3) print("Keep it going")

Drag the correct lines of code in the correct order to accomplish this: If the number of defects is less than 5, show a message of "perfect" If the number of defects is between 5 and 10, show a message of "average" If the number of defects exceed 10, show a message of "needs improvement" Not every code will be used.

1) if numberOfDefects < 5: 2) print("perfect") 3) elif numberOfDefects <= 10: 4) print("average") 5) else: 6) print("needs improvement")

The following code example does a simple calculation to divide two numbers. You want to handle any errors gracefully and ensure that the last print statement always prints, even if there is as an error. Using the drop-down arrows, fill in the missing keywords in the code to accomplish this.

FINISH THIS ONE POR FAVOR x = float(input("Enter a number. ")) y = float(input("Enter a number to divide by. ")) print(f"The answer is {x/y}.") print("Uh oh. Did you enter something besides a number? Did you try to divide by zero?") print("You successfully played the division game.") print("Thank you for playing.")

Evaluate each situation regarding data types and answer yes if its true or no if it is false

NO - When declaring variables in Python, a data type must be specified. YES - Python makes the distinction between integers and floating variables. YES - When setting a boolean variable, the value must start with a capital letter

Look at these variables and assignments: a = 5 b = 5.5 c = 7 For each comparison statement, indicate a Yes if it is true or No if it is false

NO - a != int(b) YES - a <= b YES - c >= int(b)

Using drag and drop, drag the following lines of code into the correct order to produce this output: Bears Jaguars Lions Panthers

Step 1 - animals = ["Bears", "Lions", "Jaguars", "Tigers"] Step 2 - animals.append("Panthers") Step 3 - animals.remove("Tigers") Step 4 - animals.sort() Step 5 - for animal in animals: Step 6 - print (animal)

Look at the following code and then indicate, for each question, a yes or no answer based on whether the statement is true or false. a = 5 b = 3 b = a

YES - a == b YES - a is b NO - b == 3

When using Python in a command line environment, what command will list available Python commands and show information on these commands when an individual command is entered?

help()

Look at the following code example and then indicate which symbol is needed in the missing area to continue the line of code written on the next line.

if annualSales >= 700000: print("Great year") elif annualSales >= 300000: print("Decent year") else:: print("Better luck next year") print("Thank you for your efforts") print(f"Your sales representative is Nicole, you are in the East region, " [[ \ ]] "and you are based in the Potomac office.")

Look at the following code and then select the correct keyword to use the check to see if the word "nine" is part of the quote. If this code runs, it should return a value of True. quote = "A stitch in time saves nine" print("nine" _____ quote)

in

The following code example opens a file, reads it, and then prints its contents. In the missing code line, indicate what should be done with the file in order to free up memory the file has been using.

jacketsFile = open('jackets.txt', 'r') jacketsFileContents = jacketsFile.read() print(jacketsFileContents) [[ jacketsFile.close() ]]

Which variable names reflect an improper variable name declaration? Choose two answers

last-name last Name

The following code example, as is, prints "You have {items} items in stock" instead of the number of items in stock. Using the drop-down arrow, add the symbol needed to get the number of items to print instead of {items}.

price = 9.95 items= 15 print( [[ f ]] "We have {items} items in stock.")

Finish the following code example with print statement that will return a value of True a = 5 b = 5.5 c = 7 d = 7.5 print(_____)

print (a == int(b) and c == int(d))

Take a look at the following code example: region = "West" annualSales = 500000 firstName = "Tony" print("Customer Status") if annualSales >= 500000: print("Gold Customer") elif annualSales >= 300000: print("Silver Customer") elif annualSales >= 100000: print("Bronze Customer") print("Thank you for your business") The line "Thank you for your business" should always print. Indicate through selecting yes or no which lines need to be indented in order for this code to work properly.

print("Customer Status") - NO print("Gold Customer") - YES print("Silver Customer") - YES print("Bronze Customer") - YES print("Thank you for your business") - NO

From this code example: pieces = ["king", "queen", "rook", "bishop", "knight", "pawn"] pieces.sort() Which two commands will display the rock?

print(pieces[-1]) print(pieces[5])


संबंधित स्टडी सेट्स

Prep U Chapter 24: Nursing Care of the Child with an Integumentary Disorder

View Set

flow of fluid from the glomerulus to the external urethral orifice

View Set

PSIO 201: quiz 2A and 2B questions

View Set

All RHIA and Mock Domains (FAMU)

View Set

MCAT Psych/Soc: Social Stratification

View Set

Ch. 23 - Broker-Sales Associate Relationship

View Set