python习题记录

  • 22秋季Python第1周作业
    • 1.Hello World
    • 2.人生苦短,我学python
    • 3.应声虫
    • 4.Py的A+B
    • 5.摄氏温度转换华氏温度
    • 6.从键盘输入三个数到a,b,c中,按公式值输出
    • 7.求三角形面积
    • 8.输出乘法式子
      • Python3一行输入多个&输入多行数据
    • 9.输出漏斗图形
    • 10.显示两句话
    • 11.输出日期
    • 12.计算两个整数的差
    • 13.菲姐游泳 - 实验3 简单的计算及输入输出 -《Python编程基础及应用实验教程》(高等教育出版社)
    • 14.求出5的三次方的值是多少?
  • 22秋季Python第2周作业
    • 1 输出乘法式子
    • 2 输出字符矩形
    • 3 鸡兔同笼(高教社,《Python编程基础及应用》习题3-7)
    • 4 身体质量指数(高教社,《Python编程基础及应用》习题6-3)
    • 5 输入姓名,问好,字符切片
    • 6 半圆弧的长度
    • 7 通过python实现,输入1个字符串,输出5个一样的字符串。
    • 8 单词首字母大写
  • try-except异常处理 :
    • 9 字符统计
    • 10 字符空格去除
    • 11 计算球体积
    • 12 对角线 - 实验3 简单的计算及输入输出 -《Python编程基础及应用实验教程》(高等教育出版社)
    • 13 游客检票 - 实验3 简单的计算及输入输出 -《Python编程基础及应用实验教程》(高等教育出版社)
    • 14 橡皮泥 - 实验3 简单的计算及输入输出 -《Python编程基础及应用实验教程》(高等教育出版社)
    • 15 单个身份证的校验 - 实验19 身份证校验 - 《Python编程基础及应用实验教程》 - 高教社
  • 22秋季Python第3周作业
    • 01 2018我们要赢
    • 02 重要的话说三遍
    • 03 交换a和b的值
    • 04 求圆面积
    • 05 实数x的n倍
    • 06 把字符串中的大写字母改成小写字母
    • 07 字符串的连接
    • 08 查找指定字符
      • 【Python】字符串几个常用查找方法
    • 09 输出大写英文字母
    • 10 字符转换
    • 11 算术入门之加减乘除
    • 12 统计大写辅音字母
    • 13 字符串替换
    • 14 字符串转换成十进制整数
    • 15 然后是几点
  • 22秋季Python第4周作业
    • 1 回文数
    • 2 判断是否构成三角形
    • 3 整数平方根
    • 4 分支嵌套
    • 5 不合格的小球
    • 6 简单的猜数字游戏[1]
    • 7 求某月的天数
    • 8 统计各类字符数量并输出字母
    • 9 计算邮资
    • 10 币值转换
    • 11 分段函数3
    • 12 从5个整数中找出最小的数。
    • 13 考试分数对应等级
    • 14 日历

22秋季Python第1周作业

题目

1.Hello World

print("Hello World")

2.人生苦短,我学python

#方法一
name = input()
if len(name)==2:print("{}同学,人生苦短,我学python".format(name))print("{}大侠,学好python,走遍天下也不怕".format(name[0]))print("{}小盆友,学好python,你最帅".format(name[1]))
elif len(name)==3:print("{}同学,人生苦短,我学python".format(name))print("{}大侠,学好python,走遍天下也不怕".format(name[0]))print("{}小盆友,学好python,你最帅".format(name[1:3]))#方法二
name = input()
print("{}同学,人生苦短,我学python".format(name))
print("{}大侠,学好python,走遍天下也不怕".format(name[0]))
print("{}小盆友,学好python,你最帅".format(name[1: ]))

[1:]表示选择了name[1~n-1]的数据

3.应声虫

a=input()
print(a)

4.Py的A+B

a=input()
a=int(a)
b=input()
b=int(b)
print(a+b)

5.摄氏温度转换华氏温度

c=input()
c=float(c)
print(c*1.8+32)

6.从键盘输入三个数到a,b,c中,按公式值输出

# a,b,c=map(int,input().split())
# print(b * b - 4 * a * c)line=input()
a,b,c=line.split()
a=int(a)
b=int(b)
c=int(c)
print(b * b - 4 * a * c)

7.求三角形面积

a,b,c=map(int,input().split())
p=(a+b+c)/2
p=float(p)
s=(p*(p-a)*(p-c)*(p-b))**0.5
s=float(s)
print("{:.3f}".format(s))

8.输出乘法式子

a,b=map(int,input().split())
print("%s*%s=%d"%(a,b,a*b))

Python3一行输入多个&输入多行数据

一、input().split()用法
input() 一行输入多个需要与split()结合使用

#注意:split()参数为空,默认一行输入多个时用空格隔开
username, passwd = input("请输入用户名,密码:").split()
#注意:input()的返回类型是str,如果是整数需要转化为int才可正常使用
print(username,passwd)

输入样例:
lilian 123456

二、str.split()用法

#str.split(str="", num=string.count(str))
#str是分隔符(默认为所有的空字符,包括空格、换行(\n)、制表符(\t)等),num是分隔次数
txt1 = "Google#Facebook#Runoob#Taobao"
x1 = txt1.split("#", 1)
print(x1)
txt2 = "Google#Facebook#Runoob#Taobao"
x2 = txt2.split("#", 2)
print(x2)

输出结果:
[‘Google’, ‘Facebook#Runoob#Taobao’]
[‘Google’, ‘Facebook’, ‘Runoob#Taobao’]

三、map()用法
map(function, iterable, …)

function – 函数
iterable – 一个或多个序列

返回值:
Python 2.x 返回列表。
Python 3.x 返回迭代器。
所以Python 3.x要加list()函数将迭代器转化为列表。

def f(x):return x*x
print(list(map(f, [1, 2, 3, 4, 5, 6, 7, 8, 9])))

输出结果:
[1, 4, 9, 16, 25, 36, 49, 64, 81]

#用匿名函数
print(list(map(lambda x: x ** 2, [1, 2, 3, 4, 5])))

输出结果:
[1, 4, 9, 16, 25]

9.输出漏斗图形

print("*********")
print(" *******")
print("  *****")
print("   ***")
print("    *")
print("   ***")
print("  *****")
print(" *******")
print("*********")

10.显示两句话

#1
s="Everything depends on human effort.\nJust do it."
print(s)#2
print("Everything depends on human effort.")
print("Just do it.")#3
print("""Everything depends on human effort.
Just do it.""")

11.输出日期

year=input()
mouth=input()
day=input()
print("%s-%s-%s"%(year,mouth,day))

12.计算两个整数的差

a,b=map(int,input().split())
print("s=%d"%(a-b))

13.菲姐游泳 - 实验3 简单的计算及输入输出 -《Python编程基础及应用实验教程》(高等教育出版社)

#方法一
h1,m1,h2,m2=map(int,input().split())
if(m1>m2):h2=h2-1m=m2-m1+60h=h2-h1
else:m=m2-m1h=h2-h1
print("%s:%s"%(h,m))#方法二
array = list(input().split())
if (array[1]>array[3]):array[2]=int(array[2])-1m  = int(array[3]) - int(array[1]) + 60h = int(array[2]) - int(array[0])
else:m = int(array[3]) - int(array[1])h = int(array[2]) - int(array[0])
print("%s:%s"%(h,m),end="")

14.求出5的三次方的值是多少?

a=input()
a=int(a)
print(a*a*a)

22秋季Python第2周作业

题目

1 输出乘法式子

a,b=map(int,input().split())
print("%d*%d=%d"%(a,b,a*b))

2 输出字符矩形

print("@@@@@@@@@@@@@@@@@@@@")
print("@@@@@@@@@@@@@@@@@@@@")
print("@@@@@@@@@@@@@@@@@@@@")
print("@@@@@@@@@@@@@@@@@@@@")

3 鸡兔同笼(高教社,《Python编程基础及应用》习题3-7)

# 输入变量解决问题
f = eval(input())
h = eval(input())
chicken = f / 2 - h
rabbit = 2 * h - f / 2
print("{}".format(int(rabbit)))
print("{}".format(int(chicken)))# 使用循环解决鸡兔同笼问题
f = eval(input())
h = eval(input())
chicken = 0
while True:rabbit = h - chicken  # 头的总数if 2 * chicken + 4 * rabbit == f:  # 脚的总数#         print('鸡有 {} 只, 兔有 {} 只'.format(chicken, rabbit))print("{}".format(int(chicken)))print("{}".format(int(rabbit)))breakchicken += 1

4 身体质量指数(高教社,《Python编程基础及应用》习题6-3)

weight,high=map(float,input().split(","))
# print("{}".format(weight))
# print("{}".format(high))
result = weight / (high * high)
if result < 18:print("超轻")
elif result < 25:print("标准")
elif result < 27:print("超重")
else:print("肥胖")

5 输入姓名,问好,字符切片

name = input()
print("你好,{}同学。".format(name))
print("{}同学,很高兴认识你。".format(name[0]))
print("{}同学,我们交个朋友吧!".format(name[1: ]))

6 半圆弧的长度

注意python里面import math用法

import math
a=input()
a=float(a)
L=a*math.pi
# L=float(L)
# round(L,2)
print("L={:.2f}".format(L))

7 通过python实现,输入1个字符串,输出5个一样的字符串。

# 法1
s = input()
print(s, end="")
print(s, end="")
print(s, end="")
print(s, end="")
print(s, end="")
# python 3.x版本输出不换行格式为:print(x, end="") 。end="" 可使输出不换行。# 法2
s = input()
print(s * 5, end="")

8 单词首字母大写

建议使用方法2
方法一:

try-except异常处理 :

详情可看这篇文章 python异常处理try-except语句

方法二:
for line in sys.stdin读文件,按行处理

# 方法1
while True:try:s = input()arr = s.split()for i in range(0, len(arr)):arr[i] = arr[i].capitalize()s1 = " ".join(arr)print(s1)except:break# 方法2
import sysfor line in sys.stdin:line = line.strip()  # 删除尾部的换行符print(line.title())
#     title函数:python中字符串函数,返回’标题化‘的字符串,就是单词的开头为大写,其余为小写。

9 字符统计

s=input()
ans=0
for i in s: if i == 'p' or i == 'P':ans+=1
print(ans)

10 字符空格去除

s = input()# replace(m,n)方法:将字符串里面的m替换为n。
print(s.replace(' ', ''))# split(s,num)方法:split(s,num)
print(''.join(s.split()))

11 计算球体积

import math
r=input()
r=float(r)
v=4/3*math.pi*r*r*r
print("v={:.3f}".format(v))

12 对角线 - 实验3 简单的计算及输入输出 -《Python编程基础及应用实验教程》(高等教育出版社)

import math
a=input()
a=float(a)
b=input()
b=float(b)
c=math.sqrt(a*a+b*b)
print("对角度长度为:{:.1f}cm.".format(c))

13 游客检票 - 实验3 简单的计算及输入输出 -《Python编程基础及应用实验教程》(高等教育出版社)


输入样例:

180
300

输出样例:

原有排队游客份数:900.0, 每分钟新到游客份数:3.0, 10口同开需128.6分钟清零待检票游客.
m=int(input())
n=int(input())x=2*m/(1-m/n)
y=(6*n-x)/n
z=x/(10-y)print('原有排队游客份数:%.1f, 每分钟新到游客份数:%.1f, 10口同开需%.1f分钟清零待检票游客.'%(x,y,z))

14 橡皮泥 - 实验3 简单的计算及输入输出 -《Python编程基础及应用实验教程》(高等教育出版社)

# 方法1
import mathd1 = float(input())
d2 = float(input())
r1 = d1 / 2
r2 = d2 / 2
v1 = 4 / 3 * math.pi * r1 * r1 * r1
v2 = 4 / 3 * math.pi * r2 * r2 * r2
sumV = v1 + v2
print("正方体边长为:{:.2f}.".format(pow(sumV, 1 / 3)))# 方法2
import matha = eval(input())
b = eval(input())
c = 4 / 3 * 3.1415
print("正方体边长为:{:.2f}.".format(pow(c * pow((a / 2), 3) + c * pow((b / 2), 3), (1 / 3))))

15 单个身份证的校验 - 实验19 身份证校验 - 《Python编程基础及应用实验教程》 - 高教社

注意:要判断一下输入的是否有17位

quanzhong = (7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2)
#           Z: [0,1,2,3,4,5,6,7,8,9,10]
#           M: [1,0,X,9,8,7,6,5,4,3,2]
jiaoyanma = ('1','0','X','9','8','7','6','5','4','3','2')
sum = 0
sfz = input()
if sfz[:17].isdigit():for i in range(17):sum += int(sfz[i]) * quanzhong[i]if sfz[-1]==jiaoyanma[sum % 11]:print("正确")else:print("错误")
else:print("错误")

22秋季Python第3周作业

题目

01 2018我们要赢

# 1
print("2018")
print("wo3 men2 yao4 ying2 !")
# 2
print("""2018\nwo3 men2 yao4 ying2 !""")
# 3
print("""2018
wo3 men2 yao4 ying2 !""")

02 重要的话说三遍

# 1
print("I'm gonna WIN!")
print("I'm gonna WIN!")
print("I'm gonna WIN!")
# 2
print("""I'm gonna WIN!
I'm gonna WIN!
I'm gonna WIN!""")

03 交换a和b的值

a,b=map(int,input().split())
# print("a=%d,b=%d"%(b,a))
print("a={},b={}".format(b,a))

04 求圆面积

import math
r=float(input())print("{:.6f}".format(r*3.14*r))

05 实数x的n倍

x,n=map(float,input().split())
print("y={:.6f}".format(x*n))

06 把字符串中的大写字母改成小写字母

# while True:
#     try:
#         s=input()
#         print(s.lower())
#     except:
#         breakimport sys
for line in sys.stdin:line=line.strip()print(line.lower())

07 字符串的连接

s1=input()
s2=input()
s=s1+s2
print(s)

08 查找指定字符

【Python】字符串几个常用查找方法

s=input()
str=input()
if str.rfind(s)!=-1:
#     print("index = %d"%(str.rfind(s)))
#     print("index = {}".format(str.rfind(s)))print("index = {}".format(str.rindex(s)))
else:print("Not Found")

09 输出大写英文字母

s1 = input()
s2 = ''    #除去小写字母的字符串
s3 = ''    #除去重复字母的字符串
for i in s1:if ord('A') <= ord(i) <= ord('Z'):s2 += i
mylist = list(set(s2))       #用set()函数对s2去重,存储为一个列表#由于set()函数是无顺序去重,应调回原来顺序
mylist.sort(key = s2.index)  #用s2的顺序排列列表# print(s2)for i in mylist:              #将列表的值存为字符串s3 += i
if s3 != '':                 #输出print(s3)
else:print("Not Found")

10 字符转换

# 方法一
s = input()
a = "".join(list(filter(str.isdigit, s)))
print(int(a))  # 注意后面需要以int格式输出,不然就会输出000123等格式。# 方法二
s = input()
result = list()
M = list(('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'))
for i in range(0, len(s)):if s[i] in M:result.append(s[i])
ans = "".join(result)
print(int(ans))

注意后面需要以int格式输出,不然就会输出000123等格式。

11 算术入门之加减乘除


输入样例1:

6 3

输出样例1:

6 + 3 = 9
6 - 3 = 3
6 * 3 = 18
6 / 3 = 2

输入样例2:

8 6

输出样例2:

8 + 6 = 14
8 - 6 = 2
8 * 6 = 48
8 / 6 = 1.33
# 方法一
a, b = map(float, input().split())
print("{:.0f} + {:.0f} = {:.0f}".format(a, b, a + b))
print("{:.0f} - {:.0f} = {:.0f}".format(a, b, a - b))
print("{:.0f} * {:.0f} = {:.0f}".format(a, b, a * b))
if a % b == 0:print("{:.0f} / {:.0f} = {:.0f}".format(a, b, a / b))
else:print("{:.0f} / {:.0f} = {:.2f}".format(a, b, a / b))# 方法二
a, b = map(float, input().split())
print("%d + %d = %d" % (a, b, a + b))
print("%d - %d = %d" % (a, b, a - b))
print("%d * %d = %d" % (a, b, a * b))
if a % b == 0:print("%d / %d = %.0f" % (a, b, a / b))
else:print("%d / %d = %.2f" % (a, b, a / b))

12 统计大写辅音字母

# 方法1
s = input()
ans = list(filter(lambda x: x.isupper() and x not in ('A', 'E', 'I', 'O', 'U'), s))
print(len(ans))# 方法2
s = input()
yuanyin = ['a', 'e', 'i', 'o', 'u']
ans = 0
for i in s:if i.lower() not in yuanyin and ord('A') <= ord(i) <= ord('Z'):ans += 1
print(ans)# 方法3
s = input()
ans = ""
string = "AEIOU"
for i in range(len(s)):if s[i] >= 'A' and s[i] <= 'Z' and s[i] not in string:ans = ans + s[i]
print("{}".format(len(ans)))

13 字符串替换

s = input()
ans = ""
for i in s:if ord('A') <= ord(i) <= ord('Z'):ans += chr( 155 - ord(i) )else:ans += i
print(ans)

14 字符串转换成十进制整数

s = input()s1 = ''
for ch in s:if ch != '#':s1 += chelse:breaks_sixteen = ''
index = 0
s_index = -1
for ch in s1:if ord('0') <= ord(ch) <= ord('9') or ord('a') <= ord(ch.lower()) <= ord('f'):s_sixteen += chif s_index == -1:s_index = indexindex += 1fuhao = 1
for index in range(s_index):if s1[index] == '-':fuhao = -1breakans = 0
if s_sixteen != '':ans = fuhao * int(s_sixteen, 16)
print(ans)

15 然后是几点

start_time,lost_min = map(int, input().split())start_h = start_time // 100
start_min = start_time % 100
start_sum = start_h * 60 + start_min now_sum = start_sum + lost_min now_h = now_sum // 60
now_min = now_sum % 60# print("%d%02d" %(now_h,now_min))
print("{:01d}{:02d}".format(now_h,now_min))

Python中的//是向下取整的意思
a//b,应该是对除以b的结果向负无穷方向取整后的数
举例:
5//2=2(2.5向负无穷方向取整为2),同时-5//2=-3(-2.5向负无穷方向取整为-3)

22秋季Python第4周作业

题目

1 回文数

a[::-1]是将数组所有元素逆置

a=input()
b=a[::-1]
if a==b:print('yes')
else:print('no')

2 判断是否构成三角形

a,b,c=map(int,input().split())
if a + b <= c or a + c <= b or c + b <= a:print("NO")
else:print("YES")

3 整数平方根

# 直接0.5次方
x = float(input())
ans = float(x ** 0.5)
print("{:.6f}".format(ans))# 使用指对数袖珍计算器
import math
x = float(input())
if x == 0:ans = 0
else:ans = float(math.exp(0.5 * math.log(x)))if (ans + 1) ** 2 <= x:ans = ans + 1
print("{:.6f}".format(ans))# 二分法
x = float(input())
low, high, ans = 0, x, -1
while low <= high:mid = (low + high) // 2if mid * mid <= x:ans = midlow = mid + 1else:high = mid - 1
print("{:.6f}".format(ans))# 牛顿迭代法
x = float(input())
if x == 0:ans = 0
else:C, x0 = float(x), float(x)while True:xi = 0.5 * (x0 + C / x0)if abs(x0 - xi) < 1e-7:breakx0 = xians = float(x0)
print("{:.6f}".format(ans))

4 分支嵌套

x = float(input())
yes = 1
if 0 < x < 5:y = x * x + 1
elif x == 0:y = 0
elif -5 < x < 0:y = -x + 4
else:yes = 0print("No meaning")
if yes == 1:print("x={:.2f},y={:.2f}".format(x, y))

5 不合格的小球

a, b, c, d = map(int, input().split())
list = [a, b, c, d]
number = ['A', 'B', 'C', 'D']
index = 0
for i in range(3):if list[i] == list[i + 1]:index = list[i]
for j in range(4):if list[j] != index:print("{} {}".format(number[j], list[j]))

6 简单的猜数字游戏[1]

guess = int(input())
if guess>38:print("Too big!")
elif guess<38:print("Too small!")
else:print("Good Guess!")'''
产生随机数  random.randint(start,end)
可以猜多次,直到才对了位置
如果猜错了给出提示
猜大了还是猜小了
'''
'''
# import random
# ran = random.randint(1,50)
# count = 0
# print('猜数字游戏:')
# while True:
#     #进入猜数字环节 while循环
#     guess = int(input('请输入您要猜的数字:'))
#     count = count + 1
#     if guess == ran:
#         print('恭喜你猜对了')
#         break
#     elif guess > ran:
#          print('猜大了')
#     else :
#         print('猜小了')
# print('你一共猜了%d'% count)
'''

7 求某月的天数

while True:try:y,m=input().split()y=int(y)m=int(m)list=[31,28,31,30,31,30,31,31,30,31,30,31]if y%400==0 or y%4 == 0 and y%100!=0:list[1]=29print(list[m-1])except:break

8 统计各类字符数量并输出字母


输入样例:

ABC xyz 123 ?!

输出样例:

abcXYZ
letters:6, digits:3, spaces:3, others:2.
s = input()
num, char, space, other = 0, 0, 0, 0      #分别统计数字、字母、空格、其他字符个数
s1=""
for i in s:#是否为数字if i.isdigit():num += 1#是否为字母elif i.isalpha():char += 1if "a"<= i <= "z":s1+=(i.upper())elif"A" <= i <= "Z" :s1+=(i.lower())elif i == ' ':space += 1else:other += 1
print(s1)
print("letters:{}, digits:{}, spaces:{}, others:{}.".format(char, num, space, other))

9 计算邮资

m, s = map(str, input().split())
m = int(m)
price = 0
# 如果字符是y,说明选择加急;如果字符是n,说明不加急。
if s == "n":if m <= 1000:price = 8if (m > 1000) and ((m % 500) > 0):a = ((m - 1000) // 500) + 1a = a * 4price = 8 + aif (m > 1000) and ((m % 500) == 0):a = (m - 1000) // 500a = a * 4price = 8 + aif s == "y":if m <= 1000:price = 13if (m > 1000) and ((m % 500) > 0):a = ((m - 1000) // 500) + 1a = a * 4price = 8 + a + 5if (m > 1000) and ((m % 500) == 0):a = (m - 1000) // 500a = a * 4price = 8 + a + 5
print(price)

10 币值转换

# 方法一
a = input()
a = int(a)
s = []
n = ""
p = w = 1
zero = False
if len(str(a)) <= 9 and a >= 0:count = len(str(a))counts = len(str(a))while a % 10 == 0 and a > 0:a = a // 10s = str(a)for num, i in enumerate(s):if num < len(s) - 1:w = list(s)[num]p = list(s)[num + 1]if int(w) == 0 and int(p) == 0 and not count == 5:n += ""zero = Trueelif int(w) == 0 and not int(p) == 0 and zero == False and num < len(s) - 1:n += "a"elif count == 5 and int(i) == 0:n += "W"elif count == 9 and zero == False:n += chr(ord(i) + 49) + "Y"elif count == 5 and zero == False:n += chr(ord(i) + 49) + "W"elif (count == 4 or count == 8) and zero == False:n += chr(ord(i) + 49) + "Q"elif (count == 3 or count == 7) and zero == False:n += chr(ord(i) + 49) + "B"elif (count == 2 or count == 6) and zero == False:n += chr(ord(i) + 49) + "S"elif zero:n += "a"w = p = 1zero = Falseelse:n += chr(ord(i) + 49)count -= 1if counts > 8 and int(list(s)[3]) == 0 and int(list(s)[2]) == 0 and int(list(s)[1]) == 0:n = n.replace("W", "")print(n)'''
# 方法2
def fun(a):  # a是一个由整数组成的数组num = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']flag = 1  # 高位没有零if len(a) == 4:if a[0] == '0':if a[1] == '0' and a[2] == '0' and a[3] == '0':return ''else:qianwei = 'a'flag = 0  # 高位已经有零else:qianwei = num[int(a[0])] + 'Q'if a[1] == '0' and a[2] == '0' and a[3] == '0':return qianweiif a[1] == '0':if flag == 0:baiwei = ''else:baiwei = 'a'flag = 0else:baiwei = num[int(a[1])] + 'B'flag = 1if a[2] == '0' and a[3] == '0':return qianwei + baiweiif a[2] == '0':if flag == 0:shiwei = ''else:shiwei = 'a'flag = 0else:shiwei = num[int(a[2])] + 'S'flag = 1if a[2] == '0' and a[3] == '0':return qianwei + baiwei + shiweiif a[3] == '0':gewei = ''else:gewei = num[int(a[3])]flag = 1return qianwei + baiwei + shiwei + geweielif len(a) == 3:baiwei = num[int(a[0])] + 'B'if a[1] == '0' and a[2] == '0':return baiweielif a[1] == '0' and a[2] != '0':return baiwei + 'a' + num[int(a[2])]elif a[1] != '0' and a[2] == '0':return baiwei + num[int(a[1])] + 'S'else:return baiwei + num[int(a[1])] + 'S' + num[int(a[2])]elif len(a) == 2:shiwei = num[int(a[0])] + 'S'if a[1] == '0':return shiweielse:return shiwei + num[int(a[1])]else:return num[int(a[0])]n = input()
if len(n) <= 4:print(fun(n))
# elif len(n) > 4 and len(n) <= 8:
elif 4 < len(n) <= 8:n1 = n[len(n) - 4:]n2 = n[:len(n) - 4]print(fun(n2) + 'W' + fun(n1))
else:n1 = n[len(n) - 4:]n2 = n[len(n) - 8:len(n) - 4]n3 = n[:len(n) - 8]print(fun(n3) + 'Y' + fun(n2) + 'W' + fun(n1))
'''

11 分段函数3

x = int(input())
y = 0
if x >= 0:y = x + 3
else:y = x / 2
print("y={:.6f}".format(y))

12 从5个整数中找出最小的数。

import sysfor line in sys.stdin:a = line.split()a = [int(line) for line in a]print(min(a))

13 考试分数对应等级

a = int(input())
if 0 <= a < 60:print("-1")
elif 60 <= a < 90:print("0")
else:print("1")

14 日历

请编写程序,输入年份和月份,输出日历。

输入格式

第一行为整数n
后面有n行数据,每行包含两个整数y和m
其中:y为年份(1000≤y≤9999),m为月份(1≤m≤12)

输出格式

这些月的日历(参考输出样例)

输入样例1

1
2017 6

输出样例1
(参见下图)

输入样例2

2
2020 5
2020 12

输出样例2
(参见下图)

要求:每行末尾不得有多余的空格,日历末尾不得有多余的空行。

提示:公元1年1月1日为星期一。

import calendar
# print(calendar.weekday(1, 1, 1))
# print(calendar.weekday(2017,6,1))
calendar.setfirstweekday(calendar.SUNDAY)
num = int(input())
for i in range(num):year, month = [int(x) for x in input().split()]# print(year, month)print(' ' * 5, end='')print("%4d年" % year, end='')print("%2d月"%month)print()print("日 一 二 三 四 五 六")rili = calendar.month(year, month, w=2, l=1)# print(rili)rili_lst = rili.split('\n')# print(rili_lst)for i in range(2, len(rili_lst)):if len(rili_lst[i]) > 0:print(rili_lst[i])

【python】习题 1-4周相关推荐

  1. Python语言程序设计 第一周习题

    Python语言程序设计 第一周习题 习题1 获得用户输入的一个整数,参考该整数值,打印输出"Hello World",要求:‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮ ...

  2. 【python】习题第9周

    [python]习题 第9周 22秋季Python第9周作业 函数题 6-1 完数统计 6-2 偶数是两个素数的和 6-3 浮点数的十进制转二进制 6-4 实现象棋中相的走法 6-5 富翁与骗子 - ...

  3. Python.习题五 列表与元组(下)

    Python.<习题五> 列表与元组 11.假设列表lst_info=[["李玉","男",25],["金忠","男& ...

  4. 近找到了一个免费的python教程,两周学会了python开发【内附学习视频】

    原文作者:佛山小程序员 原文链接:https://blog.csdn.net/weixin_44192923/article/details/86515984 最近找到了一个免费的python教程,两 ...

  5. 最近找到了一个免费的python教程,两周学会了python开发

    最近找到了一个免费的python教程,两周学会了python开发 最近找到了一个免费的python教程,两周学会了python开发.推荐给大家,希望召集更多的朋友一起学习python. 最近开始整理p ...

  6. 【Python习题】计算弓形的面积(保姆级图文+实现代码)

    目录 题目 实现思路 实现代码 总结 主要内容是校设课程的习题和课外学习的一些习题. 欢迎关注 『Python习题』 系列,持续更新中 欢迎关注 『Python习题』 系列,持续更新中 题目 题目 如 ...

  7. 百分制成绩转换五分制F【Python习题】(保姆级图文+实现代码)

    目录 题目 描述 输入格式 输出格式 输入输出示例 思路 代码 实现效果 总结 主要内容是校设课程的习题和课外学习的一些习题. 欢迎关注 『Python习题』 系列,持续更新中 欢迎关注 『Pytho ...

  8. 【Python习题】简易英汉字典(project-ssss)(题目的坑解析+实现代码)

    目录 题目 示例 1‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬ ...

  9. 浙大python习题超详细思路(第二章)

    人生苦短,我用python https://pintia.cn/problem-sets/1111652100718116864/problems/type/7 题源来自pta 没有读者验证码,只是验 ...

  10. Python 习题 老虎、棒棒、鸡、虫

    Python 习题 老虎.棒棒.鸡.虫 看了好多人写的同项目代码,好长,想着写个短的. import time,random def pd(n,t):if (n == 0 and t == 4) or ...

最新文章

  1. 制药行业验证过程中的偏差如何处理?
  2. 利用bat批量执行脚本文件
  3. PyTorch 之 DataLoader
  4. presto-docker运行
  5. c++ 随机字符串_关于Python的随机数模块,你必须要掌握!
  6. 基于DirectShow的局域网内音视频流的多机共享
  7. uva 10246(变形floyd)
  8. Struts2(三)
  9. Solr 4.10.3 schema.xml 域类型详解
  10. haproxy1.7编译安装配置
  11. 行为类模式(九):策略(Strategy)
  12. 网上银行显示本服务器只显示,使用企业网上银行时常见报错提示有哪些,怎么解决?...
  13. C#实例.net_经典例子400个
  14. oracle簇详解,Oracle 簇的使用详解
  15. 经历三家千人互联网公司,提炼了20+条黄金法则
  16. 前端 传表格多条数据 给后台接收 (HTML前端表格多条数据JSON封装后;异步提交到后台处理)
  17. spring-aop切面
  18. 如何选择统计检验方法
  19. UsageStatsService之坑:一个XML解析异常导致的开机动画死循环
  20. 钉钉小程序父组件调用子组件方法(钉钉小程序踩坑实录)

热门文章

  1. 计算机英语中级职称题库,职称计算机考试题库(中级职称需要考计算机吗)
  2. 关于Autorelease和RunLoop
  3. 电力拖动计算机系统考试,安徽工程大学期末考试《电力拖动自动控制系统》往年简答题答案范围总结.doc...
  4. 【粗解】【通信编码】卷积编码器的简单实现
  5. 简单的amr转换mp3音频格式转换方法
  6. OpenSolaris系列文章之----投影仪设置
  7. 高效科研神器——文献阅读篇
  8. Vmware Tools安装详细步骤
  9. Google桌面与BBdoc文件管理助手对比分析
  10. 谷歌应用程序无法启动,因为应用程序的并行配置不正确的问题解决方案