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