s=0for i inrange(1,5):#从1到四遍历for j inrange(1,5):for c inrange(1,5):if(i != j)and(i != c)and(c != j):print(i*100+j*10+ c *1)#i做为百位,j作为十位,c作为个位
s +=1print('共有%s种'% s)
2. 101 ~ 200 の間に素数がいくつあるかを判断し、すべての素数を出力します。
count =0
leap =1from math import sqrt
for m inrange(101,201):#循环
k =int(sqrt(m +1))for i inrange(2, k +1):if m % i ==0:
leap =0breakif leap ==1:print('%5d'% m, end='')
count +=1if count %10==0:print(end='')
leap =1print('\n')print('101-200之间一共有%d个素数'% count)
3. 正の整数を素因数に分解します。例: 90 を入力、90 を出力 = 2 3 3*5
from sys import stdout
from pip._vendor.distlib.compat importraw_input
n =int(raw_input("请输入一个正整数:"))print("n = %d"% n)for i inrange(2, n +1):while n != i:if n % i ==0:
stdout.write(str(i))
stdout.write("*")
n = n / i
else:breakprint("%d"% n)
4. 文字列を入力し、その中に含まれる英文字、スペース、数字、その他の文字の数を数えます。
s=input('请输入字符:')
letter=0#英文字母
space=0#空格
digit=0#数字
other=0#其他for i in s:if i.isalpha():#判断是否是字母
letter+=1elif i.isspace():#判断是否是空格
space+=1elif i.isdigit():#判断是否是数字
digit+=1else:
other+=1print('字母个数为{}\n空格字数为{}\n数字字数为{}\n其他字符为{}\n'.format(letter,space,digit,other))
5. 1 ~ 25 の階乗の合計
a=1sum=0for i inrange(1,26):
a=a*i
sum=sum+a
print("1-20的阶乘:\n",sum)