1、题目:输入一个字符,输出该字符相应的ASCII码。
# ord 函数可以字符作为参数,返回对应的 ascll 码
print(ord(input()))
2、题目:输入一个字符,输出该字符相应的ASCII码。
# round 函数可以四舍五入
round(a,b)
# a 是需要转化的数, b 是保留位数
3、题目:split函数
split(sep= " " , num)
sep为分割符,num为分割次数(默认分割所有)
分割后为列表
4.format 打印
print("score,{}{}".format(a,b))
print(f'score,{a}{b}')
BC11:
输入3科成绩,然后把三科成绩输出
list_score = input()
list_score = list_score.split()
count = 1
for i in list_score[0:2]:
print("score{}={}".format(count,i),end =",")
count+=1
print("score{}={}".format(count,list_score[2]))
5.round函数
要求保留位数的后一位“=5”,且该位数后面没有数字,则不进位:有数字则进位
所以round并不是数学意义上的四舍五入
6.用于四舍五入的函数
向上取整
需要导入
from decimal import *
a1 = Decimal('1.125').quantize(Decimal('0.00'),rounding=ROUND_HALF_UP)
BC12:
依次输入一个学生的学号,以及3科(C语言,数学,英语)成绩,在屏幕上输出该学生的学号,3科成绩(注:输出成绩时需进行四舍五入且保留2位小数)。
from decimal import*
id_list = input()
id_list = id_list.split(";")
id_student = id_list[0]
score_list = id_list[1].split(",")
print("The each subject score of No. {} is ".format(id_student),end = "")
count = 1
for i in score_list:
# i = round(float(i),2)
# declmal 的传入可以是字符串
# i = Decimal("i").quantize(Decimal(0.00),rounding = ROUND_HALF_UP)
i = Decimal(i).quantize(Decimal('0.00'),rounding=ROUND_HALF_UP)
if count == 3:
print(i, end=".")
break
elif count == 1 or 2:
print(i, end=", ")
count+=1
7.疑问
class Solution:
def maxScore(self, s: str) -> int:
这个函数还是不太懂什么意思 ,等后续工作时间 问问老师