您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 项目/工程管理 > 71python实现贪吃蛇
Chapter4Selections1.,=,==,!=,,=2.Yes.ibecomes1,jbecomes0,b1becomesTrue,andb2becomesFlase.3.random.randrange(0,20)orrandom.randint(0,19)4.random.randrange(10,20)orrandom.randint(10,19)5.random.randrange(10,50+1)orrandom.randint(10,50)6.random.randrange(0,2)orrandom.randint(0,1)7.ify0:x=18.ifscore90:pay*=1.039.ifscore90:pay*=1.03else:pay*=1.0110.Ifnumberis30,(a)displays30iseven30isodd(b)displays30isevenIfnumberis35,(a)displays35isodd(b)displays35isodd11.Note:elsematchesthesecondifclause.Theoutputis“xis3”ifx=3andy=2.Theoutputis“zis7”ififx=3andy=4.Nooutputififx=2andy=2.x2FalseTrueprint(xis,x)y2FalseTruez=x+yprint(zis,z)12.Note:elsematchesthefirstifclause.Theoutputis“xis2”ifx=2andy=4.Nooutputififx=3andy=2.Theoutputis“zis6”ififx=3andy=3.x2FalseTrueprint(xis,x)y2FalseTruez=x+yprint(zis,z)13.Considerscoreis90,whatwillbethegrade?Theconditionsaretestedinthewrongorders.14.(A)and(C)areequivalent.(B)and(D)areincorrectlyindented.15.newLine=(count%10==0)16.Botharecorrect.(B)isbetter.Bothconditionsin(A)aretested.In(B)theconditionistestedonlyonce.17.Fornumberis14,(a)displays:14iseven(b)displays14isevenFornumberis15,(a)displays:15ismultipleof5(b)displays15ismultipleof5Fornumberis30,(a)displays:30iseven30ismultipleof5(b)displays30iseven18.Yes19.Thisprogramwillhavearuntimeerror,becausetaxwillnotbecreated.20.(true)and(34)Falsenot(x0)and(x0)False(x0)or(x0)True(x!=0)or(x==0)True(x=0)or(x0)True(x!=1)==not(x==1)True21.(x1)and(x100)22.((x1)and(x100))or(x0)23.x=y=0Falsex=y=0Truex!=y==5True(x!=0)or(x==0)True24.Yes25.Ifchis'A',theexpressionistrue;Ifchis'p',theexpressionisfalse;Ifchis'E',theexpressionistrue;Ifchis'5',theexpressionisfalse;26.(xyandyz)isTrue(xyoryz)isTruenot(xy)isFalse(xyz)isTruenot(xyz)isFalse27.age13andage1828.weight50orheight160.29.weight50andheight160.30.(weight50orheight160)andnot(weight50andheight160)31.Sorted32.ticketPrice=20if(ages=16)else10print(count,end=\nifcount%10==0else)33.A:ifx10:score=3*scaleelse:score=4*scaleB:ifincome10000:tax=income*0.2else:tax=income*0.17+1000C:ifnumber%3==0:print(i)else:print(j)34.TheprecedenceorderoftheBooleanoperatorsarenot,and,orinthisorder.TrueTrue35.True36.2*2-32and4–25False2*2-32or4–25False37.Yes.Yes.Yes.
本文标题:71python实现贪吃蛇
链接地址:https://www.777doc.com/doc-4159187 .html