text
stringlengths
1
3.55k
source
stringlengths
24
207
emb
listlengths
1.02k
1.02k
3. 1 • strings revisited 75 the amount was three, but other amounts ( besides 0 ) would work too. write a program that prompts the user to input the following two values ( example input in bold ) : enter a 3 - letter word : cat shift by how many letters? 3 the program should then shift each letter of the word by the de...
openstax_introduction_to_python_programming_-_web
[ 0.04267246648669243, 0.011505253612995148, -0.0005956236273050308, 0.016058465465903282, -0.04374128207564354, -0.03109278343617916, 0.006749988999217749, 0.0265305545181036, -0.03477020189166069, 0.057637300342321396, 0.05994594469666481, -0.01382068358361721, -0.0008063149871304631, -0.0...
3. 2 formatted strings learning objectives by the end of this section you should be able to • use f - strings to simplify output with multiple values. • format numbers with leading zeros and fixed precision. f - strings a formatted string literal ( or f - string ) is a string literal that is prefixed with " f " or " f ...
openstax_introduction_to_python_programming_-_web
[ -0.011580749414861202, -0.031545523554086685, 0.029086904600262642, 0.014831303618848324, -0.02743597887456417, -0.021640367805957794, 0.009433812461793423, -0.024678362533450127, -0.024914810433983803, 0.055598679929971695, 0.028797732666134834, 0.011958794668316841, 0.025004398077726364, ...
x } + { y } = { x + y } " ) formatting numbers programs often need to display numbers in a specific format. ex : when displaying the time, minutes are formatted as two - digit integers. if the hour is 9 and the minute is 5, then the time is " 9 : 05 " ( not " 9 : 5 " ). in an f - string, a replacement field may include...
openstax_introduction_to_python_programming_-_web
[ 0.03635725378990173, 0.004367008339613676, 0.02180972509086132, -0.022660398855805397, -0.021016430109739304, 0.00689576705917716, 0.04310687631368637, 0.0005404564435593784, -0.01634063571691513, 0.07487095892429352, 0.020619405433535576, -0.010153988376259804, 0.03299428150057793, 0.0087...
3. 2 • formatted strings 77 format description example result f fixed - point ( default is 6 decimal places ). f " { math. pi : f } "'3. 141593 '. 4f fixed - point, rounded to 4 decimal places. f " { math. pi :. 4f } "'3. 1416'8. 4f fixed - point, rounded to 4 decimal places, at least 8 characters wide. f " { math. pi ...
openstax_introduction_to_python_programming_-_web
[ 0.01160591933876276, -0.03301782160997391, 0.04183780401945114, -0.0159776508808136, -0.0566730760037899, -0.0016140842344611883, 0.04243546724319458, 0.00834362767636776, -0.03595716878771782, 0.04909636080265045, 0.033963873982429504, -0.006791276391595602, 0.01791420206427574, 0.0234614...
b.,. 2f c., d. 2f try it mad lib ( f - string ) a mad lib ( https : / / openstax. org / r / 100fstring ) is a funny story that uses words provided by a user. the following mad lib is based on four words ( user input in bold ) : enter a name : buster enter a noun : dog 78 3 • objects access for free at openstax. org ent...
openstax_introduction_to_python_programming_-_web
[ 0.04733632877469063, -0.01341676339507103, 0.012621992267668247, -0.021831907331943512, -0.028166910633444786, -0.016165582463145256, 0.021370191127061844, 0.009699167683720589, 0.002107896376401186, 0.05402731895446777, 0.01650344394147396, 0.0168144591152668, 0.040183428674936295, -0.006...
. org / books / introduction - python - programming / pages / 3 - 2 - formatted - strings ) 3. 3 variables revisited learning objectives by the end of this section you should be able to • distinguish between variables, objects, and references. • draw memory diagrams with integers, floats, and strings.
openstax_introduction_to_python_programming_-_web
[ 0.02041262947022915, -0.03304167091846466, 0.025365212932229042, -0.07946845144033432, -0.030391385778784752, -0.035746753215789795, 0.036113474518060684, 0.0011697380105033517, -0.012133244425058365, 0.06268332898616791, 0.010163032449781895, -0.0038428129628300667, 0.024802593514323235, ...
3. 3 • variables revisited 79 references to objects in python, every variable refers to an object. the assignment statement message = " hello " makes the variable message refer to the object " hello ". multiple variables may refer to the same object. ex : greeting = message makes greeting refer to the same object as me...
openstax_introduction_to_python_programming_-_web
[ 0.015794429928064346, -0.01797308400273323, -0.0033391991164535284, -0.03277470916509628, -0.024467594921588898, -0.044602081179618835, 0.019263451918959618, 0.009081819094717503, -0.008469128049910069, 0.05501983314752579, 0.0012471844675019383, -0.008320804685354233, -0.001232618698850274,...
and a value : • an object's identity is a unique integer associated with the object. generally, this integer refers to the memory location where the object is stored. once created, an object's identity never changes. the built - in id ( ) function returns the object's identity. • an object's type determines the possibl...
openstax_introduction_to_python_programming_-_web
[ -0.02128985896706581, -0.016667649149894714, -0.03603694960474968, -0.04079553857445717, -0.02333555370569229, -0.05392232909798622, 0.010323502123355865, -0.012407459318637848, -0.012611046433448792, 0.050328247249126434, 0.016295431181788445, 0.009443099610507488, 0.0077713546343147755, ...
3. 3 • variables revisited 81 exploring further as shown in a memory diagram, variables and objects are two separate ideas. calling a function like id ( ) or type ( ) returns information about an object, not a variable. in fact, a variable doesn't have an identity or a type, as shown in this example : > > > rating = 10...
openstax_introduction_to_python_programming_-_web
[ 0.018220560625195503, -0.012959904037415981, -0.006655164062976837, -0.05251769348978996, -0.03651002421975136, -0.06303898990154266, 0.03299461677670479, -0.0032542222179472446, -0.03951430693268776, 0.05431467294692993, 0.03321317210793495, 0.012135779485106468, 0.002758926013484597, -0....
which object does each variable reference?
openstax_introduction_to_python_programming_-_web
[ 0.013016772456467152, 0.0015051389345899224, 0.03351130336523056, -0.046059735119342804, -0.01707194559276104, -0.0423961877822876, 0.02784954197704792, 0.02624858357012272, 0.01129495445638895, 0.047227755188941956, 0.05089529976248741, 0.016016455367207527, 0.0004060168575961143, -0.0123...
3. 4 list basics learning objectives by the end of this section you should be able to • use indexes to access individual elements in a list. • use indexes to modify individual elements in a list. • use len ( ) function to find the length of a list. • demonstrate that lists can be changed after creation. lists a list ob...
openstax_introduction_to_python_programming_-_web
[ 0.01080884225666523, 0.003369996789842844, 0.02833082340657711, -0.017902111634612083, -0.031126409769058228, -0.013218224048614502, -0.011838969774544239, -0.024486146867275238, 0.024539535865187645, 0.08605370670557022, 0.026881014928221703, 0.032377224415540695, 0.028709521517157555, -0...
3. 4 • list basics 83 2. which of the following is not a valid way to specify a list in python? a. my _ list = [ 2, 2 3, 23 ] b. my _ list = [ " jimmy ", 2, " times " ] c. my _ list = [ " c ", " c + + ", " python ", " java ", " rust ", " scala " ] using indexes individual list elements can be accessed directly using an...
openstax_introduction_to_python_programming_-_web
[ 0.025819696485996246, -0.006312133278697729, 0.015527810901403427, -0.01407494768500328, -0.01072610542178154, 0.0005584415630437434, 0.005922670941799879, -0.0196195300668478, -0.018299667164683342, 0.10054155439138412, 0.026014797389507294, -0.0078092603944242, 0.020565925166010857, -0.0...
7 8 # print the 4th element in the list 9 # the number 3 is used to refer to the 4th element 10 print ( " 4th element : ", num _ list [ 3 ] ) 11 12 # the desired value of the 4th element is actually 7 13 # update the value of the 4th element to 7 14 num _ list [ 3 ] = 7 15 16 # the list of the first 5 prime numbers 17 ...
openstax_introduction_to_python_programming_-_web
[ 0.032845839858055115, -0.005989777855575085, 0.02224740758538246, 0.004345225635915995, -0.020096438005566597, -0.02972976490855217, -0.01164343860000372, -0.023819010704755783, 0.010314792394638062, 0.07189033180475235, 0.029327895492315292, 0.014099153690040112, 0.03295915946364403, -0.0...
you should be able to • describe the features and benefits of a tuple. • develop a program that creates and uses a tuple successfully. • identify and discuss the mutability of a tuple. creating tuples and accessing elements a tuple is a sequence of comma separated values that can contain elements of different types. a ...
openstax_introduction_to_python_programming_-_web
[ 0.007884901016950607, 0.00116440758574754, 0.006745192222297192, -0.03103049471974373, -0.023977983742952347, -0.017627937719225883, -0.00001168589460576186, 0.006409513298422098, 0.024581944569945335, 0.06954621523618698, 0.0037160178180783987, 0.0015223169466480613, 0.004940873011946678, ...
3. 5 • tuple basics 85 each element is accessed by index, starting with the first element at index 0. tuple _ 1 = ( 2, 3, 4 ) print ( f'tuple _ 1 : { tuple _ 1 }') print ( tuple _ 1 [ 1 ] ) print ( ) data _ 13 = ('aimee perry ', 96, [ 94, 100, 97, 93 ] ) print ( f'data _ 13 : { data _ 13 }') print ( data _ 13 [ 2 ] ) t...
openstax_introduction_to_python_programming_-_web
[ -0.0009461998706683517, 0.003857764881104231, 0.01232319138944149, -0.04702119901776314, -0.02377282828092575, -0.03785576671361923, -0.024532685056328773, -0.020784763619303703, 0.010369028896093369, 0.10097900032997131, 0.006816574838012457, 0.026938414201140404, 0.05066453292965889, -0....
lists are mutable. checkpoint mutability of a tuple vs. a list access multimedia content ( https : / / openstax. org / books / introduction - python - programming / pages / 3 - 5 - tuple - basics ) 86 3 • objects access for free at openstax. org concepts in practice using tuples 4. consider the final program in the exa...
openstax_introduction_to_python_programming_-_web
[ 0.001531305257230997, 0.0025124235544353724, 0.02424570545554161, -0.014551998116075993, -0.0611695796251297, -0.058468494564294815, -0.03730180859565735, -0.0169491209089756, 0.01418377086520195, 0.10490164905786514, 0.002204267540946603, -0.006124482955783606, 0.056584905833005905, -0.02...
pages / 3 - 5 - tuple - basics ) try it creating a tuple with user input write a program that reads in two strings and two integers from input and creates a tuple, my _ data, with the four values. given input : 3. 5 • tuple basics 87 x y 15 20 the output is : my _ data : ('x ','y ', 15, 20 ) access multimedia content (...
openstax_introduction_to_python_programming_-_web
[ 0.024465590715408325, 0.012735257856547832, 0.04033408313989639, -0.032013263553380966, -0.06801770627498627, -0.031997550278902054, 0.029468799009919167, 0.001183828222565353, 0.0076043009757995605, 0.0819607749581337, 0.01942008174955845, -0.030080057680606842, 0.018063507974147797, -0.0...
3. 6 chapter summary highlights from this chapter include : • a string is a sequence of values that represents unicode code points. • an index refers to the position of a value in a sequence ( string, list, tuple ). • positive indexes range from 0 to length – 1. negative indexes range from – 1 to – length. • f - string...
openstax_introduction_to_python_programming_-_web
[ -0.015681082382798195, -0.00896517001092434, 0.033479202538728714, -0.0206864345818758, -0.038079921156167984, -0.04481910541653633, 0.031293775886297226, -0.013997629284858704, 0.01666504703462124, 0.07401814311742783, 0.010762837715446949, 0.009161255322396755, 0.009404083713889122, -0.0...
last element ( " c " ) of my _ tuple. table 3. 5 chapter 3 reference. 3. 6 • chapter summary 89 90 3 • objects access for free at openstax. org figure 4. 1 credit : modification of work " fork in the road ", by ian sane / flickr, cc by 2. 0 chapter outline 4. 1 boolean values 4. 2 if - else statements 4. 3 boolean oper...
openstax_introduction_to_python_programming_-_web
[ 0.025241820141673088, -0.009965667501091957, 0.0055537717416882515, -0.02203272469341755, -0.02450682781636715, -0.03631362318992615, 0.021771874278783798, 0.01963399164378643, -0.030236197635531425, 0.10353344678878784, 0.004795512650161982, 0.009019707329571247, 0.03384152799844742, -0.0...
4. 1 boolean values learning objectives by the end of this section you should be able to • explain a boolean value. • use bool variables to store boolean values. • demonstrate converting integers, floats, and strings to booleans. • demonstrate converting booleans to integers, floats, and strings. • use comparison opera...
openstax_introduction_to_python_programming_-_web
[ 0.04921823740005493, -0.000355456315446645, 0.021817723289132118, -0.005333443637937307, -0.038098983466625214, -0.033148542046546936, 0.035209089517593384, -0.015699870884418488, -0.006635183468461037, 0.044290266931056976, 0.026669621467590332, -0.01135272067040205, 0.018119970336556435, ...
what is the output? a. < class'bool'> b. < class'int'> c. error type conversion with bool ( ) deciding whether a value is true or false is helpful when writing programs / statements based on decisions. converting data types to booleans can seem unintuitive at first. ex : is " ice cream " true? but the conversion is act...
openstax_introduction_to_python_programming_-_web
[ -0.0039602783508598804, 0.00010619375098031014, 0.006443419493734837, -0.010616994462907314, -0.040136225521564484, -0.053869958966970444, 0.050276026129722595, -0.02527136728167534, -0.022786343470215797, 0.07639802247285843, -0.006111542694270611, -0.000560392567422241, 0.01137940306216478...
1. 0 13. str ( is _ on ) a. " is _ on " b. " true " 14. int ( is _ on ) a. 0 b. 1 comparison operators programmers often have to answer questions like " is the current user the admin? " a programmer may want to compare a string variable, user, to the string, " admin ". comparison operators are used to compare values, a...
openstax_introduction_to_python_programming_-_web
[ 0.02144760638475418, -0.034133441746234894, 0.01057861652225256, -0.010497456416487694, -0.00785330031067133, -0.04582701250910759, 0.00879688560962677, -0.010998633690178394, -0.008170729503035545, 0.06435850262641907, 0.00781796034425497, 0.008264011703431606, 0.030712829902768135, -0.01...
. false 20. a = " dog " compare _ result = ( a < " cat " ) a. true b. false
openstax_introduction_to_python_programming_-_web
[ 0.04162738844752312, -0.029545441269874573, 0.02130017802119255, -0.02225004881620407, -0.03949296846985817, -0.02759508602321148, 0.015286696143448353, 0.02128417417407036, -0.03281911462545395, 0.07738849520683289, 0.039856888353824615, 0.01810566335916519, 0.003342739539220929, -0.00516...
4. 1 • boolean values 95 = vs = = a common mistake is using = for comparison instead of = =. ex : is _ zero = num = 0 will always assign is _ zero and num with 0, regardless of num's original value. the = operator performs assignment and will modify the variable. the = = operator performs comparison, does not modify th...
openstax_introduction_to_python_programming_-_web
[ 0.03673194348812103, -0.012683768756687641, 0.005707483272999525, -0.03847842290997505, -0.022152790799736977, -0.030762605369091034, 0.04142018035054207, -0.013474400155246258, -0.0084026288241148, 0.05701707676053047, 0.02249721623957157, -0.00814543105661869, 0.04003898426890373, -0.017...
4. 2 if - else statements learning objectives by the end of this section you should be able to • identify which operations are performed when a program with if and if - else statements is run. • identify the components of an if and if - else statement and the necessary formatting. • create an if - else statement to per...
openstax_introduction_to_python_programming_-_web
[ -0.0030017842072993517, -0.009864912368357182, -0.0024112029932439327, -0.005558477248996496, -0.011457243002951145, -0.0013686500024050474, 0.02380078285932541, 0.0018525021150708199, -0.02680843323469162, 0.0659613087773323, 0.024368131533265114, 0.01859208382666111, 0.01617133803665638, ...
2. given the following, which lines execute if the condition is true? 1 print ( " have a great day. " ) 2 if is _ raining : 3 print ( " don't forget an umbrella! " ) 4 print ( " see you soon. " ) a. 1, 2, 3 b. 1, 2, 4 c. 1, 2, 3, 4 3. given the following ( same as above ), which lines execute if the condition is false?...
openstax_introduction_to_python_programming_-_web
[ 0.034096553921699524, -0.0007535660988651216, 0.007510327734053135, -0.018986718729138374, -0.01193138025701046, -0.02939424477517605, 0.03031165339052677, 0.02944059856235981, 0.028314772993326187, 0.0834774300456047, 0.01810302957892418, 0.044749218970537186, 0.009254214353859425, -0.011...
4. 2 • if - else statements 97 2 if is _ raining : 3 print ( " don't forget an umbrella! " ) 4 print ( " see you soon. " ) a. 1, 2, 3 b. 1, 2, 4 c. 1, 2, 3, 4 4. given num = - 10, what is the final value of num? if num < 0 : num = 25 if num < 100 : num = num + 50 a. - 10 b. 40 c. 75 5. given input 10, what is the final...
openstax_introduction_to_python_programming_-_web
[ 0.02325945720076561, 0.009498264640569687, -0.006755645386874676, -0.018445782363414764, -0.019734365865588188, -0.027063312008976936, 0.03040415793657303, 0.01596517115831375, -0.02571730501949787, 0.0764973908662796, 0.015154753811657429, 0.012576899491250515, 0.017148155719041824, -0.00...
introduction - python - programming / pages / 4 - 2 - if - else - statements ) concepts in practice exploring if - else statements 6. given the following code, the else branch is taken for which range of x? if x > = 15 : # do something else : # do something else a. x > = 15 b. x < = 15 c. x < 15 7. given x = 40, what i...
openstax_introduction_to_python_programming_-_web
[ 0.039630744606256485, -0.006906057707965374, -0.007990272715687752, -0.017056766897439957, -0.035688478499650955, -0.033625658601522446, 0.0329318530857563, 0.052810363471508026, -0.006303845904767513, 0.08871050179004669, 0.012487107887864113, 0.012291107326745987, 0.009868185967206955, -...
4. 2 • if - else statements 99 try it improved division the following program divides two integers. division by 0 produces an error. modify the program to read in a new denominator ( with no prompt ) if the denominator is 0. access multimedia content ( https : / / openstax. org / books / introduction - python - program...
openstax_introduction_to_python_programming_-_web
[ -0.010787121951580048, -0.01113243866711855, -0.006405793596059084, 0.0002468776365276426, -0.036354079842567444, 0.007163277827203274, 0.031145701184868813, 0.004905893467366695, -0.04426990821957588, 0.06955257803201675, -0.003393677994608879, -0.0016751560615375638, 0.012269055470824242, ...
4. 3 boolean operations learning objectives by the end of this section you should be able to • explain the purpose of logical operators. • describe the truth tables for and, or, and not. • create expressions with logical operators. • interpret if - else statements with conditions using logical operators. logical operat...
openstax_introduction_to_python_programming_-_web
[ 0.03574465587735176, -0.0105004096403718, 0.008638023398816586, -0.0006371500785462558, -0.02822992019355297, -0.025499925017356873, -0.004573837388306856, 0.011997717432677746, -0.03866223245859146, 0.07586845755577087, 0.015541445463895798, 0.008105301298201084, 0.009486355818808079, -0....
0 b. 5
openstax_introduction_to_python_programming_-_web
[ 0.03156757354736328, -0.008397177793085575, 0.017188705503940582, 0.01145925559103489, -0.02378932014107704, -0.04384171962738037, 0.027554864063858986, 0.025562606751918793, -0.04234042763710022, 0.03615225851535797, 0.034330807626247406, -0.015364477410912514, -0.008968334645032883, 0.01...
4. 3 • boolean operations 101 logical operator : or sometimes a decision only requires one condition to be true. ex : if a student is in the band or choir, they will perform in the spring concert. the or operator takes two condition operands and returns true if either condition is true. p q p or q true true true true f...
openstax_introduction_to_python_programming_-_web
[ 0.008824224583804607, -0.028248777613043785, -0.004718292038887739, 0.024770589545369148, -0.030236005783081055, -0.03535657748579979, 0.0015656244941055775, -0.00806654803454876, -0.01204349659383297, 0.07929083704948425, 0.020139401778578758, 0.002769813407212496, 0.026927929371595383, -...
p true false false true table 4. 3 truth table : not p. checkpoint example : diving warning access multimedia content ( https : / / openstax. org / books / introduction - python - programming / pages / 4 - 3 - boolean - operations ) concepts in practice using the not operator 8. given x = 13, what is the value of not (...
openstax_introduction_to_python_programming_-_web
[ 0.02711441181600094, 0.011187261901795864, -0.001832120819017291, 0.006636038888245821, -0.015599179081618786, -0.01729607582092285, 0.013147585093975067, 0.007408926263451576, -0.014233317226171494, 0.0920143648982048, 0.005995469633489847, 0.036406632512807846, 0.01926223561167717, -0.03...
4. 4 operator precedence learning objectives by the end of this section you should be able to • describe how precedence impacts order of operations. • describe how associativity impacts order of operations. • explain the purpose of using parentheses in expressions with multiple operators. precedence when an expression ...
openstax_introduction_to_python_programming_-_web
[ 0.006756278220564127, -0.025762425735592842, -0.03560376167297363, 0.0005016149370931089, -0.017427518963813782, -0.032023921608924866, 0.01704340986907482, 0.010418295860290527, -0.06401072442531586, 0.05993351712822914, -0.0035873581655323505, 0.053590383380651474, -0.02880307473242283, ...
3 is evaluated as ( 8 / 4 ) * 3 rather than 8 / ( 4 * 3 ) because multiplication and division are left associative. most operators are left associative and are evaluated from left to right. exponentiation is the main exception ( noted above ) and is right associative : that is, evaluated from right to left. ex : 2 * * ...
openstax_introduction_to_python_programming_-_web
[ -0.008377502672374249, -0.032551221549510956, -0.019704757258296013, -0.02249331586062908, -0.004888501483947039, -0.023615926504135132, 0.014492637477815151, -0.004814278334379196, -0.03291136026382446, 0.061846304684877396, 0.011530010029673576, 0.03296684846282005, -0.0018692752346396446,...
4. 4 • operator precedence 105 comparisons and evaluated from left to right. ex. 10 < x < = 20 is evaluated as 10 < x and x < = 20. checkpoint operation precedence access multimedia content ( https : / / openstax. org / books / introduction - python - programming / pages / 4 - 4 - operator - precedence ) concepts in pr...
openstax_introduction_to_python_programming_-_web
[ 0.022431913763284683, -0.032431162893772125, -0.002262769266963005, 0.010084741748869419, -0.01638629101216793, -0.04437151178717613, -0.006462516263127327, 0.0150687200948596, -0.059345897287130356, 0.09135690331459045, 0.0030184409115463495, 0.04200011119246483, -0.013183174654841423, -0...
given x = 8 and y = 9, what is the result of the following? ( x + 3 ) * ( y - 5 ) a. 30 b. 44 c. 94 pep 8 recommendations : spacing around operators the pep 8 style guide recommends consistent spacing around operators to avoid extraneous and confusing whitespace. • avoid multiple spaces and an unequal amount of whitesp...
openstax_introduction_to_python_programming_-_web
[ 0.0181440319865942, -0.0005419873050414026, 0.013354603201150894, -0.004528602119535208, -0.020993169397115707, -0.04373374581336975, 0.02872849628329277, 0.03649932146072388, -0.04133192449808121, 0.0693972036242485, 0.01971866749227047, 0.018279513344168663, -0.039042890071868896, -0.008...
4. 5 • chained decisions 107 two separate if statements do not guarantee that only one branch is taken and might result in both branches being taken. ex : the program below attempts to add a curve based on the input test score. if the input is 60, both if statements are incorrectly executed, and the resulting score is ...
openstax_introduction_to_python_programming_-_web
[ 0.011201244778931141, -0.0030808330047875643, 0.005756700411438942, 0.000001748452291394642, -0.054543908685445786, -0.021256152540445328, -0.0048847864381968975, 0.03013276308774948, 0.004925959277898073, 0.07164070010185242, -0.0019044163636863232, 0.006456990260630846, 0.00826815329492092...
_ _ _ _ : # body 2 a. x < 0 x = = 0 b. x = = 0 x < 0 c. x < = 0 [ no condition ] 4. which of the following is a valid chained decision statement? a. if condition _ 1 : # body 1 elif condition _ 2 : # body 2 b. if condition _ 1 : # body 1 elif condition _ 2 : # body 2 c. elif condition _ 1 : # body 1 if condition _ 2 : ...
openstax_introduction_to_python_programming_-_web
[ 0.03921620175242424, -0.007307789288461208, 0.025844376534223557, -0.02241128496825695, -0.027051584795117378, -0.038700301200151443, 0.017545944079756737, 0.045194853097200394, -0.03855288773775101, 0.05958325415849686, 0.01664755679666996, 0.036620475351810455, 0.016587940976023674, -0.0...
4. 5 • chained decisions 109 elif attendees < = 400 : rooms + = 14 a. 4 b. 15 c. 18 if - elif - else statements elifs can be chained with an if - else statement to create a more complex decision statement. ex : a program shows possible chess moves depending on the piece type. if the piece is a pawn, show moving forward...
openstax_introduction_to_python_programming_-_web
[ 0.028121644631028175, -0.0009029602515511215, -0.014919881708920002, 0.013685505837202072, -0.031557630747556686, -0.020927049219608307, -0.01514588575810194, 0.04382932186126709, -0.02897791564464569, 0.05689610168337822, 0.012593474239110947, 0.034084416925907135, 0.013509523123502731, -...
< 9. 99 : order = 50 if 9. 99 < = price < 19. 99 : order = 30 if price > = 19. 99 : order = 10 a. if price < 9. 99 : order = 50 else : order = 30 order = 10 b. if price < 9. 99 : order = 50 elif price < 19. 99 : order = 30 elif price = = 19. 99 : order = 10 c. if price < 9. 99 : order = 50
openstax_introduction_to_python_programming_-_web
[ 0.0138130197301507, 0.03632330149412155, -0.026840142905712128, -0.010427741333842278, -0.025770077481865883, -0.026639586314558983, 0.05355469509959221, 0.06273137032985687, -0.026094816625118256, 0.08014284074306488, -0.018204981461167336, 0.044213131070137024, -0.025696197524666786, -0....
4. 5 • chained decisions 111 elif price < 19. 99 : order = 30 else : order = 10 try it crochet hook size conversion write a program that reads in a crochet hook's us size and computes the metric diameter in millimeters. ( a subset of sizes is used. ) if the input does not match b - g, the diameter should be assigned wi...
openstax_introduction_to_python_programming_-_web
[ 0.012036148458719254, -0.0328214056789875, -0.013673322275280952, 0.010852833278477192, -0.03851540759205818, 0.019936181604862213, 0.010446972213685513, 0.004794412758201361, -0.008704764768481255, 0.08698727190494537, 0.045670028775930405, 0.00009171571582555771, -0.01254426408559084, -0...
4. 6 nested decisions learning objectives by the end of this section you should be able to • describe the execution paths of programs with nested if - else statements. • implement a program with nested if - else statements. nested decision statements suppose a programmer is writing a program that reads in a game id and...
openstax_introduction_to_python_programming_-_web
[ 0.023255156353116035, 0.0041597336530685425, 0.005526395980268717, -0.03967064991593361, -0.013591128401458263, -0.03828882798552513, -0.005253068171441555, 0.0005431652534753084, -0.030965205281972885, 0.07451025396585464, 0.0037475700955837965, 0.024850578978657722, 0.010488368570804596, ...
4. 6 • nested decisions 113 if players < 3 : print ( " not enough players " ) elif players > 6 : print ( " too many players " ) else : print ( " ready to start " ) # test game ids 3 - end checkpoint example : poisonous plant identification access multimedia content ( https : / / openstax. org / books / introduction - p...
openstax_introduction_to_python_programming_-_web
[ 0.038557540625333786, 0.00661257840692997, 0.013026350177824497, -0.017282122746109962, -0.00677988538518548, -0.03342616930603981, 0.003882657503709197, 0.02389121986925602, 0.0030794560443609953, 0.06545908749103546, 0.014182552695274353, 0.018161745741963387, 0.013776730746030807, 0.004...
: # body 4 else : # body 5 a. body 2 b. body 3 c. error try it meal orders write a program that reads in a string, " lunch " or " dinner ", representing the menu choice, and an integer, 1, 2, or 3, representing the user's meal choice. the program then prints the user's meal choice. lunch meal options • 1 : caesar salad...
openstax_introduction_to_python_programming_-_web
[ 0.006258387118577957, -0.02603794075548649, -0.004452172201126814, -0.02777954377233982, -0.035367392003536224, -0.027713920921087265, 0.022109966725111008, 0.03332192078232765, 0.005327774211764336, 0.057009559124708176, 0.012776343151926994, 0.021699748933315277, 0.045101847499608994, -0...
4. 7 conditional expressions learning objectives by the end of this section you should be able to • identify the components of a conditional expression. • create a conditional expression. conditional expressions a conditional expression ( also known as a " ternary operator " ) is a simplified, single - line version of ...
openstax_introduction_to_python_programming_-_web
[ -0.007203628774732351, 0.0025076179299503565, -0.007204639259725809, -0.010376065038144588, -0.030361615121364594, -0.05695559084415436, 0.03562067821621895, 0.004106029402464628, -0.054423168301582336, 0.06387031078338623, 0.010870512574911118, 0.021452736109495163, 0.003200206672772765, ...
x < y else min _ num = y a. min _ num = x b. x < y c. min _ num = y 4. which of the following is an improved version of the following if - else statement? if x < 50 : result = true else : result = false a. result = true if x < 50 else false b. result = x < 50 5. what are the possible values of total? total = fee + 10 i...
openstax_introduction_to_python_programming_-_web
[ -0.010384391993284225, 0.007368412334471941, -0.0065018110908567905, 0.006878018379211426, -0.01632048189640045, -0.02983071282505989, 0.029332300648093224, -0.003860871074721217, -0.010333935730159283, 0.08002042025327682, 0.009982038289308548, -0.00007907785766292363, -0.006255003623664379...
4. 8 chapter summary highlights from this chapter include : • booleans represent a value of true or false. • comparison operators compare values and produce true or false. • logical operators take condition operand ( s ) and produce true or false. • operators are evaluated in order according to precedence and associati...
openstax_introduction_to_python_programming_-_web
[ 0.0031990495044738054, -0.01571095921099186, 0.022808032110333443, -0.024264832958579063, -0.00029020156944170594, -0.04006021097302437, 0.0023745859507471323, -0.000674346461892128, -0.03925386443734169, 0.07766035944223404, 0.017089303582906723, 0.019307656213641167, 0.005561823025345802, ...
x is less than or equal to y and false otherwise. ex : 8 < = 7 is false. table 4. 5 chapter 4 reference. 118 4 • decisions access for free at openstax. org function description x and y ( logical ) evaluates the boolean values of x and y and returns true if both are true. ex : true and false is false. x or y ( logical )...
openstax_introduction_to_python_programming_-_web
[ 0.00936308316886425, -0.023953240364789963, 0.017207369208335876, -0.029719524085521698, -0.015130856074392796, -0.04415763169527054, 0.007390802260488272, -0.02972131036221981, -0.029887767508625984, 0.0810294970870018, 0.03515322506427765, 0.01773061789572239, 0.004749329760670662, -0.04...
if the phone is idle. once the time set by a user is reached, the phone is locked. loops can also be used for iterating over lists like student names in a roster, and printing the names one at a time. in this chapter, two types of loops, for loop and while loop, are introduced. this chapter also introduces break and co...
openstax_introduction_to_python_programming_-_web
[ -0.017807457596063614, -0.006412170361727476, -0.0003819946723524481, -0.00609206547960639, -0.0005041623953729868, -0.030716516077518463, -0.013789410702884197, -0.028232358396053314, 0.03601568564772606, 0.08118676394224167, 0.014005332253873348, 0.04998142272233963, 0.03122413344681263, ...
5. 1 while loop learning objectives by the end of this section you should be able to • explain the loop construct in python. • use a while loop to implement repeating tasks. while loop a while loop is a code construct that runs a set of statements, known as the loop body, while a given condition, known as the loop expr...
openstax_introduction_to_python_programming_-_web
[ 0.01815088465809822, -0.003115435130894184, 0.006851667072623968, -0.009165436960756779, 0.000993429566733539, -0.029678696766495705, -0.034347571432590485, 0.0046335244551301, 0.009879986755549908, 0.07125881314277649, 0.018162673339247704, -0.029588598757982254, 0.027463210746645927, -0....
values in the output? a. 1 1 2 3 5 8 13 b. 1 2 3 5 8 13 c. 1 1 2 3 5 8 13 21 122 5 • loops access for free at openstax. org counting with a while loop a while loop can be used to count up or down. a counter variable can be used in the loop expression to determine the number of iterations executed. ex : a programmer may...
openstax_introduction_to_python_programming_-_web
[ 0.027018243446946144, 0.013017813675105572, 0.014469227753579617, 0.004095892887562513, -0.028919754549860954, -0.027450162917375565, -0.004217294976115227, 0.019779881462454796, -0.00834500603377819, 0.08652298897504807, -0.00949216727167368, 0.018268423154950142, 0.00014261400792747736, ...
5. 1 • while loop 123 4. how many times does the loop execute? a. 3 b. 4 c. 5 5. which line is printed as the last line of output? a. value of n after the loop is - 1. b. value of n after the loop is 0. c. value of n after the loop is 1. 6. what happens if the code is changed as follows? n = 4 while n > 0 : print ( n )...
openstax_introduction_to_python_programming_-_web
[ 0.005627610255032778, 0.011629829183220863, 0.004338409285992384, 0.0027577339205890894, 0.022709939628839493, -0.04372575879096985, -0.020136477425694466, -0.01099261362105608, 0.004762343596667051, 0.07535941898822784, -0.0013535277685150504, 0.016059502959251404, 0.014856846071779728, -...
5. 2 for loop learning objectives by the end of this section you should be able to • explain the for loop construct. • use a for loop to implement repeating tasks. for loop in python, a container can be a range of numbers, a string of characters, or a list of values. to access objects within a container, an iterative l...
openstax_introduction_to_python_programming_-_web
[ -0.0021350053139030933, -0.009231802076101303, 0.023978635668754578, -0.0204647034406662, -0.02447773702442646, -0.03132198750972748, 0.023023642599582672, -0.01345052383840084, 0.018365295603871346, 0.06833013892173767, 0.014487052336335182, -0.02160673588514328, 0.013229696080088615, 0.0...
5. 2 • for loop 125 str _ var = " a string " count = 0 for c in str _ var : count + = 1 # new line print ( c, end ='*') print ( count ) a. a string * b. a * s * t * r * i * n * g * c. a * * s * t * r * i * n * g * range ( ) function in for loop a for loop can be used for iteration and counting. the range ( ) function i...
openstax_introduction_to_python_programming_-_web
[ 0.01065808068960905, -0.013079782947897911, 0.043216634541749954, 0.022690562531352043, -0.023848440498113632, -0.022848213091492653, -0.01468066219240427, 0.004316995851695538, -0.017732437700033188, 0.08789891004562378, 0.019831856712698936, -0.027180058881640434, -0.003205574583262205, ...
2 table 5. 1 using the range ( ) function. example 5. 2 two programs printing all integer multiples of 5 less than 50 ( notice the compactness of the for construction compared to the while ) # for loop condition using # range ( ) function to print # all multiples of 5 less than 50 for i in range ( 0, 50, 5 ) : print ( ...
openstax_introduction_to_python_programming_-_web
[ 0.039896681904792786, -0.011495406739413738, 0.019169526174664497, 0.011189831420779228, -0.008862144313752651, -0.009572888724505901, -0.003421303816139698, 0.018710406497120857, -0.02241070754826069, 0.0900086909532547, 0.026256656274199486, -0.007818699814379215, -0.013762222602963448, ...
5. 2 • for loop 127 6. what is the sequence generated from range ( - 1, - 2, - 1 )? a. 1 b. - 1, - 2 c. - 2 7. what is the output of the range ( 1, 2, - 1 )? a. 1 b. 1, 2 c. empty sequence 8. what is the output of range ( 5, 2 )? a. 0, 2, 4 b. 2, 3, 4 c. empty sequence try it counting spaces write a program using a for...
openstax_introduction_to_python_programming_-_web
[ -0.010845625773072243, 0.0026252157986164093, 0.012497383169829845, 0.014596162363886833, -0.007511742413043976, -0.030073823407292366, -0.009318070486187935, 0.009102419018745422, -0.022455129772424698, 0.11476198583841324, -0.009020021185278893, 0.018327906727790833, -0.008281072601675987,...
5. 3 nested loops learning objectives by the end of this section you should be able to • implement nested while loops. • implement nested for loops. nested loops a nested loop has one or more loops within the body of another loop. the two loops are referred to as outer loop and inner loop. the outer loop controls the n...
openstax_introduction_to_python_programming_-_web
[ 0.015264593996107578, 0.021890787407755852, -0.021813277155160904, -0.04676113277673721, -0.01459090318530798, -0.023616882041096687, -0.036900267004966736, -0.007980385795235634, 0.0017949779285117984, 0.09069233387708664, 0.014603415504097939, 0.04109228029847145, 0.00912356749176979, -0...
5. 3 • nested loops 129 concepts in practice nested while loop question set 1. given the following code, how many times does the print statement execute? i = 1 while i < = 5 : j = 1 while i + j < = 5 : print ( i, j ) j + = 1 i + = 1 a. 5 b. 10 c. 25 2. what is the output of the following code? i = 1 while i < = 2 : j =...
openstax_introduction_to_python_programming_-_web
[ 0.016320088878273964, -0.006955244112759829, -0.005278217606246471, -0.027796324342489243, 0.01033781562000513, -0.028379473835229874, -0.029310444369912148, -0.01459711417555809, 0.006773181725293398, 0.08055169880390167, -0.013683347031474113, 0.038240402936935425, 0.019189126789569855, ...
##s over different courses, and the inner loop iterates over the names in each course roster. checkpoint nested for loops access multimedia content ( https : / / openstax. org / books / introduction - python - programming / pages / 5 - 3 - nested - loops ) concepts in practice nested loop practices 4. given the followi...
openstax_introduction_to_python_programming_-_web
[ 0.020100943744182587, -0.01687052473425865, -0.019382959231734276, -0.001302457763813436, -0.004282960668206215, -0.02309979684650898, -0.03711891919374466, -0.014214780181646347, 0.006033692043274641, 0.08571101725101471, 0.021451879292726517, 0.040294256061315536, 0.035640280693769455, -...
5. 3 • nested loops 131 for j in range ( 4 ) : print ( i,'', j ) a. 4 b. 12 c. 20 6. which program prints the following output? 0 1 2 3 0 2 4 6 0 3 6 9 a. for i in range ( 4 ) : for j in range ( 4 ) : print ( i * j, end ='' ) print ( ) b. for i in range ( 1, 4 ) : for j in range ( 4 ) : print ( i * j ) c. for i in rang...
openstax_introduction_to_python_programming_-_web
[ 0.0217405054718256, -0.0017732791602611542, -0.011523953638970852, -0.023864269256591797, 0.005089758895337582, -0.01794186420738697, -0.030308907851576805, -0.02384216897189617, 0.008122975938022137, 0.10059716552495956, 0.0002488014870323241, 0.032258447259664536, 0.000854683923535049, -...
while and for loops : * * * * * * * * * * + + + + + + + + + + access multimedia content ( https : / / openstax. org / books / introduction - python - programming / pages / 5 - 3 - nested - loops ) 5. 4 break and continue learning objectives by the end of this section you should be able to • analyze a loop's execution w...
openstax_introduction_to_python_programming_-_web
[ 0.038886573165655136, 0.004423054866492748, -0.017060238867998123, -0.02377796731889248, 0.02182742767035961, -0.024402152746915817, -0.03923926129937172, -0.007093168795108795, 0.02127690240740776, 0.07787371426820755, -0.01562606915831566, 0.0569307804107666, 0.010181406512856483, -0.029...
5. 4 • break and continue 133 break a break statement is used within a for or a while loop to allow the program execution to exit the loop once a given condition is triggered. a break statement can be used to improve runtime efficiency when further loop execution is not required. ex : a loop that looks for the characte...
openstax_introduction_to_python_programming_-_web
[ -0.0019062247592955828, 0.007186313159763813, 0.01092421542853117, 0.026854196563363075, 0.007157540880143642, -0.04208545759320259, -0.0007561106467619538, -0.004180374089628458, -0.0003892286622431129, 0.08735483139753342, -0.006142400670796633, 0.019010957330465317, -0.013449639081954956,...
world c. h e l l o 2. given the following code, how many times does the print statement get executed? i = 1 while true : if i % 3 = = 0 and i % 5 = = 0 : print ( i ) break i + = 1 a. 0 b. 1 c. 15 3. what is the final value of i? i = 1 count = 0 while true : if i % 2 = = 0 or i % 3 = = 0 : count + = 1 if count > = 5 : p...
openstax_introduction_to_python_programming_-_web
[ 0.01923573575913906, -0.022957637906074524, -0.014745377004146576, -0.024533690884709358, 0.030280638486146927, -0.0218433178961277, -0.021949918940663338, -0.008203444071114063, 0.012105351313948631, 0.06439178436994553, 0.003523797495290637, 0.02056903764605522, 0.016306141391396523, -0....
5. 4 • break and continue 135 checkpoint continue statement in a while loop access multimedia content ( https : / / openstax. org / books / introduction - python - programming / pages / 5 - 4 - break - and - continue ) concepts in practice using a continue statement 4. given the following code, how many times does the ...
openstax_introduction_to_python_programming_-_web
[ 0.02976701222360134, 0.0080875214189291, 0.011078602634370327, 0.03604225069284439, 0.0475958026945591, -0.04272128641605377, -0.037177540361881256, -0.0061893099918961525, 0.02410144731402397, 0.07215394824743271, 0.002452563028782606, 0.03209618479013443, 0.02824466861784458, -0.03174512...
5. 5 loop else learning objectives by the end of this section you should be able to • use loop else statement to identify when the loop execution is interrupted using a break statement. • implement a loop else statement with a for or a while loop. loop else a loop else statement runs after the loop's execution is compl...
openstax_introduction_to_python_programming_-_web
[ -0.013035397045314312, 0.012894717045128345, -0.022384056821465492, 0.004946838598698378, -0.014224490150809288, -0.03419414535164833, -0.009020743891596794, 0.0009921836899593472, 0.014421417377889156, 0.0704428181052208, 0.018204456195235252, 0.011984573677182198, 0.011326237581670284, -...
5. 5 • loop else 137 the code prints " 10 is not in the list. ". numbers = [ 2, 5, 7, 11, 12 ] for i in numbers : if i = = 10 : print ( " found 10! " ) break else : print ( " 10 is not in the list. " ) numbers = [ 2, 5, 7, 11, 12 ] seen = false for i in numbers : if i = = 10 : print ( " found 10! " ) seen = true if see...
openstax_introduction_to_python_programming_-_web
[ 0.004313912242650986, 0.004339015576988459, -0.0007023841608315706, 0.019833121448755264, 0.0020426709670573473, -0.04598594084382057, -0.019387880340218544, 0.007553026080131531, -0.023399757221341133, 0.09243594110012054, 0.006144525948911905, 0.013927778229117393, 0.028073802590370178, ...
continue else : print ( " all numbers are less than 5. " ) a. 1 2 2 6 not all numbers are less than 5. b. 1 2 2 not all numbers are less than 5. c. 1 2 2 6 all numbers are less than 5. 5. 5 • loop else 139 try it sum of values less than 10 write a program that, given a list, calculates the sum of all integer values les...
openstax_introduction_to_python_programming_-_web
[ 0.01838091015815735, 0.01420830562710762, -0.012014965526759624, -0.005847242660820484, 0.02051641047000885, -0.05946383625268936, 0.02049199678003788, 0.029039522632956505, 0.011961940675973892, 0.05847344174981117, 0.012417293153703213, 0.013245257548987865, 0.017393680289387703, -0.0292...
5. 6 chapter summary highlights from this chapter include : • a while loop runs a set of statements, known as the loop body, while a given condition, known as the loop expression, is true. • a for loop can be used to iterate over elements of a container object. • a range ( ) function generates a sequence of integers be...
openstax_introduction_to_python_programming_-_web
[ -0.004273214377462864, -0.019754638895392418, 0.02063450962305069, -0.03695046901702881, 0.006428956985473633, -0.024983925744891167, -0.010979562997817993, 0.011003486812114716, 0.0042825499549508095, 0.08857883512973785, -0.003773024771362543, 0.02452779747545719, -0.0039518666453659534, ...
the loop table 5. 4 chapter 5 reference.
openstax_introduction_to_python_programming_-_web
[ 0.020847048610448837, -0.02275776118040085, 0.018746178597211838, 0.032013557851314545, -0.003977654036134481, -0.039743389934301376, -0.015379098244011402, -0.014955676160752773, 0.004482769872993231, 0.05721892789006233, 0.020298687741160393, 0.00045445660362020135, 0.005794691853225231, ...
5. 6 • chapter summary 141 function description continue statement # initialization while loop _ expression : # loop body if continue _ condition : continue # remaining body of loop # statements after the loop loop else statement # initialization for loop _ expression : # loop body if break _ condition : break # remain...
openstax_introduction_to_python_programming_-_web
[ 0.020372727885842323, -0.012423555366694927, 0.0005053714849054813, -0.014107155613601208, 0.017228178679943085, -0.020048096776008606, -0.013666262850165367, 0.009089327417314053, -0.007377914618700743, 0.04146831855177879, 0.013663612306118011, -0.009243185631930828, -0.004500102251768112,...
decisions chapter, functions allow different paths of execution through a program, and this chapter discusses control flow and the scope of variables in more detail.
openstax_introduction_to_python_programming_-_web
[ 0.017076928168535233, 0.005599632393568754, 0.02403266914188862, -0.025921616703271866, -0.031799353659152985, -0.013268917798995972, -0.012627104297280312, 0.003591977758333087, -0.012988532893359661, 0.05133023485541344, 0.0219215489923954, 0.041133105754852295, 0.012744669802486897, -0....
6. 1 defining functions learning objectives by the end of this section you should be able to • identify function calls in a program. • define a parameterless function that outputs strings. • describe benefits of using functions. functions 6 calling a function throughout the book, functions have been called to perform t...
openstax_introduction_to_python_programming_-_web
[ 0.01651611179113388, 0.00948853325098753, -0.007426450029015541, -0.008938907645642757, -0.010764390230178833, -0.002836920553818345, -0.016514956951141357, 0.019370824098587036, -0.02466949075460434, 0.047671616077423096, 0.05285951495170593, 0.02579655684530735, 0.013701359741389751, -0....
' s task and contains the function statements. a function must be defined before the function is called. checkpoint example : welcome message function access multimedia content ( https : / / openstax. org / books / introduction - python - programming / pages / 6 - 1 - defining - functions ) concepts in practice definin...
openstax_introduction_to_python_programming_-_web
[ -0.00022898364113643765, -0.0401231124997139, 0.009376579895615578, -0.0212831050157547, -0.0005555616226047277, -0.020916415378451347, 0.003408723510801792, 0.0006122475606389344, -0.0017103867139667273, 0.04120340198278427, 0.027964480221271515, 0.016173260286450386, 0.02271447703242302, ...
6. 1 • defining functions 147 benefits of functions a function promotes modularity by putting code statements related to a single task in a separate group. the body of a function can be executed repeatedly with multiple function calls, so a function promotes reusability. modular, reusable code is easier to modify and i...
openstax_introduction_to_python_programming_-_web
[ 0.03379619121551514, 0.01562510058283806, 0.005817446392029524, -0.015559379942715168, -0.021129639819264412, -0.021102871745824814, 0.008031927049160004, 0.016845328733325005, -0.04056115448474884, 0.0754101574420929, 0.024555006995797157, 0.015718357637524605, 0.01570531539618969, -0.013...
output is : do you accept the terms and conditions? n have a good day. do you accept the terms and conditions? y thank you for accepting. access multimedia content ( https : / / openstax. org / books / introduction - python - programming / pages / 6 - 1 - defining - functions ) 6. 2 control flow learning objectives by ...
openstax_introduction_to_python_programming_-_web
[ 0.01901848241686821, 0.006969498470425606, -0.027344655245542526, 0.0013009192189201713, -0.003952045924961567, -0.029322268441319466, -0.0276828333735466, 0.0211076308041811, -0.04473990201950073, 0.06215767562389374, -0.015400702133774757, 0.05990689992904663, 0.026081398129463196, -0.02...
6. 2 • control flow 149 checkpoint calling a brunch menu function access multimedia content ( https : / / openstax. org / books / introduction - python - programming / pages / 6 - 2 - control - flow ) concepts in practice following the control flow 1. which line is executed first? 1 def park _ greet ( ) : 2 " " " outpu...
openstax_introduction_to_python_programming_-_web
[ 0.009108524769544601, 0.03591093420982361, 0.008771750144660473, 0.01704215630888939, 0.007081006187945604, -0.028193989768624306, -0.02773078717291355, 0.02711299993097782, 0.014029894955456257, 0.07184656709432602, -0.017259841784834862, 0.08057001978158951, -0.004151188302785158, -0.028...
def park _ greet ( ) : " " " output greeting. " " " print ( " welcome to the park " ) print ( " open sunrise to sunset " ) park _ greet ( ) a. welcome to the park b. welcome to the park open sunrise to sunset c. open sunrise to sunset welcome to the park functions calling functions functions frequently call other funct...
openstax_introduction_to_python_programming_-_web
[ 0.0038210200145840645, 0.031382881104946136, 0.024642642587423325, -0.011586152017116547, -0.007913051173090935, -0.04458995163440704, -0.027396943420171738, 0.03875632956624031, -0.006208490114659071, 0.05186441168189049, -0.019793018698692322, 0.05929873138666153, 0.006306673400104046, 0...
6. 2 • control flow 151 5. how many function calls occur during the execution of the program? a. 2 b. 3 c. 6 6. when line 3 is reached and executed, which line does control flow return to? a. 1 b. 11 c. 16 try it updated terms and conditions prompt write an updated function, terms ( ), that asks the user to accept the ...
openstax_introduction_to_python_programming_-_web
[ 0.0258806012570858, 0.02822107821702957, 0.009818630293011665, 0.01671965979039669, -0.003049637423828244, -0.031622275710105896, -0.02769298665225506, 0.009894697926938534, 0.024466214701533318, 0.059534113854169846, -0.012171506881713867, 0.05788905918598175, 0.0011035403003916144, -0.01...
given inputs 50 and 40, the output is : liam's laundry 7a - 11p open washers : 50 open dryers : 40 access multimedia content ( https : / / openstax. org / books / introduction - python - programming / pages / 6 - 2 - control - flow )
openstax_introduction_to_python_programming_-_web
[ 0.019904913380742073, 0.037739355117082596, 0.011280336417257786, -0.0026042170356959105, -0.05653630197048187, -0.024624651297926903, 0.007926715537905693, 0.0220404714345932, 0.024123916402459145, 0.07207383960485458, 0.02077779732644558, 0.03697711601853371, 0.023999527096748352, -0.040...
6. 3 variable scope learning objectives by the end of this section you should be able to • identify the scope of a program's variables. • discuss the impact of a variable's scope. global scope a variable's scope is the part of a program where the variable can be accessed. a variable created outside of a function has gl...
openstax_introduction_to_python_programming_-_web
[ 0.018556442111730576, -0.00266763917170465, -0.029381565749645233, -0.0034264051355421543, -0.01651252806186676, 0.012873592786490917, 0.034795355051755905, 0.005467160604894161, -0.02535625547170639, 0.0408516600728035, 0.04097653925418854, 0.009352494031190872, -0.004984426777809858, -0....
6. 3 • variable scope 153 num _ sq = num * num print ( num, " squared is ", num _ sq ) num = float ( input ( ) ) print _ square ( ) a. num only b. num _ sq only c. num and num _ sq 3. which functions can access num? def print _ double ( ) : num _ d = num * 2 print ( num, " doubled is ", num _ d ) def print _ square ( )...
openstax_introduction_to_python_programming_-_web
[ 0.022117363288998604, 0.017630664631724358, -0.027010662481188774, 0.00006191330612637103, -0.043463535606861115, 0.007026290521025658, 0.017105530947446823, 0.010261270217597485, -0.0053420173935592175, 0.06819456815719604, 0.04341626912355423, 0.010136467404663563, -0.0041992818005383015, ...
are local? def print _ greeting ( ) : print ( out _ str ) hour = int ( input ( ) ) min = int ( input ( ) ) if hour < 12 : out _ str = " good morning " else : out _ str = " good day " print _ greeting ( ) a. hour and min b. out _ str c. none 6. which functions directly access out _ str? def print _ greeting ( ) : print ...
openstax_introduction_to_python_programming_-_web
[ 0.02652483619749546, 0.01499522477388382, -0.02883029356598854, -0.03208693116903305, -0.026154736056923866, -0.03266647085547447, 0.030391555279493332, 0.018195251002907753, -0.008956898003816605, 0.06067505478858948, -0.0036385096609592438, 0.037741970270872116, -0.027067000046372414, -0...
6. 3 • variable scope 155 using local and global variables together python allows global and local variables to have the same name, which can lead to unexpected program behavior. a function treats a variable edited within the function as a local variable unless told otherwise. to edit a global variable inside a functio...
openstax_introduction_to_python_programming_-_web
[ 0.017009489238262177, 0.02894354984164238, -0.02751118317246437, -0.008574607782065868, -0.0389295257627964, -0.01317157968878746, -0.008455528877675533, -0.015979401767253876, -0.02897150255739689, 0.054895807057619095, 0.029612332582473755, -0.00788873340934515, -0.0038152500055730343, -...
dst = true hour = int ( input ( " enter hour : " ) ) update _ hour ( ) print ( " new hour : ", new _ hour ) a. new hour : 9 b. new hour : 10 c. error benefits of limiting scope a programmer might ask, " why not just make all variables global variables to avoid access errors? " making every variable global can make a pr...
openstax_introduction_to_python_programming_-_web
[ 0.024250956252217293, 0.029659146443009377, -0.006768001243472099, 0.007070163730531931, -0.026900332421064377, -0.017122402787208557, 0.011366724967956543, -0.0009317182120867074, -0.030100785195827484, 0.06238842383027077, 0.015351234935224056, -0.01632738672196865, 0.016093146055936813, ...
6. 4 parameters learning objectives by the end of this section you should be able to • identify a function's arguments and parameters. • describe how mutability affects how a function can modify arguments. arguments and parameters what if a programmer wants to write a function that prints the contents of a list? good p...
openstax_introduction_to_python_programming_-_web
[ 0.047377463430166245, 0.025611551478505135, 0.00552054587751627, -0.015337327495217323, -0.03252192586660385, -0.01928117126226425, -0.019295454025268555, 0.016332203522324562, -0.03154512494802475, 0.06742535531520844, 0.04671905189752579, -0.0011538065737113357, -0.0087898476049304, -0.0...
example 6. 1 using multiple arguments in a function call
openstax_introduction_to_python_programming_-_web
[ 0.029760587960481644, 0.032003577798604965, 0.01699870266020298, -0.002765366341918707, -0.05518180876970291, -0.04737970978021622, -0.015225156210362911, 0.027093514800071716, 0.01246488094329834, 0.05129670724272728, 0.06609261780977249, 0.0045844619162380695, -0.0005062107811681926, -0....
6. 4 • parameters 159 def print _ div ( op _ 1, op _ 2 ) : " " " prints division operation " " " print ( f " { op _ 1 } / { op _ 2 } = { op _ 1 / op _ 2 } " ) num _ 1 = 6 num _ 2 = 3 print _ div ( num _ 1, num _ 2 ) # prints " 6 / 3 = 2. 0 " print _ div ( num _ 2, num _ 1 ) # prints " 3 / 6 = 0. 5 " print _ div ( num _...
openstax_introduction_to_python_programming_-_web
[ 0.020371396094560623, -0.008943755179643631, 0.00041007649269886315, 0.0006204382516443729, -0.019972549751400948, -0.009254038333892822, 0.015457483939826488, 0.014024633914232254, -0.008787698112428188, 0.08994544297456741, 0.026483282446861267, 0.007454562932252884, -0.009397911839187145,...
and mutability in python, a variable is a name that refers to an object stored in memory, aka an object reference, so python 160 6 • functions access for free at openstax. org uses a pass - by - object - reference system. if an argument is changed in a function, the changes are kept or lost depending on the object's mu...
openstax_introduction_to_python_programming_-_web
[ -0.0016473022988066077, 0.014057304710149765, -0.005823197308927774, -0.006501956842839718, -0.022744905203580856, -0.034832023084163666, 0.002155901398509741, 0.00579940527677536, -0.013513630256056786, 0.05795852094888687, 0.03522886708378792, -0.016927992925047874, 0.01988167315721512, ...
10. 56°f 6. 67°f. type was changed to " c " in the function but didn't keep the change outside of the function. why is the list argument change kept and not the string argument change? ( hint : a list is mutable. a string is immutable. ) checkpoint exploring a faulty function access multimedia content ( https : / / ope...
openstax_introduction_to_python_programming_-_web
[ 0.009638162329792976, 0.006830224767327309, 0.002785366028547287, 0.010690620169043541, -0.03229589760303497, -0.021449843421578407, -0.014374391175806522, 0.007557607721537352, 0.0010214262874796987, 0.082442507147789, 0.0416455902159214, 0.017687063664197922, 0.04009973630309105, -0.0457...
6. 4 • parameters 161 concepts in practice mutability and function arguments 8. in convert _ temps ( ), wknd _ temps and temps refer to _ _ _ _ _ _ _ _ in memory. a. the same object b. different objects 9. after unit is assigned with " c ", metric and unit refer to _ _ _ _ _ _ _ _ in memory. a. the same object b. diffe...
openstax_introduction_to_python_programming_-_web
[ 0.021280476823449135, 0.003554666880518198, 0.003799380036070943, 0.02176337130367756, -0.01067629735916853, -0.005442047491669655, -0.007534308359026909, -0.005332728382200003, -0.018656231462955475, 0.1020606979727745, 0.023423682898283005, 0.020627211779356003, 0.010196899995207787, -0....
https : / / openstax. org / books / introduction - python - programming / pages / 6 - 4 - parameters )
openstax_introduction_to_python_programming_-_web
[ 0.03321567922830582, 0.0047979336231946945, 0.004149537533521652, 0.007930752821266651, -0.030763182789087296, -0.012689356692135334, -0.0036063669249415398, 0.006356904748827219, -0.0025095082819461823, 0.07490002363920212, 0.04420231655240059, 0.024491969496011734, 0.02015122026205063, 0...
6. 5 return values learning objectives by the end of this section you should be able to • identify a function's return value. • employ return statements in functions to return values. returning from a function when a function finishes, the function returns and provides a result to the calling code. a return statement f...
openstax_introduction_to_python_programming_-_web
[ -0.020187407732009888, 0.01180795393884182, -0.001764093991369009, -0.011061918921768665, -0.04710442200303078, -0.02286209911108017, -0.015698101371526718, 0.01946815848350525, 0.011755532585084438, 0.0495656356215477, 0.02044084295630455, 0.04924159497022629, -0.046261873096227646, 0.008...
6. 5 • return values 163 mpg = miles / gallons return mpg a. mpg b. none c. error 2. what is returned by calc _ sqft ( )? def calc _ sqft ( length, width ) : sqft = length * width return a. sqft b. none c. error 3. what is the difference between hw _ 1 ( ) and hw _ 2 ( )? def hw _ 1 ( ) : print ( " hello world! " ) ret...
openstax_introduction_to_python_programming_-_web
[ -0.013010001741349697, 0.02804803103208542, 0.02814353257417679, 0.006674556992948055, -0.08195856213569641, 0.00026108359452337027, 0.008228282444179058, 0.018387043848633766, 0.01624266989529133, 0.0746975913643837, 0.020851843059062958, 0.024908391758799553, -0.04379003867506981, -0.041...
300, 0 ) print ( " car 2's mpg is ", car _ 2 _ mpg ) car 1's mpg is 28. 0 gallons can't be 0 car 2's mpg is - 1 table 6. 1 calculating miles - per - gallon and checking for division by zero. concepts in practice multiple return statements 4. what does yarn _ weight ( 3 ) return? def yarn _ weight ( num ) : if num = = 0...
openstax_introduction_to_python_programming_-_web
[ 0.008260966278612614, -0.000677768955938518, -0.00223860377445817, -0.00026304382481612265, -0.04859796538949013, -0.023818466812372208, 0.013901645317673683, 0.007707014214247465, -0.009643036872148514, 0.07298339158296585, 0.024067159742116928, 0.00911557488143444, -0.022132612764835358, ...
6. 5 • return values 165 if level < max : return level level + = 1 else : return level vol1 = inc _ volume ( 9, 10 ) print ( vol1 ) vol2 = inc _ volume ( 10, 10 ) print ( vol2 ) a. 9 10 b. 10 10 c. 10 11 using functions as values functions are objects that evaluate to values, so function calls can be used in expression...
openstax_introduction_to_python_programming_-_web
[ 0.005193216260522604, 0.02786344476044178, -0.01359992753714323, 0.024884188547730446, -0.03276531770825386, -0.045744094997644424, 0.0006740638054907322, 0.0019463766366243362, -0.0006289593875408173, 0.07463711500167847, 0.009646610356867313, 0.07628774642944336, -0.014846326783299446, 0...
126. 0 7. what is the value of val2? def sq ( num ) : return num * num def offset ( num ) : return num - 2 val = 5 val2 = sq ( offset ( val ) ) a. 9 b. 23 try it estimated days alive write a function, days _ alive ( ), that takes in an age in years and outputs the estimated days the user has been alive as an integer. a...
openstax_introduction_to_python_programming_-_web
[ 0.014176508411765099, 0.0457085557281971, -0.01916731521487236, 0.021515531465411186, -0.053848087787628174, 0.00683567114174366, 0.0003308681771159172, -0.011306184343993664, 0.030952027067542076, 0.060749419033527374, 0.0267730001360178, -0.036022212356328964, 0.0012433474184945226, -0.0...
6. 6 keyword arguments learning objectives by the end of this section you should be able to • describe the difference between positional and keyword arguments. • create functions that use positional and keyword arguments and default parameter values. keyword arguments so far, functions have been called using positional...
openstax_introduction_to_python_programming_-_web
[ 0.046499162912368774, -0.011722623370587826, 0.00929990503937006, 0.0014540054835379124, -0.01918969675898552, -0.026393933221697807, 0.004539338406175375, 0.03880678117275238, -0.05074983090162277, 0.06041467562317848, 0.02411305531859398, 0.004041694104671478, -0.026140246540308, 0.02548...
1, " hi ", " bea " ) c. greeting ( " cheers ", " colleagues ", 10 ) default parameter values functions can define default parameter values to use if a positional or keyword argument is not provided for the parameter. ex : def season ( m, d, hemi = " n " ) : defines a default value of " n " for the hemi parameter. note ...
openstax_introduction_to_python_programming_-_web
[ 0.005918199196457863, 0.010415609925985336, 0.027601750567555428, 0.007840431295335293, -0.06238231807947159, -0.013896708376705647, 0.03180659934878349, 0.02568313479423523, -0.039591073989868164, 0.03427848592400551, 0.023150483146309853, 0.005329945124685764, -0.02580503188073635, 0.002...
6. 6 • keyword arguments 169 a. hello friend b. nothing c. error pep 8 recommendations : spacing the pep 8 style guide recommends no spaces around = when indicating keyword arguments and default parameter values. try it stream donations write a function, donate ( ), that lets an online viewer send a donation to a strea...
openstax_introduction_to_python_programming_-_web
[ 0.03199343383312225, 0.027334611862897873, -0.004332344513386488, 0.04436924308538437, -0.022754013538360596, -0.037265848368406296, 0.026325391605496407, 0.03845937177538872, -0.049673546105623245, 0.046499427407979965, 0.019523700699210167, 0.0017150952480733395, -0.01489889807999134, 0....