輸入三個整數x,y,z,請把這三個數由小到大輸出。 1.程序分析:咱們想辦法把最小的數放到x上,先將x與y進行比較,若是x>y則將x與y的值進行交換, 而後再用x與z進行比較,若是x>z則將x與z的值進行交換,這樣能使x最小。python
1,比較大小app
list1 = []ide
for i in range(3):code
n = input('Please input number:') list1.append(n)
list1.sort()排序
print list1ip
print '你輸入的3個數從小到大排序爲:%s,%s,%s' %(list1[0],list1[1],list1[2])
2,績效utf-8
profit = input('Please input profix:')ci
if profit >=100:input
reward = 10 0.075 + 20 0.03 + 60 0.001
elif profit >=60:it
reward = 10 0.075 + 20 0.03 + (profit - 60) 0.1 + 10 0.05 + (profit - 40) 0.1 + 10 0.05
elif profit >=10:
reward = 10 0.075
else:
reward = profit * 0.1
print '你的獎金爲%s' %(reward)
補充:
profit = input('Please input profix:')
with open('config','r') as f:
L1 = float((f.readline().strip())) L2 = float((f.readline().strip())) L3 = float((f.readline().strip())) L4 = float((f.readline().strip())) L5 = float((f.readline().strip())) if profit >=100: reward = 10 L2 + 20 L3 + 60 L5 elif profit >=60: reward = 10 L2 + 20 L4 + (profit - 60) * L5 elif profit >=40: reward = 10 L2 + 20 L4 elif profit >=20: reward = 10 L2 + (profit - 20) * L3 elif profit >=10: reward = 10 L2 else: reward = profit * L1
print '你的獎金爲%s' %(reward)
config:
0.1
0.075
0.05
0.03
0.015
0.001
2017-12-25 13:04 2 條評論 評分
回覆 西紅柿雞蛋麪 • 2017-12-26 10:00
第二題
思考:若是獎金的百分比,會常常變更,你的這段代碼該怎麼寫維護起來更方便?
回覆 jxcia • 2017-12-26 16:37
profit = input('Please input profix:')
with open('config','r') as f:
L1 = float((f.readline().strip()))
L2 = float((f.readline().strip()))
L3 = float((f.readline().strip()))
L4 = float((f.readline().strip()))
L5 = float((f.readline().strip()))
if profit >=100:
reward = 10 L1 + 10 L2 + 20 L3 + 40 L3 + 60 L4 + (profit - 100) L5
elif profit >=60:
reward = 10 L1 + 10 L2 + 20 L3 + 40 L4 + (profit - 60) * L5
elif profit >=40:
reward = 10 L1 + 10 L2 + 20 L3 + (profit - 40) L4
elif profit >=20:
reward = 10 L1 + 10 L2 + (profit - 20) * L3
elif profit >=10:
reward = 10 L1 + (profit - 10) L2
else:
reward = profit * L1
print '你的獎金爲%s' %(reward)
評論一下...
0agh353272297
一、輸入三個整數x,y,z,請把這三個數由小到大輸出。
#!/usr/bin/env python
x = input("請輸入數值x:")
y = input("請輸入數值y:")
z = input("請輸入數值z:")
tmp = 0
if x > y:
tmp = x x = y y = tmp
if x > z:
tmp = x x = z z = tmp
print("x = %d, y = %d, z = %d" % (x, y, z))
二、企業發放的獎金根據利潤提成。
#!/usr/bin/env python
i = input("請輸入當月利潤:")
if i >= 100000 and i <= 2000000:
if i >= 100000: j = i * 0.1 else: j = i * 0.75
elif i >= 2000000 and i <= 400000:
j = i * 0.5
elif i >= 400000 and i <= 600000:
j = i * 0.3
elif i > 600000 and i <= 1000000:
j = i * 1.5
elif i > 1000000:
j = i * 1
print("i = %d, j = %d" % (i, j))
2017-12-25 17:35 1 條評論 評分
回覆 西紅柿雞蛋麪 • 2017-12-25 20:44
第一題的,y和z沒有作比較呀
第二題的每一個階段的提成數是不同的
評論一下...
0靈度淚 - 賣痛風藥的
#1.##############################
d = 0
x = int(input("第一個數字:"))
y = int(input("第二個數字:"))
z = int(input("第三個數字:"))
if x > y: # 作xy的比較;若是x>y,則x和y換值
x,y = y,x
if x > z: # 作xz的比較;若是x>z,則x和z換值
x,z = z,x
if y > z: # 作yz的比較;若是y>z,則y和z換值
y,z = z,y
print (x, y, z)
#2.#########################
s = float(input("請輸入利潤:"))
n = 0
if s <= 100000:
print (s*0.1)
if 100000 < s <= 200000:
n = s - 100000 print ("獎金總數是:",10000 + (n * 0.075))
if 200000 < s <= 400000:
n = s - 200000 print ("獎金總數是:",17500 + (n * 0.05))
if 400000 < s <= 600000:
n = s - 400000 print("獎金總數是:",27500 + (n * 0.03))
if 600000 < s <= 1000000:
n = s - 600000 print ("獎金總數是:",33500 + (n * 0.015))
if s > 1000000:
n = s - 1000000 print ("獎金總數是:",39500 + (n * 0.01))
2017-12-25 19:59 1 條評論 評分
回覆 西紅柿雞蛋麪 • 2017-12-26 09:49
第一題
思考:交換兩個變量的值,寫了3行代碼,有沒有更簡潔的方式?
第二題
思考:若是獎金的百分比,會常常變更,你的這段代碼該怎麼寫維護起來更方便?
評論一下...
0LINUX_A - 不要在最能吃苦的年齡選擇安逸!
x = int(raw_input("pls input a number: "))
y = int(raw_input("pls input a number: "))
z = int(raw_input("pls input a number: "))
aa = [x,y,z]
list(aa)
aa.sort()
print aa 第一種
aa = [x,y,z]
list(aa)
for i in range(len(aa)):
for j in range(i+1): if aa < aa[j]: # 實現連個變量的互換 aa,aa[j] = aa[j],aa
print aa 第二種
aa = [x,y,z]
list(aa)
if x > y:
temp = x x = y y = temp if y > z: temp = y y = z z = temp if x > y: temp = x x = y y = temp
elif y > z:
temp = z z = y y = temp if x > y: temp = x x = y y = temp
print x,y,z 第三種
i = int(raw_input("pls input the profit: "))
if i <= 100000:
print "the bonus is: %s" % (i * 0.1)
elif i >= 10000 and i<= 200000:
print "the bonus is: %s" % (100000 * 0.1 + (i - 100000) * 0.075)
elif i >= 200000 and i<= 400000:
print "the bonus is: %s" % (100000 * 0.1 + 100000 * 0.075 + (i - 200000) * 0.05)
elif i >= 400000 and i<= 600000:
print "the bonus is: %s" % (100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + (i - 400000) * 0.03)
elif i >= 600000 and i<= 1000000:
print "the bonus is: %s" % (100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.015 + (i - 600000) * 0.015)
else :
print "the bonus is: %s" % (100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.015 + 400000 *0.015 + (i - 1000000) * 0.01)
2017-12-25 23:32 1 條評論 評分
回覆 西紅柿雞蛋麪 • 2017-12-26 09:50
第一題寫了這麼多方式,很是棒
思考:交換兩個變量的值,寫了3行代碼,有沒有更簡潔的方式?
第二題
思考:若是獎金的百分比,會常常變更,你的這段代碼該怎麼寫維護起來更方便?
評論一下...
0ymk
i = int(input('淨利潤:'))arr = [1000000, 600000, 400000, 200000, 100000, 0]rat = [0.01, 0.015, 0.03, 0.05, 0.075, 0.1]r = 0for idx in range(0, 6):if i > arr[idx]:r += (i - arr[idx]) * rat[idx]i = arr[idx]print('應發獎金爲: %s元' % r)