对若干个正数求和,输入“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)
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)
举一反三
- 对若干个正数求和,输入“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为止,求输入的数字的和值并输出。 输入:1 3 4 8 -1 输出:16 程序代码如下,下划线处的代码应该是:( )。 s=0 x=eval(input()) while x!=-1: ___________________ print(s) A: x=eval(input());s=s+x B: x=eval(input());s=x C: s=x;x=eval(input()) D: s=s+x;x=eval(input())
- 下列程序段可以正确运行的有: A: int i,s,x;s=0;i=0;while(1){ scanf("%d",&x); if(x!=-1) { s=s+x; i++; } else break;}printf("ave=%d\n",s/i); B: int i,s,x;s=0;i=0;scanf("%d",&x);while(x!=-1){ s=s+x; i++; scanf("%d",&x);}printf("ave=%d\n",s/i); C: int i,s,x;s=0;i=0;while(1){ scanf("%d",&x); if(x==-1) break; s=s+x; i++; }printf("ave=%d\n",s/i);
- 对下面程序段描述正确的是 ______. int x=0,s=0; while (!x!=0) s+=++x; printf("%d",s);
- 设有以下程序段 int x=0,s=0; while(!x!=0) s+=++x; printf("%d",s); 则()