Docsity

MTA Introduction to Programming Using Python Test 1 Training, Questions and answers, Rat, Exams of Programming Methodologies

Toggle sidebar
bg1
MTA Introduction to Programming Using
Python Test 1 Training, Questions and
answers, Rated A+
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 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)
Which variable names reflect an improper variable name declaration? Choose two answers - โœ”โœ”-last-
name
last Name
Drag the appropriate function to the missing code are to convert the price variable to a value of 19.
inventoryCount = 19.95
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download MTA Introduction to Programming Using Python Test 1 Training, Questions and answers, Rat and more Exams Programming Methodologies in PDF only on Docsity!

MTA Introduction to Programming Using

Python Test 1 Training, Questions and

answers, Rated A+

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 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) Which variable names reflect an improper variable name declaration? Choose two answers - โœ”โœ”-last- name last Name Drag the appropriate function to the missing code are to convert the price variable to a value of 19. inventoryCount = 19.

print("We have " ______ (inventoryCount)" complete units in stock.") - โœ”โœ”-int 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) 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])

Choose the correct operator to get a print result of 4. a = 24 b = 5 print(a _____ b) - โœ”โœ”-% 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 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 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

  1. print("Great month")
  2. 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 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 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"

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) Which keyword is used as a placeholder for a conditional result? - โœ”โœ”-pass 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]] 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): 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) In Python, which characters(s) should be placed before text in a line of code to make that line of code a comment? - โœ”โœ”-# Take a look at the following code example: region = "West" annualSales = 500000 firstName = "Tony"

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.") 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) 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() ]] 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) 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) 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. items= 15 print( [[ f ]] "We have {items} items in stock.")

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 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 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.")