100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Exam (elaborations)

Python Final UPDATED Actual Exam Questions and CORRECT Answers

Rating
-
Sold
-
Pages
31
Grade
A+
Uploaded on
25-09-2024
Written in
2024/2025

Python Final UPDATED Actual Exam Questions and CORRECT Answers Reference the following program to answer the next four questions: def print_pi(): print(3.14159) print_pi() print_pi() - CORRECT ANSWER- 2 functions call to print_pi() 1 function definition of print_pi() 2 output statements would execute in total 1 print statement exists in the program code

Show more Read less
Institution
Python
Course
Python











Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
Python
Course
Python

Document information

Uploaded on
September 25, 2024
Number of pages
31
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Content preview

Python Final UPDATED Actual Exam
Questions and CORRECT Answers
Reference the following program to answer the next four questions:

def print_pi(): print(3.14159) print_pi() print_pi() - CORRECT ANSWER✔✔- 2 functions
call to print_pi()
1 function definition of print_pi()
2 output statements would execute in total
1 print statement exists in the program code


What is the difference between an argument and a parameter? - CORRECT ANSWER✔✔- A
parameter is a function input specified in a function definition, whereas an argument is a
value provided to a function's parameter during a function call.


Fill in the blank to complete the function definition to have a parameter named user_age.

def print_age(___): - CORRECT ANSWER✔✔- def print_age(user_age):


Call a function named print_age, passing the value 21 as an argument. - CORRECT
ANSWER✔✔- print_age(21)


Is the following a valid function definition beginning?

def my_fct(userNum + 5): - CORRECT ANSWER✔✔- False


Assume a function def print_num(user_num): simply prints the value of user_num without
any space or newline. What will the following code output?

print_num(43) print_num(21) - CORRECT ANSWER✔✔- 4321


Which correctly defines two parameters x and y for a function definition:

def calc_val(...):? - CORRECT ANSWER✔✔- (x, y)


Which correctly passes two integer arguments for the function call calc_val(...)? - CORRECT
ANSWER✔✔- (99, 44 + 5)

,Given a function definition:
def calc_val(a, b, c):
what value is assigned to b during this function call?

calc_val(42, 55, 77) - CORRECT ANSWER✔✔- 55


Given a function definition:
def calc_val(a, b, c):
and given variables i, j, and k, which answer shows valid arguments in the call

calc_val(...) - CORRECT ANSWER✔✔- (k, i + j, 99)


Add a print statement to the function definition to print the hours, given minutes. There are
60 minutes in one hour.
def print_minutes_as_hours(original_minutes): ... minutes = float(input())
print_minutes_as_hours(minutes) - CORRECT ANSWER✔✔- print(original_minutes / 60)


Add a return statement to the function definition that returns the result of adding num1 and
num2.

def sum(num1, num2): - CORRECT ANSWER✔✔- return num1 + num2


Given the following function, which statements are valid?

def square_root(x): return math.sqrt(x) def print_val(x): print(x) - CORRECT ANSWER✔✔-
y = square_root(49.0)
y = 1.0 + square_root(144.0)
y = square_root(square_root(16.0))
square_root(9.0)
y = print_val(9.0)
print_val(9.0)


Chapter 1 Statements that are true. - CORRECT ANSWER✔✔- Polymorphism refers to how
an operation depends on the involved object types.

,Static-typed languages require that the type of every variable is defined in the source code.


A dynamic-typed language like Python checks that an operation is valid when that operation
is executed by the interpreter. If the operation is invalid, a run-time error occurs.


If my_func1() and my_func2() are defined functions, then the expression
my_func1(my_func2) passes the my_func2 function object as an argument to my_func1.


Functions are compiled into bytecode when the function definition is evaluated by the
interpreter.


A benefit of functions is to reduce redundant code.


Incremental development may involve more frequent testing, but ultimately leads to faster
development of a program.


Forgetting to return a value from a function is a common error.


Returning the incorrect variable from a function is a common error.


Copying-and-pasting code can lead to common errors if all necessary changes are not made
to the pasted code.


A local variable is defined inside a function, while a global variable is defined outside any
function.


A function definition must be evaluated by the interpreter before the function can be called.


A programmer can protect mutable arguments from unwanted changes by passing a copy of
the object to a function.


Adding an element to a dictionary argument in a function might affect variables outside the
function that reference the same dictionary object.

, The statement return a, b, [c, d] is valid.


What is the output of the following program?

def dog(): print('woof') def cow(): print('moo') dog = cow dog() - CORRECT ANSWER✔✔-
moo


Define function print_teenager with parameter age.
If age is less than 13, print "Too young".
If greater than 19, print "Too old".
Otherwise, print "Has been a teenager for" followed by the result of computing age - 13
followed by "years.".
End with a newline.

Sample output with input: 14Has been a teenager for 1 years. - CORRECT ANSWER✔✔-
One possible answer is
def print_teenager(age): if age < 13: print("Too young") elif age > 19: print("Too old") else:
print("Has been a teenager for", age - 13, "years.")


Match the words - CORRECT ANSWER✔✔- scope resolution: The process of searching
namespaces for a name.


namespace: Maps the visible names in a scope to objects.


locals(): Returns a dictionary of the names found in the local namespace.


scope: The area of code where a name is visible.


For the next two questions, assume the function below is defined:
def split_check(amount, num_people, tax_percentage, tip_percentage): # ... - CORRECT
ANSWER✔✔- What value is passed as the tax_percentage argument in the following
function call?
split_check(60.52, 5, 0.07, tip_percentage=0.18) :

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
MGRADES Stanford University
View profile
Follow You need to be logged in order to follow users or courses
Sold
1072
Member since
1 year
Number of followers
102
Documents
68976
Last sold
2 days ago
MGRADES (Stanford Top Brains)

Welcome to MGRADES Exams, practices and Study materials Just think of me as the plug you will refer to your friends Me and my team will always make sure you get the best value from the exams markets. I offer the best study and exam materials for a wide range of courses and units. Make your study sessions more efficient and effective. Dive in and discover all you need to excel in your academic journey!

3.8

170 reviews

5
73
4
30
3
45
2
8
1
14

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions