您的当前位置:首页正文

Python程序设计课后习题答案-第三单元

来源:华拓网
 习题3 一、选择题 1.以下不合法的表达式是( )。D A.x in [1,2,3,4,5] B.x-6>5 C.e>5 and 4==f D.3=a 2.将数学式22 or x <=10 3.与关系表达式x==0等价的表达式是( )。B A.x=0 B.not x C.x D.x!=1 4.下列表达式的值为True的是( )。A A.2!=5 or 0 B.3>2>2 C.5+4j>2-3j D.1 and 5==0 5.下面if语句统计“成绩(mark)优秀的男生以及不及格的男生”的人数,正确的语句为( )。C A.if gender==\"男\" and mark<60 or mark>=90:n+=1 B.if gender==\"男\" and mark<60 and mark>=90:n+=1 C.if gender==\"男\" and (mark<60 or mark>=90):n+=1 D.if gender==\"男\" or mark<60 or mark>=90:n+=1 6.以下if语句语法正确的是( )。D A. if a>0:x=20 else:x=200 B. if a>0:x=20 else: x=200 C. if a>0: x=20 else:x=200 D. if a>0 x=20 else x=200 7.在Python中,实现多分支选择结构的较好方法是( )。C A.if B.if-else C.if-elif-else D.if嵌套 8.下列语句执行后的输出是( )。C if 2: print(5) else: print(6) A.0 B.2 C.5 D.6 9.下面程序段求x和y中的较大数,不正确的是( )。D A.maxNum=x if x>y else y B. if x>y:maxNum=x else:maxNum=y C. maxNum=y if x>y:maxNum=x D. if y>=x:maxNum=y maxNum=x 10.下列Python程序的运行结果是( )。B x=0 y=True print(x>y and 'A'<'B') A.True B.False C.true D.false 二、填空题 1.表达式2<=1 and 0 or not 0的值是 。True 2.已知ans='n',则表达式ans=='y' or 'Y'的值为 。'Y' 3.Python提供了两个对象身份比较运算符 和 来测试两个变量是否指向同一个对象。is,is not 4.在直角坐标中,x、y是坐标系中任意点的位置,用x和y表示第一象限或第二象限的Python表达式为 。x>0 and y>0 or x<0 and y>0 5.已知a=3,b=5,c=6,d=True,则表达式not d or a>=0 and a+c>b+3的值是 。True 6.Python表达式16-2*5>7*8/2 or \"XYZ\"!=\"xyz\" and not(10-6>18/2)的值为 。 True 7.下列Python语句的运行结果是 。True x=True y=False z=False print(x or y and z) 8.执行下列Python语句将产生的结果是 。True False m=True n=False p=True b1=m|n^p;b2=n|m^p print(b1,b2) 9.对于if语句中的语句块,应将它们 。缩进对齐 10.当x=0,y=50时,语句z=x if x else y执行后,z的值是 。50 三、问答题 1.写出条件“200: if j>0:n=1 else:n=2 语句二: if i>0: if j>0:n=1 else:n=2 语句三: if i>0:n=1 else: if j>0:n=2 语句一相当于:i0,j0i0,j0n1 n2 语句二相当于:i0,j0i0n1 n2n1 n2语句三相当于:i0,i0,j0

因篇幅问题不能全部显示,请点此查看更多更全内容