假设 number 的输入是9。以下程序将显示什么?number = eval(input("Enter an integer: ")) isPrime = True for i in range(2, number): if number % i == 0: isPrime = False print("i is", i) if isPrime: print(number, "is prime") break else: print(number, "is not prime")
A: i is 3 9 is prime
B: i is 3 9 is not prime
C: i is 2 9 is prime
D: i is 2 9 is not prime
A: i is 3 9 is prime
B: i is 3 9 is not prime
C: i is 2 9 is prime
D: i is 2 9 is not prime
举一反三
- 题目:将一个正整数分解质因数。例如:输入90,打印出90=2*3*3*5. n = int(input("input number:")) print ("n = %d" % n) for i in range(2,n + 1): while __________ if n % i == 0: print(str(i)) print("*") n = n / i else: break print( "%d" % n)
- int number_range=20;int number=2;boolean isprime=true;while(number<;number_range){isprime=true;for(int divlsor=2;divlsor<;=number/2;divlsor++){if(______){isprime=false;break;}}if(isprime){out.println(number+"<;br>;");}number++;}%>; A: divlsor%number==0 B: number%divlsor==0 C: divlsor/number==0 D: number/divlsor==0
- 下列语句的输出结果是: number = 4 while number >; 0: for i in range(number): print(i, end='') number -= 1 A: 0123012010 B: 012301201 C: 01230120 D: 0123012
- 下列选项中,能找出三位数中,所有个位数字是9并且是3的倍数的数的代码是( )。 A: for i in range(100,1000): if i%10=9 and i%3=0: print(i,end=' ') B: for i in range(100,1000): if i//10==9 and i//3==0: print(i,end=' ') C: for i in range(100,1000): if i%10==9 and i%3==0: print(i,end=' ') D: for i in range(100,1000): if i%10==9 and i%3==0: print(i,end=' ')
- 假设sqrt(n)函数中涉及的算法时间复杂度为O(1),那么下面的算法是判断n是否为素数,其时间复杂度为( )。void prime(int n){ for (i=2; isqrt(n) (n % i)!=0; i++) ; if (isqrt(n)) printf(%d is a prime number, n); else printf(%d is not a prime number, n);} A: O(n) B: O(1) C: O(sqrt(n)) sqrt表示对n取根方 D: O(n-i)