__MagicPower
Do one thing and do it best!

导航

 

Question 001:

#!/usr/bin/env python
#--*-- coding:utf-8 --*--
"""
1,2,3,4数字,能组成多少个互不相同且无重复数字的三位数字?都是多少?
"""

for i in range(1,5):
	for j in range(1,5):
		for k in range(1,5):
			if (i != k) and (i != j) and (j != k):
				print i,j,k

Question 002:

#!/usr/bin/env python
#--*-- coding:utf-8 --*--
"""
企业发放的奖金根据利润提成。
利润(I)低于或者等于10万元时,奖金可提10%;
利润高于10万元,低于20万元时,低于10万元部分按10%提成,高于10万元部分,可以提成7.5%
高于20万元部分,可以提成5%
40万到60万之间时,高于40万的部分可以提成3%
60万到100万之间时,高于60万元的部分,可提成1.5%,高于100万元时候,超过100万元的部分按1%
提成,从键盘输入当月利润I,求应发放奖金总数?
"""
bonus1 = 100000*0.1
bonus2 = bonus1 + 100000*0.075
bonus4 = bonus2 + 200000*0.05
bonus6 = bonus4 + 200000*0.03
bonus10 = bonus6 + 400000* 0.015
profit = int(raw_input('Input the profit:'))

if profit <= 100000:
	bonus = profit * 0.1
elif profit < 200000:
	bonus = bonus1 + (i - 100000)*0.075
elif profit <= 400000:
	bonus = bonus2 + (i - 200000)*0.05
elif profit <= 600000:
	bonus = bonus4 + (i - 400000)*0.03
elif profit <= 1000000:
	bonus = bonus6 + (i - 600000)*0.015
else:
	bonus = bonus10 + (i - 1000000)*0.01

print 'bonus = ',bonus 

Question003:

#!/usr/bin/env python
#--*-- coding:utf-8 --*--
"""
一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
"""
import math
for i in range(10000):
	x = int(math.sqrt(i+100))
	y = int(math.sqrt(i+268))
	if (x * x == i + 100) and (y * y == i + 268):
		print i
		

  

Question004:

#!/usr/bin/env python
#--*-- coding:utf-8 --*--
"""
输入某年某月某日,判断这一天是这一年的第几天
"""
def judge():
	year = int(raw_input('year:'))
	month = int(raw_input('month:'))
	day = int(raw_input('day:'))
	sum = 0
	months = (0,31,59,90,120,151,181,212,243,273,304,334)

	if 0 <= month <=12:
		sum = months[month - 1]
	else:
		print 'date error'
	sum += day
	leap = 0

	if (year % 400 == 0) or ((year % 4 == 0) and (year % 100 != 0)):
		leap = 1

	if (leap == 1) and (month > 2):
		sum += 1
	print 'It is the %dth day.'% sum

if __name__ == '__main__':
	judge()

Question005:

#!/usr/bin/env python
#--*-- coding:utf-8 --*--
"""
输入三个整数x,y,z 请把这三个数由大到小输出
"""

def judge():
	x = int(raw_input('x:'))
	y = int(raw_input('y:'))
	z = int(raw_input('z:'))

	list = [x,y,z]
	list.sort(reverse = True)
	print list

if __name__ == '__main__':
	judge()

Question006:

#!/usr/bin/env python
#--*-- coding:utf-8 --*--
"""
用*号输出字母C的图案
"""
def paint():
	print '*'*10
	for i in range(5):
		print '*      '
	print '*'*10	

if __name__ == '__main__':
	paint()

Question007:

#!/usr/bin/env python
#--*-- coding:utf-8 --*--
"""
输出特殊图案
字符一共256个
"""
def outputspecial():
	for i in range(256):
		print chr(i)

if __name__ == '__main__':
	outputspecial()

Question008:

#!/usr/bin/env python
#--*-- coding:utf-8 --*--
"""
输出9*9口诀
"""

def ninetable():
	list_1 = [1,2,3,4,5,6,7,8,9]
	for i in list_1:
		for j in list_1:
			print '%d * %d = %d'%(i,j,i*j)

if __name__ == '__main__':
	ninetable()

Question009:

#!/usr/bin/env python
#--*-- coding:utf-8 --*--
"""
请输出国际象棋棋盘
"""

import sys
for i in range(8):
	for j in range(8):
		if (i + j)%2 == 0:
			sys.stdout.write(chr(254))
			sys.stdout.write(chr(254))
		else:
			sys.stdout.write(' ')
	print ''

上面这段代码我在OS X上运行之后发现原本应该显示成方块的变成了问号 暂时还没有解决,似乎其他ASCii显示也有问题 

 Question010:

#!/usr/bin/env python
#--*-- coding:utf-8 --*--
"""
打印楼梯,同时在楼梯上方打印两个笑脸
"""
import sys
import locale
sys.stdout.write(chr(1))
sys.stdout.write(chr(1))
print ''

for i in range(1,11):
	for j in range(1,i):
		sys.stdout.write(chr(219))
		sys.stdout.write(chr(219))
	print ''

Question011:

#!/usr/bin/env python
#--*-- coding:utf-8 --*--
"""
古典问题:有一对兔子,从出生后的第三个月起每个月都生一对兔子,小兔子长到第三个月后
		每个月又生一对兔子,假如兔子不死,问每个月的兔子总数是多少?
"""
f1 = 1
f2 = 1
for i in range(1,21):
	print '%12d %12d'%(f1,f2)
	if (i % 2) == 0:
		print ''
	f1 = f1 + f2
	f2 = f1 + f2

Question012:

#!/usr/bin/env python
#--*-- coding:utf-8 --*--
"""
判断101-200之间多少个素数,并输出所有素数
"""
import math

def isPrime(n):
	if n <= 1:
		return False
	for i in range(2,int(math.sqrt(n)) + 1):
		if n % i == 0:
			return False
		return True

if __name__ == '__main__':
	for j in range(101,201):
		if isPrime(j):
			print '%d is Prime'%j

Question014:

#!/usr/bin/env python
#--*-- coding:utf-8 --*--
"""
将一个正整数分解质因数,例如:输入90,打印出90=2*3*3*5
"""

from sys import stdout

n = int(raw_input("input number:\n"))
print "n = %d"%n

for i in range(2,n+1):
	while n != i:
		if n%i == 0:
			stdout.write(str(i))
			stdout.write("*")
			n = n / i 
		else:
			break
print "%d"%n

Question015:

#!/usr/bin/env python
#--*-- coding:utf-8 --*--
"""
rank:
grade >= 90 A
60 ~ 89     B
<60         C
"""
def rank(number):
	if number >= 90:
		print "Your rank is A"
	elif number < 60:
		print "Your rank is C"
	elif number <=89 and number >= 60:
		print "Your rank is B"

if __name__ == '__main__':
	while True:
		n = int(raw_input('Input grade:'))
		rank(n)

  

 

  

posted on 2015-12-26 14:01  __MagicPower  阅读(300)  评论(0编辑  收藏  举报