python求100以内素数之和 from math import sqrt # 使用isPrime函数 def isPrime(n): if n <= 1: return False for i in range(2, int(sqrt(n)) + 1): if n % i == 0: return False return True count = 0 for i in range(101): if isPrime(i): count += i print(count) # 单行程序扫描素数
一.求算术平方根 a=0 x=int(raw_input('Enter a number:')) if x >= 0: while a*a < x: a = a + 1 if a*a != x: print x,'is not a perfect square' else: print a else: print x,'is a negative number' 二.求约数 方法一: divisor = [ ] x=int(raw_input('Enter a number:')) i=1 w
在统计分析中,有时候需要计算矩阵每列非0元素的个数,可以用以下方法: 先用find找到每列不为0的元素index,然后用count计数. 假设有矩阵A[M,N], 结果存在countZeros countZeros=zeros(1,N); for i=1:M countZeros(i)=length(find(A(:,i)>0); end
.请教一个面试中遇到的SQL语句的查询问题 表中有A B C三列,用SQL语句实现:当A列大于B列时选择A列否则选择B列,当B列大于C列时选择B列否则选择C列. ------------------------------------------ select (case when a>b then a else b end ), (case when b>c then b esle c end) from table_name drop table table1 create table t
数据库中有A B C三列,用SQL语句实现:当A列大于B列时选择A列否则选择B列,当B列大于C列时选择B列否则选择C列. 方法一: select (case when a>b then a else b end ),(case when b>c then b esle c end) from 表名 方法二: select if(a>b,a,b),if(b>c,b,c) from 表名