Karteikarten
PYTHON REPASO
Karten in diesem Stapel (15)
- 1—The ABC company has hired you as an intern on the coding team that creates e-commerce applications.
You must write a script that asks the user for a value. The value must be used as a whole number in a calculation, even if the user enters a decimal value.
You need to write the code to meet the requirements.
Which code segment should you use?
A. totalItems = input(“How many items would you like?”)
B. totalItems = float(input(“How many items would you like?”))
C. totalItems = str(input(“How many items would you like?”))
D. totalItems = int(input(“How many items would you like?”)) - 2—You are writing a Python program that evaluates an arithmetic formula.
The formula is described as b equals a multiplied by negative one, then raised to the second power, where a is the value that will be input and b is the result.
You create the following code segment. Line numbers are included for reference only.
01 a= eval(input ("enter a number for the equation"))
02 b=
You need to ensure that the result is correct.
How should you complete the code on line 02?
- 3—The ABC company is converting an existing application to Python. You are creating documentation that will be used by several interns who are working on the
team.
You need to ensure that arithmetic expressions are coded correctly.
What is the correct order of operations for the six classes of operations ordered from first to last in order of precedence? To answer, move all operations from the
list of operations to the answer area and arrange them in the correct order.
Select and Place:
- 4—Match the data type to the type operations.
To answer, drag the appropriate data type to the correct type operation. Each data type may be used once, more than once, or not at all
- 5—You are creating a Python program that shows a congratulation message to employees on their service anniversary.
You need to calculate the number of years of service and print a congratulatory message.
You have written the following code. Line numbers are included for reference only.
Which code should you use at line 03?
A. print(“Congratulations on” + (int(end)-int(start)) + “years of service!”)
B. print(“Congratulations on” + str(int(end)-int(start)) + “years of service!”)
C. print(“Congratulations on” + int(end - start) + “years of service!”)
D. print(“Congratulations on” + str(end - start)) + “years of service!”)
- 6—You are creating a function that manipulates a number. The function has the following requirements:
A float is passed into the function
The function must take the absolute value of the float
Any decimal points after the integer must be removed
Which two math functions should you use? Each correct answer is part of the solution. (Choose two.)
A. math.fmod(x)
B. math.frexp(x)
C. math.floor(x)
D. math.ceil(x)
E. math.fabs(x) - 7—You are writing code that generates a random integer with a minimum value of 5 and a maximum value of 11.
Which two functions should you use? Each correct answer presents a complete solution. (Choose two.)
A. random.randint(5, 12)
B. random.randint(5, 11)
C. random.randrange(5, 12, 1)
D. random.randrange(5, 11, 1)
- 8—You are writing a function that works with files.
You need to ensure that the function returns None if the file does not exist. If the file does exist, the function must return the first line.
the following code:
- 9—You develop a Python application for your company.
You need to accept input from the user and print that information to the user screen.
You have started with the following code. Line numbers are included for reference only.
01 print("What is your name?")
02
03 print(name)
Which code should you write at line 02?
A. name = input
B. input(“name”)
C. input(name)
D. name = input()
- 10—You develop a Python application for your school.
You need to read and write data to a text file. If the file does not exist, it must be created. If the file has content, the content must be removed.
Which code should you use?
A. open(“local_data”, “r”)
B. open(“local_data”, “r+”)
C. open(“local_data”, “w+”)
D. open(“local_data”, “w”) - 11—You find errors while evaluating the following code. Line numbers are included for reference only.
You need to correct the code at line 03 and line 06.
How should you correct the code? Use the drop-down menus to select the answer choice that answers each question based on the information presented in the
code segment.
- 12—You write the following code:
The out.txt file does not exist. You run the code. The code will execute without error.
Review the underlined text. If it makes the statement correct, select “No change is needed”. If the statement is incorrect, select the answer choice that makes the
statement correct.
A. No change is needed
B. The code runs, but generates a logic error
C. The code will generate a runtime error
D. The code will generate a syntax error
- 13—You are creating a function that reads a data file and prints each line of the file.
You write the following code. Line numbers are included for reference only.
The code attempts to read the file even if the file does not exist.
You need to correct the code.
Which three lines have indentation problems? Each correct answer presents part of the solution. (Choose three.)
A. Line 01
B. Line 02
C. Line 03
D. Line 04
E. Line 05
F. Line 06 G. Line 07 H. Line 08
- 14—You are writing an application that uses the sqrt function. The program must reference the function using the name squareRoot.
You need to import the function.
Which code segment should you use?
A. import math.sqrt as squareRoot
B. import sqrt from math as squareRoot
C. from math import sqrt as squareRoot
D. from math.sqrt as squareRoot
- 15—You develop a Python application for your company.
A list named employees contains 200 employee names, the last five being company management. You need to slice the list to display all employees excluding
management.
Which two code segments should you use? Each correct answer presents a complete solution. (Choose two.)
A. employees [1:-4]
B. employees [:-5]
C. employees [1:-5]
D. employees [0:-4] E. employees [0:-5]
Informationen
- Beschreibung
- Karteikarten am PYTHON REPASO, erstellt von info team am 10/07/2020.
- Erstellt von
- info team
- Aufrufe
- 37
- Bewertung