高中信息技术必修1 作业本 题单 ———— 题解

http://www.tzcoder.cn/acmhome/news.do?method=newsDetail&id=2c903bb47e8bd7a4017e938c6c09017e

本博客原文地址:https://www.cnblogs.com/BobHuang/p/14793851.html,原文体验更佳。

第四、五章为具体应用,平台无法提供测试。

第一章 数据与信息

1.1 感知数据

1.2 数据、信息与知识

P6 例2 6831 苹果装箱问题

lst = [1]
i = 1
num = int(input())
while sum(lst) <= num:
    lst.append(2 ** i)
    i = i + 1
lst.pop(-1)
if sum(lst) < num:
    lst.append(num - sum(lst))
print(len(lst))
for i in range(len(lst)):
    if i != len(lst) - 1:
        print(lst[i], end=' ')
    else:
        print(lst[i])

P6 T4 7345 二进制位数1

n = int(input())
i = 1
s = 0
while s < n:
    s = 2 ** i
    i = i + 1
print(i-1)

T7 7346 n位二进制数最大值和最小值

n = int(input())
if n == 1:
    print(1, 1, sep=',')
elif n == 2:
    print(3, 3, sep=',')
elif n >= 3:
    str1 = str2 = "1"
    for i in range(n-2):
        str1 = str1 + "0"
        str2 = str2 + "1"
    str1 = str1 + "1"
    str2 = str2 + "1"
    print(int(str1, 2), int(str2, 2), sep=',')

T8 7347 二进制三角形

"""
  ( 0, 1 )
  ( 0, 2 )  ( 1, 2)
  ( 0, 3 )  ( 1, 3)  (2, 3)
  ( 0, 4 )  ( 1, 4)  (2, 4)  (3, 4)
  ...

  第1行 ———— 第1项:  2^0 + 2^1 = 3
  第2行 ———— 第2项:  2^0 + 2^2 = 5,  第3项:  2^1 + 2^2 = 6
  第3行 ———— 第4项:  2^0 + 2^3 = 9,  第5项:  2^1 + 2^3 = 10, 第6项:  2^2 + 2^3 = 12
  第4行 ———— 第7项:  2^0 + 2^4 = 17, 第8项:  2^1 + 2^4 = 18, 第9项:  2^2 + 2^4 = 20, 第10项: 2^3 + 2^4 = 24
  第5行 ———— 第11项: 2^0 + 2^5 = 33, 第12项: 2^1 + 2^5 = 34, 第13项: 2^2 + 2^5 = 36, 第14项: 2^3 + 2^5 = 40, 第15项: 2^4 + 2^5 = 48

"""

n = int(input())
s = 0
i = 1
while s < n:    # 确定n在第几层
    s += i
    i = i + 1
i = i - 1
t = i-(s-n)   # 确定该层第几个
print(2 ** (t-1) + 2 ** i)

T9 7351 十进制数的1字节补码表示

n = bin(int(input()))
if n[0] != '-':  # 正数
    print((8 - len(n[2:])) * '0' + n[2:])  # bin()返回的结果为0bxxx,所以要去除0b
else:  # 负数
    fm = list((8 - len(n[3:])) * '0' + n[3:])  # 负数前边有符号,所以字符串截取应多一位
    s = (''.join(fm)).replace('0', '2').replace('1', '0').replace('2', '1')  # 1变0,0变1,2是中间变量
    ans = bin(int(s, 2) + 1)
    print(ans[2:])

1.3 数据采集与编码

P11 T4原型 7208 Wave格式音频文件存储容量

m = int(input())
s = int(input())
mb = (44.1 * 1000 * 2 * 8 * 2 * (m * 60 + s)) / (8 * 1024 * 1024)
print(format(mb, '.1f'))

T5原型 7209 BMP文件格式存储容量

a = int(input())
b = int(input())
print(format(a*b*24/8/1024/1024, '.2f'))

T6 7352 视频存储容量

n = int(input())
g = n * (3840 * 2160) * 30 * 180 / (1024 * 1024 * 1024)
print(format(g, '.1f'))

T7 7335 UTF-8编码

不懂Unicode 和 Utf-8编码,没思路求解。

T9 7446 论坛消息解密1

codes = ['_____', '.____', '..___', '...__', '...._', '.....', '_....', '__...', '___..', '____.']
s = input()
s = s.replace("*", ".")
s = s.split("/")
for i in range(len(s)):
    if s[i] != '':
        print(codes.index(s[i]), end='')

7447 论坛消息解密2

codes = [['A', 'B', 'C'], ['D', 'E', 'F'], ['G', 'H', 'I'], ['J', 'K', 'L'], ['M', 'N', 'O'], ['P', 'Q', 'R', 'S'],
         ['T', 'U', 'V'], ['W', 'X', 'Y', 'Z']]
s = input()
for i in range(0, len(s), 2):
    print(codes[int(s[i])-2][int(s[i+1])-1], end='')

7448 论坛消息解密3

codes = {'Q': 'A', 'W': 'B', 'E': 'C', 'R': 'D', 'T': 'E', 'Y': 'F', 'U': 'G', 'I': 'H', 'O': 'I', 'P': 'J', 'A': 'K',
         'S': 'L', 'D': 'M', 'F': 'N', 'G': 'O', 'H': 'P', 'J': 'Q', 'K': 'R', 'L': 'S', 'Z': 'T', 'X': 'U', 'C': 'V',
         'V': 'W', 'B': 'X', 'N': 'Y', 'M': 'Z'}
s = input()
for x in s:
    print(codes[x], end='')

7449 论坛消息解密4

s = list(input())
n = len(s)
if n % 2 != 0:
    lst1 = s[:n//2 + 1]
    lst2 = s[n//2 + 1:]
else:
    lst1 = s[:n//2]
    lst2 = s[n//2:]

lst3 = []
n1 = len(lst1)
n2 = len(lst2)
if n1 == n2:
    for i in range(n1):
        print(lst1[i], lst2[i], sep='', end='')
else:
    if n1 < n2:
        for i in range(n1):
            print(lst1[i], lst2[i], sep='', end='')
        print(lst2[n2-1])
    else:
        for i in range(n2):
            print(lst1[i], lst2[i], sep='', end='')
        print(lst1[n1-1])

7450 论坛消息解密5

s = input()
print(s[::-1])

或:

s = input()
s = reversed(s)
for x in s:
    print(x, end='')

1.4 数据管理与安全

1.5 数据与大数据

第二章 算法与问题解决

2.1 算法概念及描述

P19 例3 7453 伪代码转换1

a = int(input())
b = int(input())
if a < b:
    a = a + b
    b = a - b
    a = a - b
print(a, b)

P19 T1 7454 自由落体下落高度

g = float(input())
t = int(input())
h = g * t ** 2 / 2
print(format(h, '.2f'))

T4 7455 自然语言描述转换1

s = 0
n = 1
while n <= 100:
    s = s + (-1) ** (n-1) * n
    n = n + 1
print(s)

T5 7456 自然语言描述转换2

x = float(input())
if x < 0:
    y = -x
else:
    y = x
print(format(y, '.2f'))

T6 7457 伪代码转换2

m = int(input())
n = int(input())
r = m % n
while r != 0:
    m = n
    n = r
    r = m % n
print(n)

2.2 算法的控制结构

P22 例1 7458 商场促销

pay = float(input())
if pay < 500:
    pay *= 0.88
elif pay < 1000:
    pay *= 0.80
else:
    pay *= 0.7
print(format(pay, '.2f'))

例3 7459 智能停车场

s = 200
n = int(input())
for i in range(n):
    car = input()
    if car == 'IN':
        s = s - 1
    else:
        s = s + 1
    print(s)

P25 T1 6834 一元二次方程是否有实数根

a = float(input())
b = float(input())
c = float(input())
disc = b ** 2 - 4 * a * c
if disc >= 0:
    print("exist")
else:
    print("not exist")

T2 7460 自然语言描述转换3

s = 0
t = 1
i = 1
while True:
    t = t * i
    s = s + t
    i = i + 1
    if i > 10:
        break
print(s)

T7 5006 害死人不偿命的(3n+1)猜想

n = int(input())
step = 0
while n > 1:
    if n % 2 == 0:
        n /= 2
    else:
        n = (3 * n + 1) / 2
    step = step + 1
print(step)

2.3 用算法解决问题的过程

P26 例1 7461 行李托运

x = float(input())
if x <= 50:
    y = x * 1.3
else:
    y = 50 * 1.3 + (x - 50) * 1.8
print(format(y, '.2f'))

例2 7462 纸张对折

h = float(input()) / 1000
count = 0
while h <= 8848.43:
    h *= 2
    count = count + 1
print(count)

P27 T4 7463 轨道交通票价

# 起步里程数以外部分,每增加1元分别可乘4,4,6,6,8千米
x = float(input())
if x <= 4:
    y = 2
elif x <= 8:
    y = 3
elif x <= 12:
    y = 4
elif x <= 18:
    y = 5
elif x <= 24:
    y = 6
elif x <= 32:
    y = 7
else:
    y = 8
print(y)

第三章 算法的程序实现

3.1 Python语言基础(一)

P32 例 7464 BMI指数计算

w = float(input())
h = float(input()) / 100
bmi = w / (h ** 2)
print(format(bmi, '.2f'))

7465 运动会参赛情况1

ming = int(input())
zhang = int(input())
if (ming == 1 and zhang == 0) or (ming == 0 and zhang == 1) or (ming == 1 and zhang == 1):
    print(1)
else:
    print(0)

7466 运动会参赛情况2

ming = int(input())
zhang = int(input())
if ming == 1 and zhang == 1:
    print(1)
else:
    print(0)

7467 运动会参赛情况3

ming = int(input())
zhang = int(input())
if ming == 0 and zhang == 0:
    print(1)
else:
    print(0)

P33 T1 7469 声控灯控制

day = int(input())
voice = int(input())
if day == 1:
    print(0)
else:
    if voice == 1:
        print(1)
    else:
        print(0)

6766 三角形判断

a=int(input())
b=int(input())
c=int(input())
if a+b>c and b+c>a and a+c>b:
    print("1")
else:
    print("0")

6773 闰年判断

year = int(input())
if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
    print(1)
else:
    print(0)

T2 7470 储蓄问题2

import math
m = int(input())
k = float(input())
x = (k-m) / (0.037 * m)
y = math.ceil(x)
if y < x:
    y = y + 1
print(y)

T5 6855 寻找水仙花数

m = int(input())
n = int(input())
for i in range(m, n+1):
    a = i // 100
    b = i // 10 % 10
    c = i % 10
    if a ** 3 + b ** 3 + c ** 3 == i:
        print(i)

T6 7263 勤奋与坚持

qin = 1
lan = 1
for i in range(365):
    qin *= 1.01
    lan *= 0.99
print(format(qin, '.2f'))
print(format(lan, '.2f'))

3.2 Python语言基础(二)

P36 例2 7471 3位数回文数

s = input()
if s[0] == s[-1]:
    print(1)
else:
    print(0)

P37 T2原型 6836 新年大合唱比赛得分

lista = []
s = 0
for i in range(10):
    lista.append(float(input()))
    s += lista[i]
s = (s - max(lista) - min(lista)) / 8
print(format(s, '.2f'))
# print("%.2f" % s)

T4 7364 火柴棍游戏1

num = int(input())
match = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
count = match[num]
print(count)

或:

n = int(input())
if n == 0 or n == 6 or n == 9:
    y = 6
elif n == 1:
    y = 2
elif n == 2 or n == 3 or n == 5:
    y = 5
elif n == 4:
    y = 4
elif n == 7:
    y = 3
else:
    y = 7
print(y)

7365 火柴棍游戏2

num = int(input())
match = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
a = num // 100
b = num //10 % 10
c = num % 10
count = match[a] + match[b] + match[c]
print(count)

或:

num = input()
match = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
a = int(num[0])
b = int(num[1])
c = int(num[2])
count = match[a] + match[b] + match[c]
print(count)

或:

def fire_num(n):
    if n == 0 or n == 6 or n == 9:
        y = 6
    elif n == 1:
        y = 2
    elif n == 2 or n == 3 or n == 5:
        y = 5
    elif n == 4:
        y = 4
    elif n == 7:
        y = 3
    else:
        y = 7
    return y


m = int(input())
a = m // 100
b = m // 10 % 10
c = m % 10
y = fire_num(a) + fire_num(b) + fire_num(c)
print(y)

7367 火柴棍游戏4

num = int(input())
match = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
lst = []
for i in range(100, 1000):
    a = i // 100
    b = i // 10 % 10
    c = i % 10
    count = match[a] + match[b] + match[c]
    if count == num:
        lst.append(i)
n = len(lst)
for i in range(n):
    print(lst[i])

T5 7368 身份证的编码问题

a = input()
print(a[6:10] + '-' + a[10:12] + '-' + a[12:14])
if int(a[-2]) % 2 != 0:
    print('male')
else:
    print('female')
m = '10X98765432'
v = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
s = 0
for i in range(17):
    s += int(a[i]) * v[i]
print(a[-1] == m[s % 11])

3.3 顺序结构的程序实现

P40 例1原型 6944 干支纪年法

year = int(input())
gan = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
zhi = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L']
n = year % 10
if n > 3:
    g = n - 3
else:
    g = n - 3 + 10

n = year % 12
if n > 3:
    z = n - 3
else:
    z = n - 3 + 12

print(gan[g - 1], zhi[z - 1], sep='')

例2 7369 化合物质量分数计算

n = input()
num = int(n[1]) * 12 / (int(n[1]) * 12 + int(n[3]) * 1 + int(n[5]) * 16)
print(format(num, '.1f'))

P42 T4 1491 三角形面积

a = float(input())
b = float(input())
c = float(input())
p = 1/2 * (a + b + c)
s = (p*(p-a)*(p-b)*(p-c)) ** 0.5
#print("%.3f" % s)
print(format(s, '.3f'))

T5 7384 十六进制加密问题

n = input()
s = list(hex(ord(n)))
t = s[2]
s[2] = s[-1]
s[-1] = t
for i in range(2, len(s)):
    if i != len(s) - 1:
        print(s[i], end='')
    else:
        print(s[i])

7385 十六进制解密问题

lst = list(input())
t = lst[0]
lst[0] = lst[-1]
lst[-1] = t
s = ""
for x in lst:
    s = s + x
s = int(s, 16)
print(chr(s))

3.4 分支结构的程序实现

P44 例1 7370 景点买票1

h = float(input())
if h < 1.2:
    print("free")
elif 1.2 <= h <= 1.5:
    print("half")
else:
    print("full")

例2原型 6845 星期几问题

y = int(input())
m = int(input())
d = int(input())
if m == 1:
    m = 13
    y -= 1
if m == 2:
    m = 14
    y -= 1
c = y // 100
y %= 100
w = y + int(y/4) + int(c/4) - 2 * c + int(26 * (m + 1)/10) + d - 1
w %= 7
if w == 0:
    print("Sunday")
elif w == 1:
    print("Monday")
elif w == 2:
    print("Tuesday")
elif w == 3:
    print("Wednesday")
elif w == 4:
    print("Thursday")
elif w == 5:
    print("Friday")
elif w == 6:
    print("Saturday")

3.5 循环结构的程序实现

P48 例1原型 6862 反弹高度

n = int(input())
h = 100
s = 0
for i in range(1, n+1):
    s += h*2
    h /= 2
s -= 100
print(format(s, '.2f'))
print(format(h, '.2f'))

例2 7372 压缩算法

st = input()
c = 1
s = ""
for p in range(1, len(st)):
    if st[p] == st[p-1]:
        c = c + 1
    else:
        s += str(c) + st[p-1]
        c = 1
    p = p + 1
s += str(c) + st[p-1]
print(s)

P50 T3 7376 技术成绩分析1

lst = list(map(int, input().split()))
s = sum(lst)
num = len(lst)
avg = s / num
print(format(avg, '.1f'))

7377 技术分析成绩2

lst1 = list(map(int, input().split()))
lst2 = list(map(int, input().split()))
count = 0
for i in range(10):
    if (lst1[i] + lst2[i]) >= 80:
        count = count + 1
print(count)

T5 7381 极大值

s = list(map(int, input().split()))
n = len(s)
count = 0
for i in range(1, n-1):
    if s[i] > s[i-1] and s[i] > s[i+1]:
        count = count + 1
print(count)

7373 学考分数折算

s = input()
total = 0
for x in s:
    if x == 'A':
        total += 10
    elif x == 'B':
        total += 9
    elif x == 'C':
        total += 7
    else:
        total += 4
print(total)

3.6 函数与模块

P54 例1 7472 托运行李价格

w = int(input())
price = int(input())
pay = 0
if w > 20:
    pay = (w - 20) * price * 0.015
print(format(round(pay, 1), '.0f'))

P55 T3原型 1094 C语言实验题――一元二次方程

a = float(input())
b = float(input())
c = float(input())
disc = (b ** 2 - 4 * a * c) ** 0.5
x1 = (-b + disc) / (2 * a)
x2 = (-b - disc) / (2 * a)
if x1 < x2:
    t = x1
    x1 = x2
    x2 = t
print(format(x1, '.2f'), format(x2, '.2f'))

T7 7405 函数补充:计算表达式的值

def fact(a):
    if a == 1:
        return 1
    else:
        return a * fact(a - 1)


def f(y, z):
    total = 0
    for i in range(1, z + 1):
        total += (y ** i) / fact(i)
    return total

3.7 解析算法的程序实现

P59 例1 7473 公共自行车收费

stime = list(map(int, input().split(":")))     # 租车开始时间
h1 = stime[0]
m1 = stime[1]
s1 = stime[2]

etime = list(map(int, input().split(":")))     # 租车结束时间
h2 = etime[0]
m2 = etime[1]
s2 = etime[2]

time = 0        # 租车时间
if h2 > h1:
    time = h2 - h1
if m2 > m1:
    time = time + 1
elif m2 == m1 and s2 > s1:
    time = time + 1
if time <= 1:
    pay = 0       # 租车费用
elif time <= 10:
    pay = time
else:
    pay = 10
print(pay)

P61 T2 6769 超简单计算器

a = int(input())
b = int(input())
c = input()
if c == '+':
    print(a + b)
elif c == '-':
    print(a - b)
elif c == '*':
    print(a * b)
elif c == '/':
    if b == 0:
        print("Divided by zero!")
    else:
        print(a // b)
else:
    print("Invalid operator!")

3.8 枚举算法的程序实现

P64 例2原型 1098 C语言实验题――素数

def is_prime(x):
    k = int(x ** 0.5)
    for j in range(2, k + 1):
        if x % j == 0:
            return False
    return True


lst = []
for i in range(100, 201):
    if is_prime(i):
        lst.append(i)
print(len(lst))
for i in range(len(lst)):
    if i != (len(lst) - 1):
        print(lst[i], end=' ')
    else:
        print(lst[i])


P65 T4 1530 哥德巴赫猜想

def is_prime(n):
    if n == 1:
        return False
    k = int(n ** 0.5)
    for x in range(3, k+1, 2):
        if n % x == 0:
            return False
    return True


def is3same(a, b, c):
    return (a == b) and (b == c)


def is2same(a, b, c):
    if a == b and a != c:
        return True
    if a == c and a != b:
        return True
    if b == c and b != a:
        return True


n = int(input())
while n != 0:
    a = b = r = 0
    for i in range(3, n, 2):
        if is_prime(i):
            for j in range(3, n - i, 2):
                if is_prime(j) and is_prime(n-i-j):
                    if is3same(i, j, n-i-j):
                        r = r + 1
                    elif is2same(i, j, n-i-j):
                        a = a + 1
                    else:
                        b = b + 1
    r += a//3 + b//6
    if r != 0:
        print(r)
    else:
        print("Error")
    n = int(input())

3.9 综合练习

P68 T12 7474 计算折线长度

import math

a = input()
#a = "0,0," + a  # 补上原点坐标
b = a.split(",")  # 取出各点的坐标
if len(b) % 2 == 0:
    s = 0
    for i in range(0, len(b) - 3, 2):
        x1 = int(b[i])
        y1 = int(b[i + 1])
        x2 = int(b[i + 2])
        y2 = int(b[i + 3])
        s += math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
    print(format(s, '.2f'))

T13原型 6850 凯撒密码加密

def change(code, key):
    if 'a' <= code <= 'z':
        m = ord(code) - ord('a') + key
        return chr((m + 26) % 26 + ord('a'))
    if 'A' <= code <= 'Z':
        m = ord(code) - ord('A') + key
        return chr((m + 26) % 26 + ord('A'))
    return code


s = input()
n = int(input())
a = []
for x in s:
    a.append(change(x, n))
for i in range(len(a)):
    if i != len(a) - 1:
        print(a[i], end='')
    else:
        print(a[i])

第四章 数据处理与应用

4.1 常用表格数据的处理

4.2 大数据处理架构

4.3 利用pandas模块处理数据

4.4 数据可视化

4.5 文本数据处理

4.6 大数据典型应用

第五章 人工智能及应用

5.1 人工智能的产生与发展

5.2 人工智能的应用及对社会的影响

你可能感兴趣的:(python刷题题单,python,开发语言)