Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

CPSC 217 FINAL | LATEST STUDY | QUESTIONS AND ANSWERS | 2026 STUDY UPDATES

Rating
-
Sold
-
Pages
23
Grade
A+
Uploaded on
19-01-2026
Written in
2025/2026

CPSC 217 FINAL | LATEST STUDY | QUESTIONS AND ANSWERS | 2026 STUDY UPDATES

Institution
CPSC 217
Course
CPSC 217

Content preview

CPSC 217 FINAL | LATEST STUDY | QUESTIONS AND
ANSWERS | 2026 STUDY UPDATES
What is the best way to create functions for a program? Give example - ANSWER- Top
down approach, break it down into parts



ex. Program to calculate interest, break it into 3 functions

1. Get info

2. Do Calculations

3. Display results

What is the result of and how does it work?



def displayInstructions ( ):

print ("Displaying instructions")



displayInstructions ( )

print ("End") - ANSWER- You created a function called displayIntructions. The body of that
function has the print function in it which will have the output of: "Displaying instructions"

Then you called on your newly defined function, so this executes the function (ie, its body) and
then the last output is: "End"

True or false: once a function is executed one time, it can't be called again, even if you try and
call the function multiple times. - ANSWER- False! You can reuse a function as many times
as you want/is called

What is the difference between a local variable and global variable? - ANSWER- Local
variables are stored within function bodies.

Global variables are generally defined at the beginning of the code and can be accessed anytime

,Why have local variables? - ANSWER- Since variables are memory locations, they take up
a portion of memory of the program. So by creating local variables, the memory is used up
temporarily, and then once the function is executed, that memory frees up.

When a constant or a variable is in scope, we really mean...Give example - ANSWER- It is
somewhere that it can be used. Ex. a local variable is in scope of the function it is under

What is parameter passing? What's often forgotten (2)? - ANSWER- Passing local variables
from one function to another.

The number of parameters passed into a function, must equal the number of
parameters/variables that are called on. It also needs to match exactly what is called on in the
start function.

Is this correct:



def start ( ):

print (num) - ANSWER- No, no parameter 'num' passed into start, so it can't access that
memory location called 'num'.



To fix it, must have:

def start (num):

print (num)

What does the return function do? What is often forgotten?

Give example - ANSWER- It communicates a copy of information out of a function (back to
caller) as function ends.



THE RETURN VALUE MUST BE STORED IN THE START FUNCTION




def square (num):

result = num * num

, return (result)



def start ( ):

aStr = input ("Enter a number: ")

num = int(aStr)

*result* = square (num)

print (result)

Difference between parameter passing and return values? - ANSWER- Parameter passing
passes info INTO function before it executes (passes memory location of variable into function)



Return values communicate info OUT of a function as the function ends

What are some good style of functions that should be implemented? - ANSWER- 1.
Function should have a well defined task

2. Have a self-descriptive name

3. No longer than 1 screen

4. Use variable naming conventions (lower case, camel-case, or underscore)

Why should you not use global variables? Give an example - ANSWER- Can accidentally be
changed anywhere - since they can be accessed from anywhere, makes code harder to trace



num = 1



def fun ( ):

*global* num #calls in global num

num = 2 #changes global num from 1 to 2

print (num)



def start ( ):

Written for

Institution
CPSC 217
Course
CPSC 217

Document information

Uploaded on
January 19, 2026
Number of pages
23
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$16.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

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.
EduSprint Chamberlain College Of Nursing
View profile
Follow You need to be logged in order to follow users or courses
Sold
39
Member since
2 year
Number of followers
6
Documents
6470
Last sold
4 days ago
STUDY_STASH

4.3

6 reviews

5
4
4
0
3
2
2
0
1
0

Trending documents

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