text
stringlengths
1
3.55k
source
stringlengths
24
207
emb
listlengths
1.02k
1.02k
14. 6 • chapter summary 347 statement description data = file. readlines ( ) read all lines of a file. the variable data is a list of strings. file. write ( " have a nice day! \ n " ) writes a line to a file. in contrast to print ( ), the write ( ) function does not automatically append a newline. file. write ( [ " lin...
openstax_introduction_to_python_programming_-_web
[ -0.03699037432670593, -0.010744006372988224, 0.0257597416639328, -0.006995789241045713, 0.005156809464097023, -0.008459075354039669, 0.013618852011859417, -0.020119138062000275, 0.0034880884923040867, 0.07555440068244934, -0.012607867829501629, -0.0023024941328912973, 0.01585358753800392, ...
business, education, politics, environmental science, and social sciences. this chapter aims to provide an introduction to the field of data science and the data science life cycle. the resources provided in this chapter are meant to guide readers using python to further explore data science.
openstax_introduction_to_python_programming_-_web
[ 0.014894719235599041, 0.010159510187804699, 0.02512255124747753, -0.06523553282022476, -0.010163421742618084, 0.015314442105591297, -0.02653805911540985, 0.005311402026563883, 0.01601450704038143, 0.07138916105031967, -0.0029123760759830475, -0.02057407796382904, 0.05977417528629303, -0.01...
15. 1 introduction to data science learning objectives by the end of this section you should be able to • describe data science. • identify different stages of the data science life cycle. • name data science tools and software. • use google colaboratory to run code. data science life cycle data science is a multidisci...
openstax_introduction_to_python_programming_-_web
[ 0.004979623947292566, -0.008604847826063633, 0.035306163132190704, -0.02596297673881054, -0.013057682663202286, 0.007934000343084335, -0.05634447932243347, 0.0014724646462127566, 0.016066350042819977, 0.05093689262866974, -0.01343282125890255, -0.024530190974473953, 0.06049983203411102, -0...
stage? a. document insights and visualization b. analyze data c. data cleaning and visualization data science tools several tools and software are commonly used in data science. here are some examples. • python programming language : python is widely used in data science. it has a large system of libraries designed for...
openstax_introduction_to_python_programming_-_web
[ 0.02667965553700924, -0.014144441112875938, 0.015456641092896461, -0.014322462491691113, -0.005668065045028925, 0.013142879121005535, -0.03135859966278076, 0.015808723866939545, -0.0032702358439564705, 0.05465303733944893, -0.01642204448580742, -0.015654703602194786, 0.026246841996908188, ...
manipulation, basic statistical calculations, and simple visualizations. checkpoint google colaboratory ecosystem access multimedia content ( https : / / openstax. org / books / introduction - python - programming / pages / 15 - 1 - introduction - to - data - science ) concepts in practice data science tools and softwa...
openstax_introduction_to_python_programming_-_web
[ 0.04006689041852951, -0.004020716995000839, -0.010388916358351707, 0.006573254708200693, -0.016326425597071648, -0.003939309157431126, -0.01921127736568451, -0.007642540615051985, 0.00031078586471267045, 0.05134281516075134, -0.002044819761067629, 0.01456871535629034, 0.024952813982963562, ...
15. 2 numpy learning objectives by the end of this section you should be able to • describe the numpy library. • create a numpy array object. • choose appropriate numpy functions to process arrays of numerical data. numpy library numpy ( numerical python ) is a python library that provides support for efficient numeric...
openstax_introduction_to_python_programming_-_web
[ 0.03131460025906563, 0.025717973709106445, -0.0345354862511158, -0.0451727919280529, -0.009838063269853592, -0.0014517692616209388, -0.005290431901812553, -0.005792160052806139, 0.012507062405347824, 0.09203492105007172, 0.038970060646533966, -0.02397032454609871, -0.004739928990602493, -0...
a. np. array ( [ 2, 3 ] ) b. np. zeros ( 1, 2 ) c. np. zeros ( ( 1, 2 ) ) 2. which of the following is a numpy data type? a. ndarray b. list c. array 3. what is the benefit of using anndarray object compared to a list? a. computational efficiency 352 15 • data science access for free at openstax. org b. array - oriente...
openstax_introduction_to_python_programming_-_web
[ 0.015840716660022736, -0.004328123759478331, -0.030978286638855934, -0.02745373360812664, 0.0011902060359716415, 0.004911798518151045, -0.018033234402537346, 0.0005706934025511146, 0.014617642387747765, 0.09535752236843109, 0.016206439584493637, 0.026646660640835762, 0.010968497022986412, ...
] [ 6 8 ] ] c. [ [ 1 2 ] [ 3 4 ] ] 5. which of the following results in a 2 by 3 ndarray? a. import numpy as np arr = np. array ( 2, 3 ) b. import numpy as np
openstax_introduction_to_python_programming_-_web
[ 0.03753405064344406, 0.0018707566196098924, 0.027116376906633377, -0.034904368221759796, -0.059406064450740814, -0.03586353734135628, -0.0048574041575193405, 0.006644645240157843, 0.00815514288842678, 0.08289682120084763, 0.027772583067417145, 0.009046207182109356, -0.003278156276792288, -...
15. 2 • numpy 353 arr = np. array ( [ [ 1, 2 ], [ 1, 2 ], [ 1, 2 ] ] ) c. import numpy as np arr = np. array ( [ [ 1, 2 ], [ 1, 2 ], [ 1, 2 ] ] ). t 6. the function np. multiply ( arr1, arr2 ) receives two ndarray objects arr1 and arr2 with the same dimensions, and performs element - wise multiplication. what is the ou...
openstax_introduction_to_python_programming_-_web
[ 0.03224512189626694, 0.01587529107928276, -0.03952094539999962, -0.022067710757255554, -0.014407310634851456, -0.01757855713367462, -0.008628974668681622, 0.006682225503027439, 0.0008107825997285545, 0.07840126007795334, 0.04861921817064285, -0.006551048252731562, -0.019918205216526985, -0...
15. 3 pandas learning objectives by the end of this section you should be able to • describe the pandas library. • create a dataframe and a series object. • choose appropriate pandas functions to gain insight from heterogeneous data. pandas library pandas is an open - source python library used for data cleaning, proce...
openstax_introduction_to_python_programming_-_web
[ 0.010156973265111446, -0.018077248707413673, 0.03319595381617546, -0.027772841975092888, -0.01314223650842905, 0.03842676430940628, -0.02551252767443657, 0.03459838032722473, 0.010869611985981464, 0.053528428077697754, -0.005155852995812893, -0.017293985933065414, -0.0007328724605031312, -...
list, numpy array, or a csv file. column names and column data types can be specified at the time of dataframe instantiation.
openstax_introduction_to_python_programming_-_web
[ -0.0026127055753022432, -0.01868203468620777, 0.05020593851804733, -0.026841232553124428, -0.040651191025972366, -0.0029390675481408834, 0.00554067175835371, 0.016030823811888695, 0.041980501264333725, 0.049680329859256744, 0.02420903742313385, -0.042432066053152084, 0.020437056198716164, ...
15. 3 • pandas 355 description example output explanation dataframe from a dictionary import pandas as pd # create a dictionary of columns data = { " name " : [ " emma ", " gireeja ", " sophia " ], " age " : [ 15, 28, 22 ], " city " : [ " dubai ", " london ", " san jose " ] } # create a dataframe from the dictionary df...
openstax_introduction_to_python_programming_-_web
[ 0.004174795001745224, -0.01696336455643177, 0.03835554048418999, -0.024163423106074333, -0.0328369066119194, 0.01298095379024744, -0.01507566124200821, 0.015861213207244873, 0.005579856690019369, 0.05323755368590355, 0.013565546832978725, -0.03772629052400589, -0.00342712365090847, -0.0046...
0, 0 ], [ 0, 1, 0 ], [ 2, 3, 4 ] ] ) # define column labels columns = [ " a ", " b ", " c " ] # create a dataframe from the numpy array df = pd. dataframe ( data, columns = columns ) # display the dataframe df a b c 0 1 0 0 1 0 1 0 2 2 3 4 a numpy array, along with column labels, are passed to the pd. dataframe ( ) fun...
openstax_introduction_to_python_programming_-_web
[ 0.023965654894709587, -0.028434621170163155, 0.04813116043806076, -0.03585066646337509, -0.021977657452225685, 0.007180187851190567, 0.016874562948942184, 0.02226780354976654, 0.016361860558390617, 0.04945225641131401, 0.03809165582060814, -0.023079007863998413, 0.00025549414567649364, 0.0...
15. 3 • pandas 357 description example output explanation dataframe from a csv file import pandas as pd # read the csv file into a dataframe df = pd. read _ csv ( " data. csv " ) # display the dataframe df the content of the csv file will be printed in a tabular format. the pd. read _ csv ( ) function reads a csv file ...
openstax_introduction_to_python_programming_-_web
[ -0.0004837808373849839, -0.003927211277186871, 0.03173615410923958, 0.0010176720097661018, -0.009935839101672173, 0.03070635348558426, -0.010028119198977947, 0.029068944975733757, 0.020144246518611908, 0.08891145139932632, -0.00864541344344616, -0.015062584541738033, -0.022264881059527397, ...
summer ','summer ','fall ','winter ','fall ','winter'],'month': ['july ','june ','september ','january ','october ','february'],'month - day': [ 1, 12, 3, 7, 20, 28 ],'year': [ 2000, 1990, 2020, 1998, 2001, 2022 ] } df = pd. dataframe ( days ) season month month - day year 0 summer july 1 2000 1 summer june 12 1990 2 f...
openstax_introduction_to_python_programming_-_web
[ 0.0037678240332752466, 0.020061654970049858, 0.04516040161252022, -0.020782100036740303, -0.040232960134744644, -0.011265263892710209, 0.018554283306002617, 0.03470847010612488, 0.029919728636741638, 0.06860321760177612, 0.007643002085387707, -0.0003633262822404504, 0.030808446928858757, -...
15. 3 • pandas 359 function name explanation example output head ( n ) returns the first n rows. if a value is not passed, the first 5 rows will be shown. df. head ( 4 ) season month month - day year 0 summer july 1 2000 1 summer june 12 1990 2 fall september 3 2020 3 winter january 7 1998 tail ( n ) returns the last n...
openstax_introduction_to_python_programming_-_web
[ 0.032686036080121994, -0.004042863845825195, 0.0310721006244421, -0.0020271402318030596, -0.01892760582268238, -0.02382059022784233, 0.01012505404651165, 0.029583901166915894, -0.0014850333100184798, 0.0680989921092987, 0.03812525421380997, -0.02722018025815487, -0.007074195891618729, 0.00...
. 000000 1990. 000000 25 % 4. 000000 1998. 500000 50 % 9. 500000 2000. 500000 75 % 18. 000000 2015. 250000 max 28. 000000 2022. 000000 value _ counts ( ) counts the occurrences of unique values in a column when a column is passed as an argument and presents them in descending order. df. value _ counts \ ('season') seas...
openstax_introduction_to_python_programming_-_web
[ 0.0029386316891759634, 0.004817286506295204, 0.023679163306951523, 0.01630391739308834, -0.026031583547592163, -0.014472445473074913, -0.007558688521385193, 0.025580869987607002, -0.0030209894757717848, 0.04852079972624779, -0.023110080510377884, -0.00735357403755188, 0.0007070060237310827, ...
15. 3 • pandas 361 concepts in practice dataframe operations 4. which of the following returns the top five rows of a dataframe? a. df. head ( ) b. df. head ( 5 ) c. both 5. what does the unique ( ) function do in a dataframe when applied to a column? a. returns the number of unique columns b. returns the number of uni...
openstax_introduction_to_python_programming_-_web
[ 0.04077048972249031, -0.010471177287399769, 0.0030197009909898043, -0.0054894741624593735, -0.039218805730342865, 0.0022559871431440115, -0.019755590707063675, 0.025906339287757874, 0.021876581013202667, 0.02887932024896145, 0.023087264969944954, 0.006958417594432831, -0.013432968407869339, ...
15. 4 exploratory data analysis learning objectives by the end of this section you should be able to • describe exploratory data analysis. • inspect dataframe entries through appropriate indexing. • use filtering and slicing to obtain a subset of a dataframe. • identify null values in a dataframe. • remove or replace n...
openstax_introduction_to_python_programming_-_web
[ -0.019720137119293213, 0.001204845029860735, 0.012355335988104343, -0.017103036865592003, -0.007738690357655287, 0.04094617813825607, -0.02942061237990856, 0.0159299336373806, 0.006009629461914301, 0.07518063485622406, -0.0010656724916771054, -0.006896430626511574, 0.0017639320576563478, -...
_ index. checkpoint indexing a dataframe access multimedia content ( https : / / openstax. org / books / introduction - python - programming / pages / 15 - 4 - exploratory - data - analysis ) concepts in practice dataframe indexing given the following code, respond to the questions below. import pandas as pd # create s...
openstax_introduction_to_python_programming_-_web
[ 0.005025715567171574, -0.028437741100788116, 0.036457523703575134, -0.013099659234285355, -0.003294689580798149, -0.019427884370088577, -0.028939412906765938, 0.0014588687336072326, 0.02192298322916031, 0.08973375707864761, -0.024298513308167458, -0.002555130748078227, 0.023040616884827614, ...
15. 4 • exploratory data analysis 363 c. b data slicing and filtering data slicing and filtering involve selecting specific subsets of data based on certain conditions or index / label ranges. data slicing refers to selecting a subset of rows and / or columns from a dataframe. slicing can be performed using ranges, lis...
openstax_introduction_to_python_programming_-_web
[ 0.007072166074067354, -0.020500557497143745, 0.03421289846301079, -0.0012527642538771033, -0.01309248898178339, 0.013504193164408207, 0.006819813512265682, 0.009693486616015434, -0.0033395153004676104, 0.0908203274011612, 0.008188660256564617, -0.013125848956406116, 0.0018106985371559858, ...
9, 10, 11, 12 ] } df = pd. dataframe ( data ) 4. which of the following returns the first three rows of column a? a. df. loc [ 1 : 3, " a " ] b. df. loc [ 0 : 2, " a " ] c. df. loc [ 0 : 3, " a " ] 364 15 • data science access for free at openstax. org 5. which of the following returns the second row? a. df. iloc [ 2 ]...
openstax_introduction_to_python_programming_-_web
[ 0.02669767662882805, 0.0018333187326788902, 0.023710619658231735, -0.012775396928191185, -0.034899111837148666, -0.010054631158709526, -0.013882567174732685, 0.014676365070044994, -0.0038408103864639997, 0.06192951276898384, 0.02427719719707966, 0.013418374583125114, -0.007244578562676907, ...
isnull ( ) function can be used to identify null entries in a dataframe. the return value of the function is a boolean dataframe, with the same dimensions as the original dataframe with true values where missing values exist. • dropna ( ) : the dropna ( ) function can be used to drop rows with null values. • fillna ( )...
openstax_introduction_to_python_programming_-_web
[ 0.0349174402654171, 0.03251541405916214, 0.019618362188339233, -0.011360843665897846, -0.03318195417523384, -0.0032340444158762693, -0.01288540754467249, 0.019272707402706146, -0.002751828171312809, 0.06567828357219696, 0.043982140719890594, 0.01247301697731018, 0.00252708257175982, -0.044...
is null. fillna ( ) df [ " column 2 " ] = \ df [ " column 2 " ]. fillna ( df [ " column 2 " ]. mean ( ) ) column 1 column 2 column 3 0 a 172. 5 true 1 b 200. 0 true 2 c 500. 0 false 3 d 0. 0 nan 4 e - 10. 0 nan null values in column 2 are replaced with the mean of non - null values in the column. dropna ( ) # applied a...
openstax_introduction_to_python_programming_-_web
[ 0.02678580954670906, 0.01429404690861702, 0.006208202335983515, -0.00878320261836052, -0.03668360784649849, -0.017185665667057037, -0.013922026380896568, 0.023963622748851776, -0.010578184388577938, 0.06188652291893959, 0.027273938059806824, 0.016917826607823372, -0.0014720611507073045, -0...
15. 4 • exploratory data analysis 367 concepts in practice missing value treatment 8. which of the following is used to check the dataframe for null values? a. isnan ( ) b. isnull ( ) c. isnone ( ) 9. assuming that a dataframe df is given, which of the following replaces null values with zeros? a. df. fillna ( 0 ) b. d...
openstax_introduction_to_python_programming_-_web
[ 0.005173112265765667, -0.002735491143539548, 0.009588757529854774, -0.011780315078794956, -0.037390630692243576, -0.024034328758716583, 0.021258804947137833, 0.01372726634144783, 0.007807438727468252, 0.05472784861922264, 0.02783181704580784, 0.013211132027208805, 0.028348080813884735, -0....
15. 5 data visualization learning objectives by the end of this section you should be able to • explain why visualization has an important role in data science. • choose appropriate visualization for a given task. • use python visualization libraries to create data visualization. why visualization? data visualization h...
openstax_introduction_to_python_programming_-_web
[ 0.01626206375658512, -0.001208449830301106, 0.027431204915046692, -0.029532723128795624, -0.04559820517897606, -0.00941924937069416, 0.0027052585501223803, 0.0158015638589859, 0.0010940186912193894, 0.06526000052690506, -0.03471388667821884, -0.03075091913342476, 0.018965281546115875, 0.00...
best suited for visualizing outliers and quartiles of a continuous variable? a. histogram plot b. bar plot c. box plot 3. which of the following plot types is effective for displaying trends and changes over time? a. line plot b. bar plot c. histogram plot data visualization tools many python data visualization librari...
openstax_introduction_to_python_programming_-_web
[ 0.028886079788208008, -0.006144728045910597, 0.025149961933493614, -0.048224419355392456, -0.028841814026236534, -0.012324702925980091, 0.010241287760436535, 0.014998532831668854, 0.031811993569135666, 0.0884099081158638, -0.038350872695446014, -0.017306003719568253, 0.01592104695737362, 0...
15. 5 • data visualization 369 plot types. some of the most commonly used frameworks are matplotlib, plotly, and seaborn. here, some useful functionalities of matplotlib are summarized. plot type method bar plot the plt. bar ( x, height ) function takes in two inputs, x and height, and plots bars for each x value with ...
openstax_introduction_to_python_programming_-_web
[ 0.038206808269023895, -0.008129614405333996, 0.05523277074098587, -0.03981897234916687, -0.03806015104055405, -0.00692968163639307, 0.015233411453664303, 0.010103178210556507, 0.018521832302212715, 0.06522747129201889, -0.0050075300969183445, -0.01099154632538557, 0.006921337451785803, -0....
plt. ylabel ( " inflation " ) # display the chart plt. show ( ) table 15. 9 matplotlib functionalities. line plot.
openstax_introduction_to_python_programming_-_web
[ 0.023022903129458427, -0.018641680479049683, 0.03426486998796463, 0.004835568834096193, -0.02560531720519066, -0.027955036610364914, 0.0024902576114982367, 0.0066238162107765675, 0.034100811928510666, 0.04833681136369705, 0.02023441158235073, -0.0186073649674654, 0.009864828549325466, -0.0...
15. 5 • data visualization 371 plot type method scatter plot the plt. scatter ( x, y ) function takes in two inputs, x and y, and plots points representing ( x, y ) pairs. example output import matplotlib. pyplot as plt # data x = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] y = [ 10, 8, 6, 4, 2, 5, 7, 9, 3, 1 ] # create the scat...
openstax_introduction_to_python_programming_-_web
[ 0.023586325347423553, 0.014035467989742756, 0.031038077548146248, -0.046048324555158615, -0.04678615182638168, -0.01614384353160858, -0.016678286716341972, 0.006965946406126022, 0.03681457042694092, 0.07061321288347244, -0.012034663930535316, -0.006562711205333471, 0.0393889881670475, 0.01...
15. 5 • data visualization 373 plot type method box plot the plt. boxplot ( x ) function takes in one input, x, and represents minimum, maximum, first, second, and third quartiles, as well as outliers in x. example output import matplotlib. pyplot as plt import numpy as np # data : random 100 samples data = [ np. rando...
openstax_introduction_to_python_programming_-_web
[ 0.04295097291469574, 0.03377655893564224, 0.04565564915537834, -0.0482596755027771, -0.03898745775222778, -0.03527635335922241, 0.0018752870382741094, 0.006618366576731205, 0.02285424992442131, 0.06529135257005692, -0.00192565331235528, 0.0021912006195634604, 0.011100420728325844, 0.001117...
interactive visualizations? a. matplotlib b. plotly c. pandas exploring further please refer to the following user guide for more information about the matplotlib, plotly, and seaborn libraries. • matplotlib user guide ( https : / / openstax. org / r / 100matplotguide ) • plotly user guide ( https : / / openstax. org /...
openstax_introduction_to_python_programming_-_web
[ 0.01980559714138508, -0.014337738044559956, 0.019455093890428543, -0.029040221124887466, -0.009279650636017323, -0.015718815848231316, -0.021788766607642174, -0.00402359152212739, 0.026149995625019073, 0.03415437042713165, -0.02834501676261425, -0.02913830429315567, 0.03228120133280754, 0....
15. 6 • summary 375 • google colaboratory is a cloud - based jupyter notebook environment that allows programmers to write, run, and share python code online. • numpy ( numerical python ) is a python library that provides support for efficient numerical operations on large, multi - dimensional arrays and serves as a fu...
openstax_introduction_to_python_programming_-_web
[ 0.01792221888899803, -0.0017904270207509398, -0.01646606996655464, -0.007167004514485598, 0.008550080470740795, 0.02196207083761692, -0.0120850196108222, 0.007336268201470375, 0.006487676408141851, 0.058031223714351654, -0.013408453203737736, -0.028767045587301254, 0.013521136716008186, -0...
, and plt, respectively. at this point, you should be able to write programs to create data structures to store different datasets and explore and visualize datasets. function description np. array ( ) creates an ndarray from a list or tuple. np. zeros ( ) creates an array of zeros. np. ones ( ) creates an array of one...
openstax_introduction_to_python_programming_-_web
[ 0.0189544428139925, -0.022431664168834686, 0.028865789994597435, -0.04749009385704994, -0.00378719181753695, -0.008410114794969559, -0.00015918623830657452, 0.01313846930861473, 0.024128319695591927, 0.05430933088064194, 0.010927950032055378, -0.0497313067317009, 0.04015982151031494, -0.01...
_ row : end _ row, start _ column : end _ column ] slices using label ranges. df. loc [ [ label1, label2,... ], : ] slices rows that are in the list [ label1, label2,... ]. df. isnull ( ) returns a boolean array with boolean values representing whether each entry has been null. fillna ( ) replaces null values. dropna (...
openstax_introduction_to_python_programming_-_web
[ 0.01847180724143982, 0.00465091597288847, 0.03146892040967941, -0.012957523576915264, -0.004908476024866104, -0.016791610047221184, 0.008187676779925823, -0.010221379809081554, 0.02807922288775444, 0.07253437489271164, 0.026530511677265167, 0.007555182557553053, 0.015774529427289963, -0.02...
. c. python's syntax is more concise than java's. 6. a. python does not require a semicolon at the end of each line. braces are also not required.
openstax_introduction_to_python_programming_-_web
[ 0.0012793169589713216, -0.02434077486395836, -0.0004852457786910236, -0.031443770974874496, -0.021426547318696976, 0.018713468685746193, 0.048935241997241974, -0.006733403075486422, 0.005432172678411007, 0.06943707913160324, 0.0075133191421628, 0.01911652646958828, -0.06243203580379486, -0...
1. 2 input / output 1. c. the hello world program is just one line of code. 2. c. the end = " " option removes the newline character after hello, producing hello world! on the same line. 3. c. the default space character that separates multiple items has been replaced with the dash character. 4. c. the user input is st...
openstax_introduction_to_python_programming_-_web
[ 0.0003195040626451373, 0.015255286358296871, 0.03648349642753601, -0.02954917773604393, -0.02466457150876522, -0.03658277913928032, 0.03130236640572548, 0.012003010138869286, -0.008481450378894806, 0.045139528810977936, -0.008837249130010605, 0.03131616488099098, -0.0168925728648901, -0.02...
1. 3 variables 1. c. this would produce the output string, " the city where you live is chicago ". 2. b. these two lines of code would produce the output string, " total = 6 ". 3. c. the single = character is the assignment operator. 4. a. an assignment statement has the variable name on the left side and the value on ...
openstax_introduction_to_python_programming_-_web
[ 0.0182354673743248, -0.02867666259407997, 0.0303664468228817, -0.018151167780160904, -0.03900907188653946, -0.04120495915412903, 0.0336591936647892, 0.01568111591041088, -0.021460574120283127, 0.06797003746032715, 0.03277169540524483, 0.011208834126591682, -0.004511589650064707, -0.0339342...
1. 4 string basics 1. c. a string that is enclosed by matching double quotes is a valid string. note that'7 days'is also a string. 2. c. the string, fred78 @ gmail. com, is enclosed in matching double quotes, and is assigned to the variable email. a string can contain characters such as " @ " or ". " in addition to let...
openstax_introduction_to_python_programming_-_web
[ -0.010610625147819519, -0.008592672646045685, 0.05128445103764534, -0.005427151452749968, -0.040384504944086075, -0.030584821477532387, 0.03390384465456009, 0.03690718486905098, 0.005977285094559193, 0.07241730391979218, 0.026214024052023888, 0.06328882277011871, 0.0009348143357783556, -0....
##catenation of the two strings is assigned to the variable holiday. note that " one - sided " would assign the same string to holiday.
openstax_introduction_to_python_programming_-_web
[ -0.004529279191046953, 0.006631382741034031, 0.023589996621012688, -0.016516856849193573, -0.05165701359510422, -0.05040586367249489, 0.012900334782898426, 0.017803363502025604, -0.029604222625494003, 0.05806790292263031, 0.034362565726041794, -0.001265593571588397, -0.027395697310566902, ...
1. 5 number basics 1. c. x = 1 is an integer, and when printing the type of an integer variable, the output is < class'int'>. 2. b. y = 2. 0 is floating - point number. 3. a. any value defined within quotation marks is a string value regardless of the content. 4. c. line 2 of the code evaluates as follows : c = x - z =...
openstax_introduction_to_python_programming_-_web
[ -0.0022255561780184507, -0.03204040601849556, 0.0015625894302502275, -0.02272440679371357, -0.007918008603155613, -0.01219951268285513, 0.048207737505435944, -0.012030748650431633, -0.024056410416960716, 0.06943795830011368, 0.0007139410590752959, 0.005170568823814392, -0.004036384634673595,...
folders. 2. b. line 2 is mentioned immediately after the filename. 3. b. the type of error is always the first word on the last line of the error message. 4. a. the middle three lines are indented. in python, lines may not begin with spaces or tabs unexpectedly. 5. c. the quote marks are missing at the end of the input...
openstax_introduction_to_python_programming_-_web
[ 0.0020791366696357727, -0.028066551312804222, 0.03974613547325134, -0.024641549214720726, -0.025012562051415443, -0.018907727673649788, 0.030458394438028336, -0.0022099297493696213, 0.00912413839250803, 0.08690790832042694, -0.014039574190974236, 0.03173781558871269, 0.0008173628593795002, ...
1. 7 comments 1. b. comments help explain the purpose of code so that other programmers understand what the code intends. 2. a. the hash character indicates the beginning of a comment. 3. b. having one space after the # is the community standard. 4. c. this comment explains the intent of the code. if the code had a mis...
openstax_introduction_to_python_programming_-_web
[ 0.014966568909585476, -0.027876146137714386, 0.016485683619976044, -0.027664190158247948, -0.01676631160080433, -0.023313531652092934, 0.046634938567876816, 0.019710857421159744, -0.028203913941979408, 0.06836669892072678, -0.008601365610957146, 0.037015024572610855, -0.005505192559212446, ...
. most programming languages are high - level and meant to be understood by humans. 2. c. the most basic line of python code is a single expression, such as the integer 1. 3. b. after the input is stored in memory, the shell displays a prompt for the next line. 4. c. the up arrow displays the previous line, and the lef...
openstax_introduction_to_python_programming_-_web
[ 0.028381770476698875, -0.014833221212029457, 0.0008891570032574236, -0.03664088249206543, 0.0070951879024505615, -0.03657802194356918, 0.0276237390935421, 0.0068618557415902615, -0.015501136891543865, 0.08987545967102051, -0.00011239160812692717, 0.033760830760002136, -0.016596317291259766, ...
2. 2 type conversion 1. a. book _ rating was assigned with 3. 5 on line 5 and converted from an integer to a float by the interpreter. book _ rating isn't modified after line 5. 2. a. combining a float and an integer in a calculation produces a float. book _ rating would be assigned with 4. 0. 3. a. a calculation with ...
openstax_introduction_to_python_programming_-_web
[ 0.003623873693868518, -0.016856767237186432, -0.004190550651401281, -0.02539079822599888, -0.038119520992040634, -0.028691178187727928, 0.03714871034026146, 0.017460469156503677, -0.013805127702653408, 0.05392045900225639, 0.01081835012882948, -0.001751973177306354, 0.009609781205654144, -...
2. 3 mixed data types 1. b. multiplying an integer and a float produces a float. 2. a. multiplying two integers produces an integer. 3. b. dividing two integers produces a float, even when the result is a whole number. 4. b. dividing two integers produces a float and does not round. 5. b. dividing a float by an integer...
openstax_introduction_to_python_programming_-_web
[ -0.01110582984983921, -0.023872898891568184, -0.006352750118821859, -0.04401284083724022, -0.033062294125556946, -0.03447045385837555, 0.038013678044080734, 0.015493880957365036, 0.020591167733073235, 0.09526588767766953, 0.014478456228971481, 0.025764726102352142, 0.02360920049250126, -0....
2. 4 floating - point errors 1. b. an overflow error occurs because the value is larger than the upper limit of the floating - point range. 2. a. the digits starting from the eighteenth place after the decimal are inaccurate due to approximation, so a round - off error occurs. 3. c. round ( 6. 6 ) = 7 as 7 is the close...
openstax_introduction_to_python_programming_-_web
[ 0.0024476919788867235, 0.003593592904508114, -0.009723610244691372, -0.03002447821199894, -0.0237954743206501, 0.0023762104101479053, 0.04458089545369148, 0.01598202995955944, 0.001353951171040535, 0.08256514370441437, 0.006429265718907118, 0.010223808698356152, -0.0012588934041559696, 0.0...
. tau is equal to 2π, so tau divided by 2 is π. 5. a. the math. sqrt ( ) function returns a float, even when given an integer. 6. b. this expression is a concise way to write πr2. 7. a. when given integers, the * * operator returns an integer result.
openstax_introduction_to_python_programming_-_web
[ -0.008484363555908203, -0.0023822796065360308, 0.02197800762951374, -0.06542925536632538, -0.05902181193232536, -0.010748134925961494, 0.01794845424592495, 0.037321265786886215, -0.004711846821010113, 0.0670943483710289, 0.041673023253679276, 0.03571680188179016, -0.027074048295617104, 0.0...
2. 7 formatting code 1. a. the code has one space before and after the assignment operator ( = ). 2. c. each operator ( =, + ) has one space both before and after. 3. b. the comma is followed by a space. 4. a. the expressions b * * 2 and 4 * a * c are evaluated first. adding space around the - operator makes the order ...
openstax_introduction_to_python_programming_-_web
[ 0.004909243434667587, -0.024589242413640022, 0.009105932898819447, -0.013778898864984512, -0.0028373715467751026, -0.05077388882637024, 0.034024566411972046, -0.0024816168006509542, -0.010218181647360325, 0.0550331175327301, 0.01104641705751419, 0.04359034448862076, -0.007925785146653652, ...
3. 1 strings revisited 1. a. since index values start at 0, the index 1 refers to the second character of the string. 2. b. the character at index 1 is y, and the character at index - 1 is!. 3. c. the result of s [ 0 ] is " p ", which is a string of length 1. 4. b. code points 65 to 90 are used for uppercase letters. 5...
openstax_introduction_to_python_programming_-_web
[ 0.017078086733818054, 0.01873459294438362, 0.06485705077648163, -0.021568160504102707, -0.04208211228251457, -0.025593291968107224, 0.016040347516536713, -0.010870611295104027, -0.01760725863277912, 0.09503407776355743, 0.02416492998600006, 0.03017624281346798, 0.005046789068728685, -0.029...
3. 2 formatted strings 1. b. the same variable, says, is used in three replacement fields. 2. a. the string is not an f - string, so the brace characters ( around temp and food ) are printed literally. 3. c. using an f - string allows the entire output to be specified without commas and extra quote marks. 4. a. the for...
openstax_introduction_to_python_programming_-_web
[ 0.021940523758530617, -0.015403758734464645, 0.03992201387882233, -0.02021227777004242, -0.04379422962665558, -0.00565918767824769, 0.05779507756233215, -0.003178228856995702, -0.0170100387185812, 0.07574939727783203, 0.024016769602894783, -0.012580198235809803, 0.03776025399565697, -0.018...
in a list of 4 elements, can also be used in place of - 1 here.
openstax_introduction_to_python_programming_-_web
[ 0.007845102809369564, -0.007414553314447403, -0.00025176777853630483, 0.009977721609175205, -0.06779780983924866, -0.02653849497437477, 0.029372744262218475, -0.017808053642511368, 0.008653889410197735, 0.06248677149415016, 0.07456640154123306, -0.01161153707653284, 0.02303820103406906, -0...
3. 5 tuple basics 1. a. the first element, 2, is at index 0. 2. c. tuples can have elements of the same type as well as elements of different types. 3. a. a tuple must be created using commas. parentheses are optional but recommended. the three elements are " a ", " b ", and " c ". 4. b. my _ tuple is initially assigne...
openstax_introduction_to_python_programming_-_web
[ 0.008593677543103695, -0.006227248813956976, 0.03246815502643585, -0.04869253560900688, -0.06021805480122566, -0.0476238876581192, 0.016708167269825935, -0.009776105172932148, 0.00341338524594903, 0.07494267076253891, 0.038609929382801056, 0.013558910228312016, 0.01637023687362671, -0.0000...
4. 1 boolean values 1. c. " true " uses quotation marks, so the value is a string. 2. b. is _ vegetable is an integer and can be used in arithmetic operations. 3. a. a variable assigned with either true or false is a boolean variable. 4. a. a boolean variable represents the value true or false. 5. b. true and false are...
openstax_introduction_to_python_programming_-_web
[ 0.007752495352178812, -0.01081792265176773, 0.014057878404855728, -0.006112442351877689, -0.035567507147789, -0.03717482089996338, 0.07017910480499268, -0.0008125153253786266, -0.014938663691282272, 0.06079358235001564, 0.021332131698727608, -0.0013910250272601843, 0.029795339331030846, -0...
: >, <, > =, < =. using = = or! = will produce a boolean. 19. b. strings are compared by comparing each character's unicode values. letters have ascending unicode values in alphabetical order ( and are case sensitive ). " c " and " c " are equal, so " i " is compared to " o ". " i " is not equal to " o " so false is pr...
openstax_introduction_to_python_programming_-_web
[ -0.01581454649567604, -0.004040705040097237, 0.04673241823911667, -0.026409577578306198, -0.006470540072768927, -0.032903339713811874, 0.036531805992126465, 0.0024404057767242193, -0.011095588095486164, 0.06929930299520493, 0.0270061194896698, 0.01646905578672886, -0.015623044222593307, -0...
4. 2 if - else statements 1. b. age < 12 is between " if " and " : " and is an expression that evaluates to true or false. 2. c. the program executes the body when the condition is true. 3. b. the body, line 3, isn't executed because the condition is false. 4. c. - 10 < 0 is true, so num is assigned with 25. then 25 < ...
openstax_introduction_to_python_programming_-_web
[ 0.04189739748835564, 0.0077756852842867374, 0.00816693902015686, -0.020257482305169106, -0.016352428123354912, -0.014870479702949524, 0.04962436482310295, 0.027175897732377052, -0.03928327560424805, 0.08500388264656067, 0.024087056517601013, -0.009076299145817757, 0.027943050488829613, -0....
4. 3 boolean operations 1. a. 2500 < 3000 is true, and 2. 5 > 1. 0 is true, so jaden can enter. 2. b. 3000 > 3000 is false. false and true is false. false and false is false. so no value of hrs _ to _ close will allow darcy to enter. 3. b. false and true is false. 384 access for free at openstax. org 4. b. ( 8 < 10 ) a...
openstax_introduction_to_python_programming_-_web
[ 0.022288605570793152, 0.021974915638566017, -0.0009062822791747749, 0.005530997179448605, -0.016334032639861107, -0.02865874394774437, 0.01755569688975811, 0.0315469466149807, -0.019066864624619484, 0.07035160809755325, 0.027717527002096176, 0.04695748910307884, 0.017005521804094315, -0.03...
4. 4 operator precedence 1. b. exponentiation has the highest precedence, then division, then addition. 2. a. multiplication has the highest precedence, then greater than, then not. 3. b. division has the highest precedence, then equality and less than, then and. 4. b. multiplication and division have the highest prece...
openstax_introduction_to_python_programming_-_web
[ 0.010271650739014149, -0.03775356709957123, -0.0016635711072012782, -0.012222024612128735, 0.008762257173657417, -0.011660522781312466, 0.028608009219169617, 0.010027861222624779, -0.059379421174526215, 0.05207109823822975, 0.005138050299137831, 0.054803479462862015, -0.003799227299168706, ...
4. 5 chained decisions 1. b. elif will evaluate condition _ 2 if condition _ 1 is false and execute body 2 if condition _ 2 is true. 2. b. x > 44, 42 > 44, is false, so x < 50 is evaluated. 42 < 50 is true, so y = 0 + 5. only one of the if and elif branches is taken. 3. a. if x < 0, body 1 executes. else if x = = 0, bo...
openstax_introduction_to_python_programming_-_web
[ 0.028107427060604095, 0.012409788556396961, -0.004181927535682917, -0.01583530753850937, -0.039713189005851746, -0.009815466590225697, 0.012807974591851234, 0.031687021255493164, -0.010747554711997509, 0.08729790151119232, 0.01363526564091444, 0.022300133481621742, 0.004628766793757677, -0...
4. 6 nested decisions 1. c. leaf _ count = = 3 is false, so the outer else's body is executed. 2. c. num _ dancers is positive, so the else branch is taken. num _ dancers is odd, so the error is printed before the program continues after the nested if and prints num _ dancers. 3. b. 256 = = 513 is false, and 256 < 513 ...
openstax_introduction_to_python_programming_-_web
[ 0.01554796565324068, -0.0011557695688679814, -0.009114247746765614, -0.04664117842912674, -0.014927338808774948, -0.02026035264134407, 0.027449212968349457, 0.021212952211499214, 0.007182583212852478, 0.06015898287296295, 0.02475918084383011, 0.02085503749549389, 0.01947905123233795, -0.00...
4. 7 conditional expressions 1. c. the conditional expression will assign response with " even " if x is even. response is assigned with " odd " if x is odd. 2. a. 100 < 100 is false so result is assigned with x - offset = 100 - 10 = 90. 3. c. min _ num cannot be assigned with min _ num = y. the correct expression is m...
openstax_introduction_to_python_programming_-_web
[ 0.020363766700029373, 0.007804553955793381, 0.005120425019413233, -0.008080781437456608, -0.04653402045369148, -0.03463292494416237, 0.05358590930700302, -0.015442798845469952, -0.04955783486366272, 0.08321768790483475, 0.03495381027460098, 0.023738525807857513, 0.012301245704293251, -0.02...
5. 1 while loop 1. b. the loop runs six times for values of g = 1, 2, 3, 5, 8, and 13. 2. c. 21 is the first fibonacci number larger than 20, and for g = 21, the condition will evaluate to false for the first time. 3. a. the code first prints the variable f's initial value. then, at each iteration, g's value is printed...
openstax_introduction_to_python_programming_-_web
[ -0.0008326284005306661, 0.000956456467974931, 0.04852267727255821, -0.0021058020647615194, 0.01329879928380251, -0.04049626365303993, -0.013187974691390991, 0.010776964947581291, 0.001190741779282689, 0.05701545998454094, 0.03933999314904213, 0.012195467017591, 0.029223978519439697, -0.045...
5. 2 for loop 1. b. eight characters exist in the str _ var. iterating over all characters and incrementing the value of count variable at each iteration results in the count's value of 8. 2. a. since the initial count's value is 0, multiplying count by any number results in the output of 0. 3. c. the added line prints...
openstax_introduction_to_python_programming_-_web
[ 0.0010915313614532351, 0.00330797559581697, 0.040802810341119766, 0.010639638639986515, 0.002124737948179245, -0.0403447262942791, 0.012022523209452629, 0.026927201077342033, -0.040595121681690216, 0.10275203734636307, 0.004474112764000893, -0.021556392312049866, -0.005190972238779068, -0....
5. 3 nested loops 1. b. the combination of i and j values, ( i, j ), that meet the inner and outer loop conditions are as follows : ( 1, 1 ), ( 1, 2 ), ( 1, 3 ), ( 1, 4 ), ( 2, 1 ), ( 2, 2 ), ( 2, 3 ), 386 access for free at openstax. org ( 3, 1 ), ( 3, 2 ), ( 4, 1 ) 2. b. each inner loop's full execution prints three ...
openstax_introduction_to_python_programming_-_web
[ -0.010077093727886677, 0.010082594119012356, 0.023657988756895065, -0.013681120239198208, -0.014630235731601715, -0.02445281483232975, -0.03992314264178276, -0.02166058123111725, 0.006386711727827787, 0.08903038501739502, 0.0306919626891613, 0.07415175437927246, -0.021325701847672462, -0.0...
5. 4 break and continue 1. c. the code prints all characters before the first occurrence of a space character in separate lines. hence the output is : h e l l o 2. b. as soon as the print statement is executed, the break statement causes the loop's termination. also, for i = 15, the condition ( i % 3 = = 0 and i % 5 = ...
openstax_introduction_to_python_programming_-_web
[ -0.006550202611833811, 0.010509087704122066, 0.028151635080575943, 0.00029860661015845835, 0.03271621838212013, -0.030587660148739815, -0.013138632290065289, -0.001123180496506393, -0.006957648787647486, 0.09572109580039978, 0.0021931214723736048, 0.051019951701164246, 0.0006711770547553897,...
5. 5 loop else 1. b. the variable i is initialized to 16, and the while loop executes with i = 16, 8, 4, and 2. in each loop's iteration, the variable exp's value is incremented by 1. hence, at the end of the loop, exp = 4. since the loop terminates without interruption, the else statement after the loop is executed an...
openstax_introduction_to_python_programming_-_web
[ -0.019429001957178116, -0.003601923817768693, 0.003351562889292836, -0.009674586355686188, 0.004114230163395405, -0.03963090851902962, -0.009723215363919735, -0.005577423609793186, 0.0016168724978342652, 0.07505130022764206, 0.014468954876065254, 0.03904741257429123, 0.008385254070162773, ...
6. 1 defining functions 1. c. the print ( ) function is called to output the variable, offset _ num. 2. b. lines 1, 4, and 5 each call print ( ) once. lines 2 and 3 call a different function, input ( ). 3. b. line 1 is a comment that is not executed. lines 2 and 3 each call float ( ) and input ( ). line 3 calls print (...
openstax_introduction_to_python_programming_-_web
[ -0.004906952381134033, 0.009270576760172844, -0.0032224287278950214, -0.026213105767965317, -0.009963887743651867, -0.0001533300383016467, 0.013237785547971725, 0.023466315120458603, -0.0010171890025958419, 0.06460320204496384, 0.04737816005945206, 0.0274591576308012, -0.0038516628555953503,...
6. 2 control flow 1. c. line 5 is the start of the main program, which is not indented. park _ greet ( ) is called on line 6 and executed. 2. b. control flow moves to where park _ greet ( ) is defined, at line 4. 3. c. control flow returns to the line that called the function. line 12 contains the function call to extr...
openstax_introduction_to_python_programming_-_web
[ -0.0037645872216671705, 0.004416248761117458, 0.039736099541187286, -0.005126769654452801, 0.017643988132476807, -0.024096554145216942, -0.021142760291695595, 0.01107906736433506, -0.014589120633900166, 0.06605242192745209, -0.008694428950548172, 0.06380748003721237, 0.010355785489082336, ...
6. 3 variable scope 1. c. both num and num _ sq are created outside of functions and are global variables. 2. a. num is created outside of a function and is global. num _ sq is created in print _ square ( ) and is not global. 3. c. num is global and can be accessed anywhere in the program, including both print _ double...
openstax_introduction_to_python_programming_-_web
[ 0.00530267134308815, 0.01993032731115818, -0.023347511887550354, -0.021281108260154724, -0.042174555361270905, -0.008663967251777649, 0.02808302827179432, -0.0006891078664921224, -0.0032970765605568886, 0.061995554715394974, 0.0476316474378109, 0.011861283332109451, -0.008522788994014263, ...
6. 4 parameters 1. b. username is the argument passed to print _ welcome ( ). name is print _ welcome ( )'s parameter that is assigned with username's value. 2. a. name is the only parameter defined with print _ welcome ( ). username is the argument passed on line 5's function call. 3. a. name is a parameter that exist...
openstax_introduction_to_python_programming_-_web
[ 0.048162225633859634, 0.012380244210362434, 0.030183210968971252, -0.015467723831534386, -0.02271942049264908, 0.01200177799910307, -0.006932560354471207, 0.02081143483519554, -0.04681166633963585, 0.059303898364305496, 0.04339899122714996, 0.017960000783205032, 0.009369564242661, -0.04130...
6. 5 return values 1. a. calc _ mpg ( ) specifies mpg to be returned with the return statement. 2. b. return is a valid statement to end the function and return to the calling code without a specified value. calc _ sqft ( ) should return sqft with the line return sqft. 3. c. if the return value or return statement is n...
openstax_introduction_to_python_programming_-_web
[ -0.014497902244329453, 0.04327967017889023, 0.027324790135025978, 0.011580889113247395, -0.063996322453022, -0.015636537224054337, 0.01094820350408554, 0.04489037021994591, -0.0022531631402671337, 0.08286964148283005, 0.01709909550845623, 0.046667858958244324, -0.03518969938158989, -0.0347...
6. 6 keyword arguments 1. d. the function call uses all keyword arguments to assign values to the named parameters. 2. b. " hiya " is the value of msg and " ash " is the value of name in the function. 3. a. " welcome " is unnamed and assigned correctly to count. positional arguments must come before keyword arguments. ...
openstax_introduction_to_python_programming_-_web
[ 0.04339441657066345, 0.016534510999917984, 0.005670913960784674, 0.012671176344156265, -0.01877834089100361, -0.0021795921493321657, 0.01016310416162014, 0.0409100279211998, -0.0578446090221405, 0.04447612166404724, 0.021753080189228058, 0.010723914951086044, -0.021101893857121468, 0.00716...
7. 2 importing names 1. a. this statement imports the sqrt function defined in the math module. 2. b. a variable is defined for each function imported : sin, cos, and tan. 3. b. a name error occurs when a variable name is not found, which might be due to a missing import statement. 4. b. this statement replaces the pre...
openstax_introduction_to_python_programming_-_web
[ 0.023877263069152832, 0.008910689502954483, 0.04483312740921974, -0.03056168183684349, -0.042981382459402084, 0.015704359859228134, 0.017021726816892624, -0.0019768092315644026, -0.006877352483570576, 0.05053800344467163, 0.05681620165705681, 0.02785693109035492, -0.03141579404473305, -0.0...
7. 3 top - level code 1. b. whenever this module is imported, python will output " defining sphere function " as a side effect. 2. a. even though nothing is printed, calling the sphere function ten million times causes a delay in the main program. 3. a. all code is at the top level, and no functions are defined. import...
openstax_introduction_to_python_programming_-_web
[ -0.002860925393179059, 0.0084305414929986, 0.00030362303368747234, -0.028501223772764206, -0.0026902207173407078, 0.0023481943644583225, -0.010372459888458252, -0.007593437097966671, -0.012005695141851902, 0.03679924085736275, 0.0063257887959480286, 0.031146563589572906, 0.01105836033821106,...
7. 4 the help function 1. b. the digits have 0 red and 0 green, so the color must be a shade of blue. navy is a darker version of standard blue, # 0000ff. 2. c. ff in hexadecimal is 255, the maximum amount of red, green, or blue in a color. 3. a. the red, green, and blue values for orange are higher than the red, green...
openstax_introduction_to_python_programming_-_web
[ 0.048059359192848206, -0.007287215441465378, 0.038994330912828445, 0.017826024442911148, -0.053437091410160065, 0.003572308924049139, 0.014357978478074074, 0.0074632428586483, -0.007315888535231352, 0.09647559374570847, 0.03914636746048927, 0.008958805352449417, 0.017827054485678673, -0.00...
7. 5 finding modules 1. a. this reference describes the standard library, including built - in functions, types, and modules. 2. b. as explained in the documentation of the calendar module, monday is 0 and sunday is 6. 3. a. the tkinter module stands for tk interface. tk is a standard toolkit for creating windows, text...
openstax_introduction_to_python_programming_-_web
[ 0.06565622985363007, 0.010275323875248432, -0.026719296351075172, -0.0035290291998535395, -0.037873029708862305, -0.019451092928647995, 0.020895805209875107, 0.009133178740739822, -0.002412740606814623, 0.08065469563007355, -0.025124382227659225, -0.0029334307182580233, 0.024650180712342262,...
8. 1 string operations 1. a. since a's ascii value is less than b's ascii value, the output for " aaa " < " aab " is true. 2. b. since " a " is shorter than " aa ", and the prefix " aa " with length 1 equals the second operand ( " a " ), the shorter string is considered smaller. as such, " aa " < " a " evaluates to fal...
openstax_introduction_to_python_programming_-_web
[ 0.009112163446843624, -0.02239791490137577, 0.03755258023738861, -0.01902487687766552, -0.017744455486536026, -0.02586817927658558, 0.035829808562994, -0.030688682571053505, 0.004661119543015957, 0.0675465539097786, 0.02382492832839489, 0.00827731192111969, -0.025545822456479073, -0.070562...
8. 2 string slicing 1. b. since indexing starts from 0, the character at index 1 is the second character in the string, which is " e ". 2. b. since negative indexing starts from - 1 from the right of the string to the left, " u " is at index - 2. 3. a. character " e " in the string " chance " has index of - 1 ( negativ...
openstax_introduction_to_python_programming_-_web
[ 0.006484915968030691, -0.011480063199996948, 0.017169667407870293, -0.02089690789580345, -0.030356278643012047, -0.03551950678229332, 0.028420569375157356, -0.005850168410688639, -0.020733080804347992, 0.09729684144258499, 0.008518830873072147, -0.02490631490945816, 0.03201090171933174, -0...
8. 3 searching / testing strings 1. c. since " a " is a substring of " an umbrella ", the output of " a " in " an umbrella " is true. 2. b. " ab " is not a substring of " arbitrary " ; hence, the output is false. 3. a. since " " is a substring of length 0 for " string ", the output is true. 4. a. the for loop iterates ...
openstax_introduction_to_python_programming_-_web
[ 0.003907803446054459, 0.00598389096558094, 0.032256703823804855, -0.022130118682980537, -0.006456008646637201, -0.013661336153745651, -0.0055403742007911205, -0.013008339330554008, 0.01606564223766327, 0.08783400803804398, 0.03319898620247841, -0.007818319834768772, -0.00712205097079277, -...
b ", - 1 is returned. 13. a. the index ( ) method returns the index of the start of the first occurrence of a substring in the given string. the index of the first occurrence of " o " in " school " is 3. 14. c. substring " ooo " does not exist in the string " ooo " and hence the index ( ) method returns a valueerror. 1...
openstax_introduction_to_python_programming_-_web
[ -0.010573131963610649, -0.009935804642736912, 0.005437950603663921, -0.0014011559542268515, -0.010032515041530132, -0.02883218415081501, -0.022334007546305656, -0.011286907829344273, 0.011044638231396675, 0.07829276472330093, 0.004580862820148468, -0.004609675146639347, 0.0010197428055107594...
8. 4 string formatting 1. c. " ana " is substituted for the replacement field { } in the template and hence the output is " hello ana! ". 2. b. the two arguments are passed to the template " { } : { } " that outputs " one : 1 ". 3. a. the arguments for the format ( ) function are passed in order and will be substituted...
openstax_introduction_to_python_programming_-_web
[ 0.019677406176924706, -0.014608284458518028, 0.05335618555545807, 0.008534292690455914, -0.025104153901338577, -0.013935943134129047, 0.017689522355794907, -0.0024424572475254536, -0.015075860545039177, 0.047607824206352234, 0.030539730563759804, 0.006159450393170118, -0.011715302243828773, ...
. b. { : + d } formats the decimal number by adding the positive sign.
openstax_introduction_to_python_programming_-_web
[ 0.004726382438093424, -0.009470712393522263, 0.020612070336937904, -0.01813606359064579, -0.007479946129024029, 0.008959424681961536, 0.08384349942207336, 0.004987470805644989, -0.009598474949598312, 0.06452540308237076, 0.0016893928404897451, 0.006558135151863098, 0.002361457794904709, 0....
8. 5 splitting / joining strings 1. b. when " 1 * 2 * 3 * " is broken into substrings using the'*'delimiter, the output is [ " 1 ", " 2 ", " 3 " ]. 2. c. when " a year includes 12 months " is broken into substrings using blank space characters, the list [ " a ", " year ", " includes ", " 12 ", " months " ] is created. ...
openstax_introduction_to_python_programming_-_web
[ 0.012511307373642921, 0.0013076923787593842, 0.0483827069401741, 0.015904823318123817, -0.028227614238858223, -0.05067065358161926, 0.006906307302415371, 0.0023458239156752825, 0.04110536724328995, 0.0992770716547966, -0.0006873334641568363, 0.02606523036956787, -0.00907955039292574, -0.05...
9. 1 modifying and iterating lists 1. b. the append ( ) operation adds an element to the end of a list. 392 access for free at openstax. org 2. c. the element to be removed is passed as a parameter to the remove operation. the remove is performed on the specified list. 3. c. both pop ( ) and remove ( ) can be used to r...
openstax_introduction_to_python_programming_-_web
[ -0.015756720677018166, -0.018966298550367355, 0.011294137686491013, 0.009012105874717236, -0.017425866797566414, -0.019913746044039726, -0.03459719195961952, -0.013655039481818676, 0.026755262166261673, 0.09151026606559753, -0.003727103117853403, 0.006060144864022732, -0.012168698012828827, ...
9. 2 sorting and reversing lists 1. b. sorting in descending order means to arrange the elements from largest to smallest. - 3 is the smallest element of the list and would be the last element when the list is sorted in descending order. 2. a. for strings, ascending order refers to dictionary order. 3. c. in alphabetic...
openstax_introduction_to_python_programming_-_web
[ -0.0016040713526308537, -0.03425765782594681, -0.010678715072572231, -0.013122315518558025, -0.02898658812046051, -0.010111067444086075, 0.011956063099205494, 0.025875721126794815, -0.020299032330513, 0.08560348302125931, -0.005611239466816187, 0.02278038114309311, -0.008988535962998867, -...
9. 4 nested lists 1. a. each row of the matrix is represented as a list in the larger list - of - lists, mata. mata represents the complete matrix. 2. c. 6 is in the 2nd row and 3rd column. using zero - indexing results in index 1 for the row and 2 for the column. 3. c. the first element of the list mata is a list [ 7,...
openstax_introduction_to_python_programming_-_web
[ 0.014409735798835754, 0.007337882183492184, 0.03646034002304077, -0.05533906817436218, 0.017644962295889854, -0.03049503266811371, -0.01624813862144947, -0.02936934120953083, -0.00391630781814456, 0.06984031200408936, 0.01761067658662796, 0.08341168612241745, -0.000734965899027884, -0.0434...
9. 5 list comprehensions 1. a. the expression tells python what element to put in the new list. 2. c. i + 2 results in adding 2 to each element of a _ list to generate b _ list. 3. b. the for loop starts at 1 and steps by three, so it begins at 1 and ends at 13. dividing using the / / operator results in dropping the p...
openstax_introduction_to_python_programming_-_web
[ -0.0009870619978755713, 0.0013862348860129714, 0.011245844885706902, -0.03544047474861145, -0.018087996169924736, -0.030078742653131485, 0.03753800317645073, 0.022068189457058907, -0.022705236449837685, 0.12240149825811386, -0.021656502038240433, 0.03105716034770012, 0.03036043606698513, 0...
10. 1 dictionary basics 1. a. the first item in each key - value pair is the key. hence " sunday ", " monday ", " tuesday " are key items. 2. b. the second item in each key - value pair is the value. hence 1, 2, 3 are value items. 3. b. based on the days dictionary object, the value assigned to " sunday " is 1. 4. b. t...
openstax_introduction_to_python_programming_-_web
[ 0.007764048874378204, -0.0007046224782243371, 0.008688223548233509, -0.04528246819972992, -0.03299332037568092, 0.002819396322593093, 0.017733518034219742, 0.011965162120759487, 0.010989466682076454, 0.08876626193523407, 0.002018387895077467, 0.010770286433398724, 0.010710218921303749, 0.0...
10. 2 dictionary creation 1. b. curly braces can be used to create an empty dictionary. 2. c. { " one " : 1 } creates a dictionary object with one item " one " : 1. 3. b. two pairs of items exist in the my _ dict dictionary. the two pairs are " a " : 1 and " b " : 2. 4. b. dict ( ) function, along with keyword argument...
openstax_introduction_to_python_programming_-_web
[ 0.004616974387317896, 0.0034958282485604286, 0.0015097636496648192, -0.019881080836057663, -0.04809866100549698, -0.001448833616450429, 0.02417665533721447, 0.004490398336201906, 0.013472005724906921, 0.09074912965297699, 0.03006967157125473, -0.023548264056444168, -0.007801830302923918, -...
10. 3 dictionary operations 1. c. the value associated with the key " jaya " is " student ". 2. b. when a key does not exist in a dictionary, none is returned by default. 3. b. the second argument to the get ( ) function will be returned if the key is not found in the dictionary. 4. a. the return type of keys ( ) funct...
openstax_introduction_to_python_programming_-_web
[ -0.011866197921335697, -0.006534783635288477, -0.03904688358306885, -0.00685122050344944, -0.04973316565155983, -0.01647212728857994, -0.016286548227071762, 0.005641494877636433, -0.011192644014954567, 0.10088647156953812, 0.007664847187697887, 0.008431416936218739, -0.011472003534436226, ...
10. 4 conditionals and looping in dictionaries 1. a. " apple " is a key in the dictionary and exists in the returned keys from fruit _ count. keys ( ). 2. b. the key " orange ", with associated value 5, exists in the dictionary and the return value is true. 3. b. conditional statements can be written to examine keys an...
openstax_introduction_to_python_programming_-_web
[ 0.018456006422638893, -0.005222315434366465, -0.008493674919009209, -0.002031957730650902, 0.013312817551195621, -0.03631210699677467, -0.017366847023367882, 0.014140760526061058, 0.018263807520270348, 0.08356232196092606, 0.01670193299651146, 0.011240925639867783, -0.005491149146109819, -...
10. 5 nested dictionaries and dictionary comprehension 1. b. a nested dictionary contains another dictionary. 2. c. both outer and inner keys must be used to index into both outer and inner dictionaries, respectively, to obtain an inner value. 3. b. a nested dictionary is a value of another dictionary, representing the...
openstax_introduction_to_python_programming_-_web
[ -0.01577494479715824, 0.000285534915747121, -0.0008470175671391189, -0.05548711121082306, -0.034590136259794235, 0.00651519512757659, -0.004586589056998491, -0.021515237167477608, 0.0034228593576699495, 0.07178917527198792, -0.019345831125974655, 0.046810928732156754, -0.007127443794161081, ...
11. 2 classes and instances 1. a. cat follows the class keyword at the top of the class definition and is the name of the class. 2. c. pet _ 1 is an instance of the cat class created by calling cat ( ). the other instance is pet _ 2. 3. a. breed is an instance attribute defined in _ _ init _ _ ( ). the other instance a...
openstax_introduction_to_python_programming_-_web
[ 0.018596502020955086, -0.0012838216498494148, 0.03017706796526909, -0.046474289149045944, -0.005497786682099104, 0.002526636701077223, 0.009760313667356968, -0.0009902769234031439, -0.009877046570181847, 0.05417760834097862, 0.04721862077713013, -0.01215093769133091, 0.01935260370373726, -...
to access a class attribute using an instance is unsafe. in _ _ init _ _ ( ), trying to access the class attribute creates a new instance attribute called cls _ id. though possible, programmers should avoid using the same name for class attributes and instance attributes to avoid confusion.
openstax_introduction_to_python_programming_-_web
[ -0.02233678102493286, -0.023210054263472557, 0.01766728237271309, -0.02529207430779934, 0.007135778199881315, 0.002091204049065709, 0.024050720036029816, -0.003241542726755142, 0.0019904724322259426, 0.0265823807567358, 0.02454550750553608, -0.016248809173703194, 0.030019167810678482, -0.0...
11. 3 instance methods 1. b. removing the default parameter value makes bp a required parameter. 2. b. self is the first parameter in _ _ init _ _ ( ) definition, not an explicit argument. self should not be included in the call. 3. c. the second definition overwrites the first as multiple explicit definitions of _ _ i...
openstax_introduction_to_python_programming_-_web
[ 0.009503061883151531, -0.007784741930663586, 0.026763498783111572, -0.025191020220518112, -0.03733394667506218, -0.0028133541345596313, -0.005365078337490559, 0.005390513222664595, -0.012446083128452301, 0.07292141020298004, 0.04525704309344292, -0.021117325872182846, 0.011768192984163761, ...
11. 4 overloading operators 1. c. _ _ add _ _ ( ) is a magic method, indicated by the double underscores at the start and end of the method name. 2. b. magic methods are designed to be invoked internally to perform under - the - hood actions to simplify tasks for the user. 3. c. _ _ init _ _ ( ) is defined by the progr...
openstax_introduction_to_python_programming_-_web
[ 0.015543765388429165, -0.0286569707095623, 0.02595166303217411, -0.05117218196392059, -0.009038961492478848, -0.02114657126367092, 0.04028574004769325, 0.020281633362174034, -0.033523716032505035, 0.04636082053184509, 0.02863140217959881, 0.01124121155589819, 0.009669126011431217, -0.04327...
11. 5 using modules with classes 1. b. level and xp are classes imported from the character module into the program. any other class in the character module is not imported. 2. b. a single class or multiple classes can be imported from a module using the class name ( s ). 3. c. the number of classes in a module is unli...
openstax_introduction_to_python_programming_-_web
[ 0.0630209669470787, 0.009101035073399544, 0.014169512316584587, 0.012205956503748894, -0.02180389128625393, -0.012371690012514591, 0.05149510130286217, 0.006235870067030191, -0.030597005039453506, 0.07598092406988144, 0.04703870043158531, 0.03362051770091057, 0.04046403616666794, -0.019463...
12. 1 recursion basics 1. a. the move of the smaller ring, which is a smaller problem, is done twice on the way to solving for the two rings overall. the task of moving all three rings is broken down into smaller tasks of moving one ring at a time. 2. b. the two - ring solution from question 1 is used in the solution f...
openstax_introduction_to_python_programming_-_web
[ 0.028328198939561844, 0.031254760921001434, 0.007982519455254078, 0.002210121601819992, -0.031256966292858124, -0.016161248087882996, -0.054837699979543686, 0.033617064356803894, 0.0056485263630747795, 0.09746617078781128, 0.05922688543796539, 0.027546441182494164, -0.010663457214832306, -...
12. 2 simple math recursion 1. the summation can be calculated using recursion because there is a regular pattern and the summation to n depends on the summation to n - 1. 2. each number in the sequence can be found by adding 2 to the previous number, with the solution at 1 being 1. 3. a prime number does not depend on...
openstax_introduction_to_python_programming_-_web
[ 0.0015025980537757277, 0.013829102739691734, 0.0359661690890789, -0.03751133754849434, 0.012331648729741573, -0.04579830914735794, -0.037500858306884766, 0.02068847231566906, 0.003182975109666586, 0.09881826490163803, 0.03226277977228165, -0.0323866531252861, -0.010588504374027252, 0.00401...
12. 3 recursion with strings and lists 1. b. once changed to all lower case, the word " madam " is a palindrome, so the function will recognize the word as a palindrome. 2. a. when a palindrome has an even number of letters, eventually an empty string is left as pairs of letters are removed. thus, the base case should ...
openstax_introduction_to_python_programming_-_web
[ -0.012968238443136215, -0.002206090372055769, 0.02420325204730034, -0.02261522226035595, -0.032169900834560394, -0.04979206994175911, 0.004421064164489508, 0.0032346074003726244, -0.0113665871322155, 0.07623445242643356, 0.0377153605222702, 0.004202342592179775, -0.002879653824493289, -0.0...