1、有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?
list1 = [1,2,3,4]
result = []
for x in list1:
for y in list1:
for z in list1:
if x != y and x != z and y != z:
a = x*100+y*10+z
result.append(a)
print result
print len(result)
2、企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高
I = input("请输入当月利润:") #利润可为整数或浮点数,所以不建议用raw_input
tj = [1000000,600000,400000,200000,100000,0] #条件
tc = [0.01,0.015,0.03,0.05,0.075,0.01] #提成
reward = 0 #初始化奖金
for i in range(6):
if I >= tj[i]:
reward += (I-tj[i])*tc[i]
I = tj[i]
print reward
3、一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?(求1000以内的所有满足条件的数)
from math import sqrt
for z in range(1000):
x = int(sqrt(z+100))
y = int(sqrt(z+100+168))
if x**2 == z+100 and y**2 == z+100+168:
print z
for x in range(1,10):
for y in range(10):
for z in range(10):
i = x*100 + y*10 + z
if x**3+y**3+z**3 == i:
print i
n = int(raw_input("请输入要分解的正整数:"))
num = n
for k in range(2,n):
while n != k:
if n%k == 0:
print "%d*"%k,
n = n/k
else:
break
print "%d=%d"%(n,num)
最大公约数:指两个或多个整数共有约数中最大的一个
最小公倍数=两数的乘积/最大公约(因)数
m = int(raw_input("请输入正整数m:"))
n = int(raw_input("请输入正整数n:"))
x = m
y = n
if n>m:
m,n = n,m
for i in range(n):
k = m%n
if k != 0:
m,n =n,k
MAXgy = n #最大公约数
MINgb = x*y/MAXgy #求最小公倍数
print "最大公约数为:" + str(MAXgy)
print "最小公倍数为:" + str(MINgb)
a = raw_input("请输入计算值a: ")
n = input("几个数进行相加? ")
str = ""
for i in range(1,n+1):
str += a*i+"+"
print "%s = %d"%(str[:-1],eval(str[:-1]))
ws = []
for n in range(1,1000):
t = []
for i in range(1,n):
if n%i == 0:
t.append(i)
if sum(t) == n:
ws.append(n)
print ws
x = int(raw_input("最大宽度几颗星:"))
for i in range(x):
print " "*(x-i-1),"* "*(i+1)
for j in range(x):
print " "*(j+1),"* "*(x-j-1)