python学习9——小练习

print("今天学习元曲:《天净沙·秋思》")
poem='''
\t天净沙·秋思\n\t马致远\n枯藤老树昏鸦\n小桥流水人家\n古道西风瘦马\n夕阳西下\n断肠人在天涯
'''
print("******\'")
print(poem)
print("******\'")

def apple(started):
 orange=started*20
 grape=(orange)*50/3
 mango=(grape) / 2
 return orange,grape,mango
start_point=600
orange,grape,mango = apple(start_point)
print("To begin with, Bill has %d apples." % start_point)
print("Bill sold his apples for %d grapes." %grape)
print("There were %d oranges in the farm." %orange)
print("Bill can get money by sell %d mangoes." %mango)

start_point=start_point*10
print("We can also do it this way:")
print("To begin with, Bill sold his apples for %d grapes. There were %d oranges in the farm, Bill can get money by sell %d mangoes." %apple(start_point))

输出结果:

想要将apple的值改为提示别人输入值,需要使用input(),在python3 中input()的值默认为字符串,会出现TypeError: unsupported operand type(s) for /: 'str' and 'int'的错误,所以需要借助int()

print("今天学习元曲:《天净沙·秋思》")
poem='''
\t天净沙·秋思\n\t马致远\n枯藤老树昏鸦\n小桥流水人家\n古道西风瘦马\n夕阳西下\n断肠人在天涯
'''
print("******\'")
print(poem)
print("******\'")

def apple(started):
 orange=started*20
 grape=(orange)*50/3
 mango=(grape) / 2
 return orange,grape,mango
start_point=int(input("How many applps in the farm?"))
orange,grape,mango = apple(start_point)
print("To begin with, Bill has %d apples." % start_point)
print("Bill sold his apples for %d grapes." %grape)
print("There were %d oranges in the farm." %orange)
print("Bill can get money by sell %d mangoes." %mango)

start_point=start_point*10
print("We can also do it this way:")
print("To begin with, Bill sold his apples for %d grapes. There were %d oranges in the farm, Bill can get money by sell %d mangoes." %apple(start_point))

 

posted on 2018-08-27 17:06  shannon_V  阅读(159)  评论(0编辑  收藏  举报

导航