tin 完全平方数 请问 mov utf pytho pro style
题目:有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是多少?
我的代码:python 3+
- #2017 - 7 - 20
- list_h = [1, 2, 3, 4] list_c = [] list_u = [] n = 0
- for x in list_h: list_c = list_h[: ] list_c.remove(x) for y in list_c: list_u = list_c[: ] list_u.remove(y) for z in list_u: n += 1 result = x * 100 + y * 10 + z print("第%d种:" % n, result)
推荐代码:python 2+
- # ! /usr/bin / python# - *-coding: UTF - 8 - *-
- 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
- 将
- for循环和
- if语句综合成一句,直接打印出结果# ! /usr/bin / env python# - *-coding: UTF - 8 - *-
- list_num = [1, 2, 3, 4]
- list = [i * 100 + j * 10 + k
- for i in list_num
- for j in list_num
- for k in list_num
- if (j != i and k != j and k != i)]
- print(list)
题目:企业发放的奖金根据利润提成。利润 (I) 低于或等于 10 万元时,奖金可提 10%;利润高于 10 万元,低于 20 万元时,低于 10 万元的部分按 10% 提成,高于 10 万元的部分,可提成 7.5%;20 万到 40 万之间时,高于 20 万元的部分,可提成 5%;40 万到 60 万之间时高于 40 万元的部分,可提成 3%;60 万到 100 万之间时,高于 60 万元的部分,可提成 1.5%,高于 100 万元时,超过 100 万元的部分按 1% 提成,从键盘输入当月利润 I,求应发放奖金总数?
- #2017 - 7 - 20# - *-coding: utf - 8 - *-
- profit = int(input("请输入利润值:")) list_profit = [1000000, 600000, 400000, 200000, 100000, 0] point = [0.01, 0.015, 0.03, 0.05, 0.075, 0.1] bonus = 0
- for x in range(len(point)) : if profit > list_profit[x] : bonus += (profit - list_profit[x]) * point[x] profit = list_profit[x]
- else: continue print(bonus)
题目:一个整数,它加上 100 后是一个完全平方数,再加上 168 又是一个完全平方数,请问该数是多少?
- #2017 - 07 - 20# - *-coding: utf - 8 - *-
- for x in range(2, 85, 2) : y = 168 / x
- if x > y and(x + y) % 2 == 0 and(x - y) % 2 == 0 : m = (x + y) / 2 n = (x - y) / 2 x = n * n - 100 print(x)
题目:输入某年某月某日,判断这一天是这一年的第几天?
- #2017 - 7 - 20# - *-coding: utf - 8 - *-
- year = int(input("请输入年份:")) month = int(input("请输入月份:")) day = int(input("请输入日:"))
- if year % 400 == 0 or(year % 100 != 0 and year % 4 == 0) : days = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30]
- else: days = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30] which_day = 0
- if month >= 1 and month <= 12 : for x in range(month) : which_day += days[x] which_day += day print("this day is the %dth day" % which_day)
- else: print('error month type')
python(练习实例)
来源: http://www.bubuko.com/infodetail-2218518.html