x=100[br][/br] y=x+1 if x>=0: print(x,y) if x==0: y=x print(y) else: y=x-1 print(y)
举一反三
- 下面哪个分支程序的语法和程序逻辑不正确的为: A: if x<y:<br> print("x小于y") B: if x<y:<br> print('x小于y')<br> else:<br> print('x大于y') C: if x<y:<br> print('x小于y') D: if x<y:<br> print("x小于y")<br> else:<br> print("x大于y")
- def fun(x,y): global x,y t=x x=y y=t x=0 y=1 fun(x,y) print(x,y) 结果是 1 0
- 为了在运行下面的程序之后得到输出y=25,键盘输入x应该是___或____。 INPUT x IF x<0 THEN y=(x+1)*(x+1) ELSE y=(x-1)*(x-1) ENDIF PRINT y
- 1.以下“if-elif-else”程序正确的是() A: if x>;yprint(x)elif y>;zprint(y)print(z) B: if x>;y:print(x)elif y>;z:print(y)else:print(z) C: if x>;y:print(x)elif x>;y:print(y)else:print(z) D: if x>;yprint(x)elif y>;zprint(y)elseprint(z)
- Which of the following are NOT valid if/else statements in Python, assuming x and y are defined appropriately: A: if x < y: print('foo') else: print('bar') B: if x < y and x > 10: print('foo') C: if x < y: print('foo'); print('bar'); print('baz') D: if x < y: print('foo') elif y < x: print('bar') else: print('baz')