1. 程式人生 > >python day07作業答案

python day07作業答案

1.

sum=0
a=input()
for i in a:
    sum=sum+int(i)**3
if sum==int(a):
    print('水仙數')

2.

lst=[100,2,6,9,1,10,12,35,10,15,16,1,9,65,8,100,0,1,9,5,6]
count=0
while count<len(lst):
    for i in range(0, len(lst) - 1):
        if lst[i] > lst[i + 1]:
            lst[i + 1], lst[i] = lst[i], lst[i + 1]
        
elif lst[i] == lst[i + 1]: continue count+=1 print(lst)

3.

from random import randint
a=randint(0,20)
lst=set()
count=0
while len(lst)<7:
        lst.add(randint(0,20))
print(lst)

4.

a=int(input('輸入工資:'))
sum=0
if a <2000:
    sum=sum+0
elif a <4000:
    sum=sum+(a-2000)*0.03
elif
a <6000: sum=sum+(a-4000)*0.04+2000*0.03 elif a<10000 : sum=sum+(a-6000)*0.08+2000*0.04+2000*0.03 elif a >10000: sum=sum+(a-10000)*0.2+2000*0.08+2000*0.04+2000*0.03 print(sum) print(a-sum)