文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>【python练习-原创】2010.11.25

【python练习-原创】2010.11.25

时间:2010-11-25  来源:simonchia

1.定义一个乘积函数能根据你输入的数字显示出两个数字相乘的积
#!/usr/bin/env python
def chengji(x,y):
 return x*y

a = int(raw_input("Enter a:"))
b = int(raw_input("Enter b:"))
print chengji(a,b)
2.输入三个数字得出它们的排序(从小到大)
#!/usr/bin/env python
a = int(raw_input("Enter the first number:"))
b = int(raw_input("Enter the second number:"))
c = int(raw_input("Enter the third number:"))
if a < b < c:
 print a,b,c
elif a < c < b:
 print a,c,b
elif b < a < c:
 print b,a,c
elif b < c < a:
 print b,c,a
elif c < a < b:
 print c,a,b
elif c < b < a:
 print c,b,a
else:
 print "a=b=c"
3.根据输入的成绩判断级别
#!/usr/bin/env python
a = int(raw_input("Enter the chengji:"))
if 89 < a < 101:
 print "A"
elif 79 < a <90:
 print "B"
elif 69 < a < 80:
 print "C"
elif 59 < a < 70:
 print "D"
elif 0 <= a < 60:
 print "F"
else:
 print "this is wrong number~~!!!"
4.判断一个年份是否是闰年
#!/usr/bin/env python
year = int(raw_input("Enter a year:"))
if year%4==0:
 print "runnian~!"
elif year%400==0:
 print "runnian~!"
else:
 print "bu shi runnian~!"
5.输入一个100美分以内的金额,计算可以换成最少多少硬币(1美分/5美分/10美分/25美分四种硬币)
#!/usr/bin/env python
pay = int(raw_input("Enter value(range 0-100):"))
a = pay/25
b = (pay%25)/10
c = ((pay%25)%10)/5
d = (((pay%25)%10)%5)/1
print a,"ge 25"
print b,"ge 10"
print c,"ge 5"
print d,"ge 1"

相关阅读 更多 +
排行榜 更多 +
找茬脑洞的世界安卓版

找茬脑洞的世界安卓版

休闲益智 下载
滑板英雄跑酷2手游

滑板英雄跑酷2手游

休闲益智 下载
披萨对对看下载

披萨对对看下载

休闲益智 下载