#!/usr/bin/env python
#coding: utf-8
"""
NAME : 判断闰年.py
Author: W
Date: 27/04/18
Connect: [email protected]
Desc:
"""
year = int(input("请输入年数:"))
if year % 400 == 0 or (year % 100 != 0 and year % 4 == 0):
print("%s是闰年" %year)
else:
print("%s不是闰年" %year)
请输入年数:2008
2008是闰年
#!/usr/bin/env python
#coding: utf-8
"""
NAME : 打印9*9乘法表.py
Author: W
Date: 27/04/18
Connect: [email protected]
Desc:
"""
for i in range(1, 10):
for j in range(1, 10):
result = i * j
print("%d * %d=%2d " % (i, j, result))
print("\t")
1 * 1= 1
1 * 2= 2
1 * 3= 3
1 * 4= 4
1 * 5= 5
1 * 6= 6
1 * 7= 7
1 * 8= 8
1 * 9= 9
2 * 1= 2
2 * 2= 4
2 * 3= 6
2 * 4= 8
2 * 5=10
2 * 6=12
2 * 7=14
2 * 8=16
2 * 9=18
3 * 1= 3
3 * 2= 6
3 * 3= 9
3 * 4=12
3 * 5=15
3 * 6=18
3 * 7=21
3 * 8=24
3 * 9=27
…….
9 * 1= 9
9 * 2=18
9 * 3=27
9 * 4=36
9 * 5=45
9 * 6=54
9 * 7=63
9 * 8=72
9 * 9=81
#!/usr/bin/env python
#coding: utf-8
"""
NAME : 输入一个1-100的数是否等于你设定的数.py
Author: W
Date: 27/04/18
Connect: [email protected]
Desc:
带循环和条件判断的给定一个数值num,
用户输入使用raw_input()函数来提示用户输入一个1和100之间的数,
如果用户输入的数等于num, 显示成功并退出。
否则显示一个错误信息然后再次提示用户输入数值,直到满足条件为止。
"""
num = 88
count = 0
while count < 3:
a = int(input("请输入1-100之间的数:"))
if a > num:
print("请输入1-100之间的数 !!!")
break
count += 1
if a == num:
print("匹配成功!!!")
break
else:
print("请再次输入!!")
continue
else:
print("你输入的次数超过3次了!!!!")
请输入1-100之间的数:88
匹配成功!!!
#!/usr/bin/env python
#coding: utf-8
"""
NAME : 输入2个数求最大公约数和最大公倍数.py
Author: W
Date: 27/04/18
Connect: M.@qq.com
Desc:
"""
# 1. 输入两个数值: input接收字符串;
num1 = int(input('Num1:'))
num2 = int(input('Num2:'))
# 2. 找出两数中最小的值;
min_num = min(num1, num2)
# 3. 最大公约数在1~min_num之间存在, 如果num1和num2能整除的最大的数为最大公约数;
for i in range(1, min_num + 1):
if num1 % i == 0 and num2 % i == 0: # i=1, i=2
# 当循环完,res中保存的是最大的约数;
res = i
# 最小公倍数=(num1*num2)/最大公约数;
lcm = int((num1 * num2) / res)
print("%s和%s的最大公约数为:%s" % (num1, num2, res))
print("%s和%s的最小公倍数为:%s" % (num1, num2, lcm))
Num1:12
Num2:6
12和6的最大公约数为:6
12和6的最小公倍数为:12
#!/usr/bin/env python
#coding: utf-8
"""
NAME : [1,2,3,4]数能组成多少个不重复的3位数.py
Author: W
Date: 27/04/18
Connect: [email protected]
Desc:
"""
count = 0
num_list = [1, 2, 3, 4]
for i in num_list:
for j in num_list:
for k in num_list:
if i != j and j != k and i != k:
count += 1
print(i, j, k)
print("总共有个%d无重复的3位数" % (count))
…….
4 3 3
4 3 4
4 4 1
4 4 2
4 4 3
4 4 4
总共有个24无重复的3位数
test2
#!/usr/bin/env python
#coding: utf-8
"""
NAME : 从第一个字符串中删除第二个字符串的中的字符.py
Author: W
Date: 27/04/18
Connect: [email protected]
Desc:
输入两个字符串,从第一字符串中删除第二个字符串中所有的字符。
例如,输入”They are students.”和”aeiou”,
则删除之后的第一个字符串变成”Thy r stdnts.”
"""
# l1 = list(input("请输入第一个字符串:"))
# l2 = list(input("请输入第二个字符串:"))
# for i in l2:
# for j in l1:
# if i == j:
# l1.remove(j)
# print(str(l1))
s = input("请输入第一传串字符:")
b = input("请输入第二传串字符:")
for i in b:
s = s.replace(i, "")
else:
print(s)
请输入第一传串字符:wqwq
请输入第二传串字符:w
qq
#!/usr/bin/env python
#coding: utf-8
"""
NAME : 企业发放的奖金利润提成.py
Author: W
Date: 27/04/18
Connect: [email protected]
Desc:
利润(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,求应发放奖金总数?
"""
I = int(input("输入利润I:"))
a = [1000000, 600000, 400000, 200000, 100000, 0]
b = [0.01, 0.015, 0.03, 0.05, 0.075, 0.1]
r = 0
for i in range(0, 6):
if I > a[i]:
r += (I - a[i]) * b[i] ##r1超出的部分利润,r2低于的部分
I = a[i]
print(r)
输入利润I:565756
32472.68
#!/usr/bin/env python
#coding: utf-8
"""
NAME : 句子反转.py
Author: W
Date: 27/04/18
Connect: [email protected]
Desc:
- 输入
hello xiao mi
- 输出
mi xiao hello
"""
print (" ".join(input("请输入句子:").split()[::-1]))
请输入句子:hello xiao mi
mi xiao hello
#!/usr/bin/env python
#coding: utf-8
"""
NAME : 加100和加168都是一个完全平方数.py
Author: W
Date: 27/04/18
Connect: [email protected]
Desc:
一个整数,它加上100后是一个完全平方数,
再加上168又是一个完全平方数,请问该数是多少?
先把x:(i+100),y:(i+168)对应的数开方,再给x,y平方等于对应的数,
再判断符合条件的i
"""
import math ##导入处理数的库
num = int(input("请输入你要找的范围的最大数:"))
for i in range(num):
# int把求的开方数转化为整形
x = int(math.sqrt(i + 100))
y = int(math.sqrt(i + 168))
if (x * x == i + 100) and (y * y == i + 168):
print(i)
请输入你要找的范围的最大数:5000
156
#!/usr/bin/env python
#coding: utf-8
"""
NAME : 大写字母且相邻的不能相同.py
Author: W
Date: 27/04/18
Connect: [email protected]
Desc:
小易喜欢的单词具有以下特性:
1.单词每个字母都是大写字母
2.单词没有连续相等的字母
示例1 :
输入
AAA
输出
Dislikes
"""
str = input("请输入:")
if not str.isupper():
print("请输入大写字母!!")
elif str.isalpha() and len(str) <= 100:
for i in range(len(str)):
if str[i] == str[i - 1]:
print("DISLIKE")
break
else:
print("LIKE")
else:
print("输入字母或者字符长度超过100!!")
请输入:ASSD
DISLIKE