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

CMPSC 101 CORRECT QUESTIONS & ANSWERS(SCORED A+)

Rating
-
Sold
-
Pages
6
Grade
A+
Uploaded on
26-02-2025
Written in
2024/2025

x = 125 y = x/5 print(x,y) x= 100 print(x,y) - ANSWER125 25.0 100 25.0 **when x changes it doesn't change y** Global Variable - ANSWERa variable defined outside of a function or class and can be used at any point following their definition in the script how long to local variables last - ANSWERremain active during the function call and when the function comes to an end it does as well return - ANSWEREnds execution of a method and possibly returns a value of a result float vs int - ANSWERint is only whole numbers while float has decimal points how to make multiple line strings - ANSWER1. use ''' ''' so you can separate when you want line breaks 2. can write first line with n at the end and add to the variable using += how to put two different strings together - ANSWERprint("first part...", end="") print("second part") 1.58e2 - ANSWER158 charList = list('abcd') print(charList) - ANSWER['a','b','c','d'] x = 35.6 print(int(x)) - ANSWER35 / - ANSWERnormal division with answer being a float point result // - ANSWERinteger division so only counts how many times it goes in completely 11//3 = 3 % - ANSWERremainder division so the output is the leftover from integer division 11%3 = 2 +=

Show more Read less
Institution
CMPSC 101
Course
CMPSC 101









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

Written for

Institution
CMPSC 101
Course
CMPSC 101

Document information

Uploaded on
February 26, 2025
Number of pages
6
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

  • cmpsc 101 stuvia 2025

Content preview

CMPSC 101 CORRECT QUESTIONS &
ANSWERS(SCORED A+)
x = 125
y = x/5
print(x,y)

x= 100
print(x,y) - ANSWER125 25.0
100 25.0
**when x changes it doesn't change y**

Global Variable - ANSWERa variable defined outside of a function or class and can
be used at any point following their definition in the script

how long to local variables last - ANSWERremain active during the function call and
when the function comes to an end it does as well

return - ANSWEREnds execution of a method and possibly returns a value of a
result

float vs int - ANSWERint is only whole numbers while float has decimal points

how to make multiple line strings - ANSWER1. use ''' ''' so you can separate when
you want line breaks
2. can write first line with \n at the end and add to the variable using +=

how to put two different strings together - ANSWERprint("first part...", end="")
print("second part")

1.58e2 - ANSWER158

charList = list('abcd')
print(charList) - ANSWER['a','b','c','d']

x = 35.6
print(int(x)) - ANSWER35

/ - ANSWERnormal division with answer being a float point result

// - ANSWERinteger division so only counts how many times it goes in completely
11//3 = 3

% - ANSWERremainder division so the output is the leftover from integer division
11%3 = 2

+= 1

, -= 1 - ANSWERadds one to the variable
subtracts one from the variable

**=2 - ANSWERraises the variable to the 2 power

flstr = "the price is $%s.2f, and we need %4d units"
print(flstr % (25.30, 1500)) - ANSWERthe price is $25.30, and we need 1500 units

ord (num or letter)
chr(num) - ANSWERord gives back a number associated to whats in the ()
and chr gives back a letter

how to slice - ANSWER<string>[start:end:step size]

print(s1[::3])
print(s1[::-1])
print([7:]) - ANSWERprints every 3 letter
prints string backwards
prints characters 7 to the end

<string>.<method>(<inputs>) - ANSWERways to change strings

strip method - ANSWERremoves given characters from end of string

split method - ANSWERbreaks a string into sub strings at given place

join method - ANSWERbuilds one string from multiple

count method - ANSWERcount occurrences of sub string

find method - ANSWERfind position where a sub string occurs

right justify - ANSWERstr.rjust(s, width[, fillchar])
print (rstr.rjust(40, '-'))

left justify - ANSWERstr.ljust(s, width[, fillchar])
print (lstr.ljust(40, '-'))

#1.#2f - ANSWER#1 is how long the whole string can be
#2 length after the decimal

abs() - ANSWERtakes absolute value of # in ()

how to put a list in alphabetical order - ANSWERlyst.sort()

role of the else - ANSWERonly is tested when the if part is proven not to be true
CPU - ANSWERhandles basic instructions and allocates the more complicated tasks
to other specific chips to get them to do what they do best

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.
papersbyjol West Virginia
View profile
Follow You need to be logged in order to follow users or courses
Sold
421
Member since
2 year
Number of followers
253
Documents
13986
Last sold
1 week ago

3.8

72 reviews

5
27
4
18
3
17
2
2
1
8

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