最近在Coursera上课。 台湾的课程:用Python做商管程式设计(一)(Programming for Business Computing in Python (1))。想说最近写程序很夯,挑战看看
没有专门下载Python,只是在colab.research.google.com/直接写了(用大姐的电脑)
目前才上到week 3的课程。 虽然课堂上老师讲的东西,看似简单,容易明白。等到自己要亲自动手写,从无到有,要做功课和作业时,才头痛。
想在这里记录一下 Week 3 做的作业。题目在这里就不多提了。主要就是想说--可能其实有更简单的方法写,只是身为一个程序小白,刚刚学会 assignment =, comparison ==, if, else, else if, nested if else...
我只会用最直白的方式写出来。这题的output有63种组合,我就傻傻的一个一个的写...... 写了200多行。(不重要的题外话:问题要的是“,”, 我写了“:”)虽然答题还是可以的,但假如是在真的考场有时间上的压力的话,做了这题就别想做其他题目了,已经耗尽了全部能量和精力。
spend = int(input())
give = 1000
totalchange = give - spend
c500 = int()
c100 = int()
c50 = int()
c10 = int()
c5 = int()
c1 = int()
c500 = (totalchange)//500
c100 = (totalchange%500)//100
c50 = ((totalchange)%100)//50
c10 = (totalchange%100%50)//10
c5 = (totalchange%10)//5
c1 = (totalchange%10%5)//1
print("total change: ", totalchange)
if (c500 == 0):
if (c100 == 0):
if (c50 == 0):
if (c10 == 0):
if (c5 == 0):
if (c1 != 0):
print ("1: " + str (c1)) #1-4
else:
if (c1 != 0):
print ("5: " + str(c5) + "; 1: " + str(c1)) #6-9
else:
print ("5: " + str(c5)) #5
else:
if (c5 == 0):
if (c1 == 0):
print ("10: " + str(c10)) # 10, 20, 30, 40
else:
print ("10: " + str(c10) + "; 1: " + str(c1)) #11-14, 21-24,31-34, 41-44
else:
if (c1 == 0):
print ("10: " + str(c10) + "; 5: " + str(c5)) #15, 25, 35, 45
else:
print ("10: " + str(c10) + "; 5: " + str(c5) + "; 1: " + str(c1)) #16-19, 26-29, 36-39, 46-49
else:
if (c10 == 0):
if (c5 == 0):
if (c1 == 0):
print ("50: " + str(c50)) # 50
else:
print ("50: " + str(c50) + "; 1: " + str(c1)) # 51-54
else:
if (c1 == 0):
print ("50: " + str(c50) + "; 5: " + str(c5))# 55
else:
print ("50: " + str(c50) + "; 5: " + str(c5) + "; 1: " + str(c1)) #56-59
else:
if (c5 == 0):
if (c1 == 0):
print ("50: " + str(c50) + "; 10: " + str(c10))
else :
print ("50: " + str(c50) + "; 10: " + str(c10) + "; 1: " + str(c1))
else:
if (c1 == 0):
print ("50: " + str(c50) + "; 10: " + str(c10) + "; 5: " + str (c5))
else:
print ("50: " + str(c50) + "; 10: " + str(c10) + "; 5: " + str (c5) + "; 1: " + str(c1))
else:
if (c50 == 0):
if (c10 == 0):
if (c5 == 0):
if (c1 == 0):
print ("100: " + str (c100))
else :
print ("100: " + str (c100) + "; 1: " + str (c1))
else :
if (c1 == 0):
print ("100: " +str (c100) + "; 5: " + str (c5))
else :
print ("100: " +str (c100) + "; 5: " + str (c5) + "; 1:" + str (c1))
else:
if (c5 == 0):
if (c1 == 0):
print ("100: " + str (c100) + "; 10: " + str (c10))
else:
print ("100: " + str (c100) + "; 10: " + str (c10) + "; 1: " + str (c1))
else:
if (c1 == 0):
print ("100: " + str (c100) + "; 10: " + str (c10) + "; 5: " + str (c5))
else:
print ("100: " + str (c100) + "; 10: " + str (c10) + "; 5: " + str (c5) + "; 1: " + str (c1))
else:
if (c10 == 0):
if (c5 == 0):
if (c1 == 0):
print ("100: " +str (c100) + "; 50: " + str (c50))
else:
print ("100: " +str (c100) + "; 50: " + str (c50) + "; 1: " + str (c1))
else:
if (c1 == 0):
print ("100: " +str (c100) + "; 50: " + str (c50) + "; 5: " + str (c5))
else:
print ("100: " +str (c100) + "; 50: " + str (c50) + "; 5: " + str (c5) + "; 1: " + str (c1))
else:
if (c5 == 0):
if (c1 == 0):
print ("100: " +str (c100) + "; 50: " + str (c50) + "; 10: " + str (c10))
else:
print ("100: " +str (c100) + "; 50: " + str (c50) + "; 10: " + str (c10) + "; 1: " + str (c1))
else:
if (c1 == 0):
print ("100: " +str (c100) + "; 50: " + str (c50) + "; 10: " + str (c10) + "; 5: " + str (c5))
else:
print ("100: " +str (c100) + "; 50: " + str (c50) + "; 10: " + str (c10) + "; 5: " + str (c5) + "; 1: " + str (c1))
else:
if (c100 == 0):
if (c50 == 0):
if (c10 == 0):
if (c5 == 0):
if (c1 == 0):
print ("500: " + str (c500))
else :
print ("500: " + str (c500) + "; 1: " + str (c1))
else:
if (c1 == 0):
print ("500: " + str (c500) + "; 5: " + str (c5))
else:
print ("500: " + str (c500) + "; 5: " + str (c5) + "; 1: " + str (c1))
else:
if (c5 == 0):
if (c1 == 0):
print ("500: " + str (c500) + "; 10: " + str (c10))
else :
print ("500: " + str (c500) + "; 10: " + str (c10) + "; 1: " + str (c1))
else:
if (c1 == 0):
print ("500: " + str (c500) + "; 10: " + str (c10) + "; 5: " + str (c5))
else:
print ("500: " + str (c500) + "; 10: " + str (c10) + "; 5: " + str (c5) + "; 1: " + str (c1))
else: #got 500, got 50
if (c10 == 0):
if (c5 == 0):
if (c1 == 0):
print ("500: " + str (c500) + "; 50: " + str (c50))
else:
print ("500: " + str (c500) + "; 50: " + str (c50) + "; 1: " + str (c1))
else:
if (c1 == 0):
print ("500: " + str (c500) + "; 50: " + str (c50) + "; 5: " + str (c5))
else:
print ("500: " + str (c500) + "; 50: " + str (c50) + "; 5: " + str (c5) + "; 1: " + str (c1))
else: # got 500, got 50, got 10
if (c5 == 0):
if (c1 == 0):
print ("500: " + str (c500) + "; 50: " + str (c50) + "; 10: " + str (c10))
else:
print ("500: " + str (c500) + "; 50: " + str (c50) + "; 10: " + str (c10) + "; 1: " + str (c1))
else: #got 500, got 50, got 10, got 5
if (c1 == 0):
print ("500: " + str (c500) + "; 50: " + str (c50) + "; 10: " + str (c10) + "; 5: " + str (c5))
else:
print ("500: " + str (c500) + "; 50: " + str (c50) + "; 10: " + str (c10) + "; 5: " + str (c5) + "; 1: " + str (c1))
else: # got 500, got 100
if (c50 == 0):
if (c10 == 0):
if (c5 == 0):
if (c1 == 0):
print ("500: " + str (c500) + "; 100: " + str (c100))
else:
print ("500: " + str (c500) + "; 100: " + str (c100) + "; 1: " + str (c1) )
else:
if (c1 == 0):
print ("500: " + str (c500) + "; 100: " + str (c100) + "; 5: " + str (c5))
else:
print ("500: " + str (c500) + "; 100: " + str (c100) + "; 5: " + str (c5) + "; 1: " + str (c1))
else: # got 500, got 100, got 10
if (c5 == 0):
if (c1 == 0):
print ("500: " + str (c500) + "; 100: " + str (c100) + "; 10: " + str (c10))
else:
print ("500: " + str (c500) + "; 100: " + str (c100) + "; 10: " + str (c10) + "; 1: " + str (c1))
else:
if (c1 == 0):
print ("500: " + str (c500) + "; 100: " + str (c100) + "; 10: " + str (c10) + "; 5: " + str (c5))
else:
print ("500: " + str (c500) + "; 100: " + str (c100) + "; 10: " + str (c10) + "; 5: " + str (c5) + "; 1: " + str (c1))
else: # got 500, got 100, got 50
if (c10 == 0):
if (c5 == 0):
if (c1 == 0):
print ("500: " + str (c500) + "; 100: " + str (c100) + "; 50: " + str (c50))
else:
print ("500: " + str (c500) + "; 100: " + str (c100) + "; 50: " + str (c50) + "; 1: " + str (c1))
else:
if (c1 == 0):
print ("500: " + str (c500) + "; 100: " + str (c100) + "; 50: " + str (c50) + "; 5: " + str (c5))
else:
print ("500: " + str (c500) + "; 100: " + str (c100) + "; 50: " + str (c50) + "; 5: " + str (c5) + "; 1: " + str (c1))
else: # got 500, got 100, got 50, got 10
if (c5 == 0):
if (c1 == 0):
print ("500: " + str (c500) + "; 100: " + str (c100) + "; 50: " + str (c50) + "; 10: " + str (c10))
else:
print ("500: " + str (c500) + "; 100: " + str (c100) + "; 50: " + str (c50) + "; 10: " + str (c10) + "; 1: " + str (c1))
else:
if (c1 == 0):
print ("500: " + str (c500) + "; 100: " + str (c100) + "; 50: " + str (c50) + "; 10: " + str (c10) + "; 5: " + str (c5))
else:
print ("500: " + str (c500) + "; 100: " + str (c100) + "; 50: " + str (c50) + "; 10: " + str (c10) + "; 5: " + str (c5) + "; 1: " + str (c1))
No comments:
Post a Comment