想要使用while循环重复打印3次OK,下列代码正确的是?
A: a = 0while a < 3: a += 1 print('OK')
B: a = 0while a < 10: a += 1 print('OK')
C: a = 0while a < 3: a += 1print('OK')
D: a = 0while a < 3: print('OK')
A: a = 0while a < 3: a += 1 print('OK')
B: a = 0while a < 10: a += 1 print('OK')
C: a = 0while a < 3: a += 1print('OK')
D: a = 0while a < 3: print('OK')
举一反三
- 对若干个正数求和,输入“ok”结束,下面正确的代码是( )。知识点:while循环。 A: s = 0x = input()while x!="ok": s += int(x) print(s) B: s = 0while True: x = input() if x=="ok": break s += int(x) print(s) C: s = 0x = input()while x!="ok": s += int(x) x = input()print(s) D: s = 0while x!="ok": x = input() s += int(x) print(s)
- 在下列代码中,哪一个选项的print语句能够被执行? A: if 4 < 3: print('OK') B: if 4 == 3: print('OK') C: if 4 != 3: print('OK') D: if 3 = 3: print('OK')
- 对若干个正数求和,输入“ok”结束,下面正确的代码是( )。知识点:while循环。 A: s = 0x = input()while x!="ok": s += int(x) print(s) B: s = 0while True: x = input() if x=="ok": break s += int(x) print(s) C: s = 0x = input()while x!="ok": s += int(x) x = input()print(s) D: s = 0while x!="ok": x = input() s += int(x) print(s)
- 运行下列代码段,输出结果中包含1的是( )。 A: while True:print(1) B: while False:print(1) C: while 1:print(1) D: while 0:print(1)
- 下面代码中输出结果为0、1、2三个数字的有(_____)。 A: for i in range(3): print(i) B: i=1 while i<3: print(i) i+=1 C: i=3 while i>1: i=i-1 print(3-i) D: for i in range(3,0,-1): print(3-i)