100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Python Final UPDATED Actual Exam Questions and CORRECT Answers CA$13.66   Add to cart

Exam (elaborations)

Python Final UPDATED Actual Exam Questions and CORRECT Answers

 6 views  0 purchase
  • Course
  • Python
  • Institution
  • Python

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 wou...

[Show more]

Preview 4 out of 31  pages

  • September 25, 2024
  • 31
  • 2024/2025
  • Exam (elaborations)
  • Questions & answers
  • Python
  • Python
avatar-seller
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) :

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller MGRADES. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for CA$13.66. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

67096 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
CA$13.66
  • (0)
  Add to cart