TZC 高中信息技术(Python)必修题单————题解

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

高中课本默认初中学习过Python,建议先尝试下 初中信息技术(Python)TZOJ题单
必修部分,即普通高中学业水平考试(学考)内容,Python题目有一个分类 TZOJ中学信息技术(Python)题目分类

TZC 高中信息技术(Python)必修题单————题解_第1张图片

必修1 数据与计算

第一章 数据与信息

1.1 感知数据

1.2 数据、信息与知识

1.3 数据采集与编码

P16 6882 十进制转二进制

a=int(input())
m=''
while a>0:
    m+=str(a%2)
    a//=2
print(m[::-1])

或:

a=int(input())
m=bin(a)
print(m[2:])

P16 6883 二进制转十进制

a=input()
print(int(a,2))

P16 7031 十进制转十六进制

n=int(input())
s=str(hex(n))
print(s[2:].upper())

P16 7207 二进制转十六进制

n=input()
s=hex(int(n,2))
print(s[2:].upper())

P17 5885 ASCII表

s=input()
print(ord(s))

P17 5889 打印字符

s=int(input())
print(chr(s))

P22 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])

1.4 数据管理与安全

1.5 数据与大数据

P30 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'))

P30 7209 BMP文件格式容量

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

P33 7212 Base64编码简单版

import base64
n = input()
result = base64.b64encode(n.encode())
for x in result:
    print(chr(x), end="")

P33 7213 Base64编码解码简单版

import base64
n = input()
result = base64.b64decode(n)
for x in result:
    print(chr(x), end="")

第二章 算法与问题解决

2.1 算法概念及描述

P38 7134 最大公约数之更相减损术

m = int(input())
n = int(input())
while m != n:
    if m > n:
        m = m - n
    else:
        n = n - m
print(n)

P38 7135 最大公约数之辗转相除法

def gcd(x, y):
    r = x % y
    if r == 0:
        return y
    else:
        return gcd(y, r)


m = int(input())
n = int(input())
if m < n:
    t = m
    m = n
    n = t
z = gcd(m, n)
print(z)

或:

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

P39 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'))

P40 6832 函数补充:斐波那契数列的前n个元素

def fib(x):
    if x == 1:
        return 1
    elif x == 2:
        return 1
    else:
        return fib(x - 1) + fib(x - 2)

P40 7210 取区间中点1

start = int(input())
end = int(input())
middle = (start + end) / 2
print(format(middle, '.1f'))

P40 7216 账号登录程序

num = 0
pw = input()
while pw != "Python@16":
    num = num + 1
    if num < 5:
        print("The password is wrong. Try again!")
        pw = input()
    else:
        print("Input the password more than 5 times. Please reset your password by email!")
        break
if pw == "Python@16":
    print("Login successful!")

P41 7217 洗衣机洗衣算法---是否加水

n = float(input())
if n >= 50:
    print("Break")
else:
    print("Continue")

P41 7218 洗衣机洗衣算法---漂洗是否加水

n = int(input())
for i in range(n):
    input_list = input().split()
    num, quantity_of_water = int(input_list[0]), float(input_list[1])
    flag = False
    if quantity_of_water < 50:
        if num < 3:
            print("Water")
            flag = True
    if not flag:
        print("No")

P42 7219 智能空调算法--压缩机运行

t = float(input())
if t <= 26:
    print("pause")
else:
    print("run")

P46 6833 停车场车位探测中的算法

x = int(input())
if x == 0:
    print("green, parking space is empty")
else:
    print("red, parking space is occupied")

P47 7220 智能停车场引导系统

n = int(input())
park = []
for i in range(n):
    park.append(int(input()))
count = 0
for x in park:
    if x == 0:
        count = count + 1
print(count)

P47 7135 最大公约数之辗转相除法

同上,重复

P47 7134 最大公约数之更相减损术比较

同上,重复

P48 7226 电饭锅烧饭--温度控制

n = int(input())
flag = False
for i in range(n):
    temp = float(input())
    if temp < 103 and not flag:
        print("Continue")
    elif not flag:
        print("Break")
        flag = True

2.2 算法的控制结构

P50 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")

P51 6835 超市收银系统

n = int(input())
s = 0
for i in range(n):
    m = float(input())
    s += m
# print(format(s, '.2f'))
print("%.2f" % s)

P52 7228 智能农业大棚2

n = int(input())
for i in range(n):
    temp = float(input())
    if temp > 28+40:
        print("Start up cooling system")
    elif temp < 28-18:
        print("Start up heating system")

2.3 用算法解决问题的过程

P54 6741 动动有奖

n = int(input())
s, c = 0, 0
for i in range(n):
    x, f = map(int, input().split())
    if f == 1:
        if x >= 1000:
            t = 0.3+((x-1000)//2000)*0.1
            if t > 3:
                t = 3
        else:
            t = 0
        c = c+1
        if c >= 4:
            s = s+2*t
        else:
            s = s+t
    else:
        c = 0
print("%.1f"%s)

P58 7229 3个数排序简单版

a = int(input())
b = int(input())
c = int(input())
s = a + b + c
ma = max(a, max(b, c))
mi = min(a, min(b, c))
mid = s - ma - mi
print(mi, mid, ma)

或:

a = int(input())
b = int(input())
c = int(input())
s = a + b + c
ma = max(a, max(b, c))
mi = min(a, min(b, c))
mid = s - ma - mi
print(mi, mid, ma)

P58 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)

第三章 算法的程序实现

3.1 用计算机编程解决问题的一般过程

P67 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())

P67 4865 统计单词数

import re

while True:
    try:
        find = input().lower()
        inp = input().lower()
        cmp = re.compile('\\b' + find + '\\b')
        res = re.search(cmp, inp)
        if res is None:
            print(-1)
        else:
            ls = inp.split(" ")
            print("{0} {1}".format(ls.count(find), res.span()[0]))
    except:
        break

P69 1452 C语言实验题――Hello World

print("Hello, World!")

P69 1001 整数求和

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

3.2 Python语言程序设计

P77 7231 子串问题1

a = input()
b = input()
if b in a:
    print("exist")
else:
    print("not exist")

P73 7165 列表索引问题简单版1

a=input()
print(a[4])

P73 7169 字符串切片1

lista = input()
print(lista[1:4])

P77 6837 区间测速

t = float(input())
t /= 3600
v = 25 / t
if v > 100:
    print("speeding")
else:
    print("normal")

P80 7236 区间测速加强版

t = float(input())
t = t / 3600
v = 25 / t
if v > 100:
    if v < 120:
        print(format(v, '.1f'))
        print("Exceeding the specified speed and less than 20%")
    elif v < 150:
        print(format(v, '.1f'))
        print("Exceeding the specified speed by more than 20% and less than 50%")
    elif v < 170:
        print(format(v, '.1f'))
        print("Exceeding the specified speed by more than 50% and less than 70%")
    else:
        print(format(v, '.1f'))
        print("Exceeding the specified speed by more than 70%")
else:
    print(format(v, '.1f'))
    print("normal")

P81 6838 热量消耗

a = input().split()
b = []
for x in a:
    b.append(int(x))
print(sum(b))

P83 7191 猜数游戏2

while True:
    a = int(input())
    if a == 23:
        print("right")
        break
    elif a > 23:
        print("bigger")
    else:
        print("smaller")

P84 6839 求地的面积

def area(a, b, c):
    p = (a + b + c) / 2
    s = (p * (p - a) * (p - b) * (p - c)) ** 0.5
    return s


l1 = float(input())
l2 = float(input())
l3 = float(input())
l4 = float(input())
l5 = float(input())

y1 = area(l1, l2, l5)
y2 = area(l3, l4, l5)
y = y1 + y2
print(format(y, '.2f'))

P85 6781 算数平方根

n = float(input())
#print( format( n ** 0.5, '.2f'))
print('%.2f' % ( n ** 0.5))

P86 7237 圆的面积加强版

import math
n = float(input())
s = math.pi * (n ** 2)
print(format(s, '.8f'))

P89 6810 两个数较大

a=int(input())
b=int(input())
if a >= b:
    print(a)
else:
    print(b)

P89 5908 三个数的最大值

a = int(input())
b = int(input())
c = int(input())
# 打擂台算法
imax = a
if b > imax:
    imax = b
if c > imax:
    imax = c
print(imax)

或:

a = int(input())
b = int(input())
c = int(input())
imax = max(a, max(b, c))
print(imax)

P89 1459 求最大值

n = int(input())
lista = []
for i in range(n):
    lista.append(int(input()))
print(max(lista))

P89 6840 身份证号码

s = input()
print("{}-{}-{}".format(s[6:10], s[10:12], s[12:14]))
if int(s[-2]) % 2 == 0:
    print("female")
else:
    print("male")

P89 5953 求1到n中的偶数的和

s = input()
print("{}-{}-{}".format(s[6:10], s[10:12], s[12:14]))
if int(s[-2]) % 2 == 0:
    print("female")
else:
    print("male")

P89 6841 检测字符串是否全是数字

s = input()
if s.isdigit():
    print(1)
else:
    print(0)

3.3 简单算法及其程序实现

P91 7238 答题卡填涂--判断RGB颜色

r = int(input())
g = int(input())
b = int(input())
gray = 0.299 * r + 0.587 * g + 0.1144 * b
if gray < 132:
    print("Black")
else:
    print("White")

P91 6842 整数的因子

n = int(input())
for i in range(1, n+1):
    if n % i == 0:
        print(i)

P92 7240 答题卡填涂--像素填涂个数

n = int(input())
count = 0
for i in range(n):
    a = float(input())
    if a < 132:
        count = count + 1
print(count)

P93 7241 答题卡填涂--信息点是否填涂判断

count = 0
for i in range(300):
    R, G, B = map(int, input().split())
    gray = 0.299 * R + 0.587 * G + 0.1144 * B
    if gray < 132:
        count = count + 1
prob = count / 300
if prob >= 0.64:
    print("True")
else:
    print("False")

P100 6843 城市人口问题

x = float(input())
y = float(input())
year = 0
while x < y:
    x *= 1.012
    year = year + 1
print(year)

P100 6844 设备价格问题

m = 120
n = int(input())
for i in range(2, n+1):
    if i < 7:
        m -= 10
    else:
        m *= 0.75
print(format(m, '.2f'))

P100 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")

P100 6846 小z的简单加密

s = input()
b = []
for x in s:
    if x == 'a':
        x = 'z'
    else:
        x = chr(ord(x) - 1)
    b.append(x)
for x in b:
    print(x, end='')

P100 6847 韩信点兵

for i in range(1000, 1101):
    if i % 3 == 2 and i % 5 == 4 and i % 7 == 6:
        print(i)

P100 7194 百钱买百鸡 简单版

for i in range(21):
    for j in range(34):
        k = 100 - i - j
        if 5 * i + 3 * j + k / 3 == 100:
            print(i, j, k)

P101 6848 篮球得分预测问题

a, b = map(int, input().split(':'))
team = input()
t = int(input())
if a > b:
    a -= 3
    if team == 'A':
        a += 0.5
    else:
        a -= 0.5
    if a < 0:
        a = 0
    a = a ** 2
    if a > t:
        team = "A"
    else:
        team = "B"
else:
    b -= 3
    if team == 'B':
        b += 0.5
    else:
        b -= 0.5
    if b < 0:
        b = 0
    b = b ** 2
    if b > t:
        team = "B"
    else:
        team = "A"
print(team)

P101 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'))

P101 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)

P101 7242 成绩等级统计

a = b = c = d = e = 0
for i in range(30):
    n = int(input())
    if 90 <= n <= 100:
        a = a + 1
    elif 80 <= n <= 89:
        b = b + 1
    elif 70 <= n <= 79:
        c = c + 1
    elif 60 <= n <= 69:
        d = d + 1
    else:
        e = e + 1
print("A:", a)
print("B:", b)
print("C:", c)
print("D:", d)
print("E:", e)

P101 1499 C语言实验题――鸡兔同笼

n,m=map(int,input().split())
y=m//2-n
x=n-y
print(x,y)

P104 6849 图书优惠问题

n = int(input())
a = n // 300
b = (n % 300) // 200
c = ((n % 300) % 200) // 100
print(n - (a * 120 + b * 70 + c * 30))

P104 1476 C语言实验题――圆周率

n = int(input())
pi = 0
for i in range(1, n+1):
    pi += 1 / (4 * i - 3) - 1 / (4 * i - 1)
pi *= 4
print(format(pi, '.5f'))

P104 7195 利用蒙特卡罗方法计算π的值

import random
num = int(input())
point = 0
for i in range(num):
    x = random.random()
    y = random.random()
    if (x * x + y * y) <= 1:
        point = point + 1
print((point / num) * 4)

第四章 数据处理与应用

4.1 常用表格数据的处理

4.2 大数据处理

4.3 大数据典型应用

第五章 人工智能及应用

5.1 人工智能的产生与发展

5.2 人工智能的应用

5.3 人工智能对社会的影响

必修2 信息系统与社会

第一章 信息系统概述

1.1 信息技术与信息系统

1.2 信息系统的组成与功能

1.3 信息系统的应用

1.4 信息社会及其发展

第二章 信息系统的支撑技术

2.1 计算机硬件

2.2 计算机软件

2.3 移动终端

2.4 传感与控制

2.5 网络系统

2.6 网络应用软件开发

第三章 信息系统安全

3.1 信息安全与保护

3.2 信息系统安全与防护

P106 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])

P106 6851 凯撒密码解密

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])

P116 6875 简单换位密码1

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

P116 6876 简单换位密码2

s = list(input())
n = int(input())
for i in range(n):
    x = s.pop(0)
    s.append(x)
for i in range(len(s)):
    if i != len(s)-1:
        print(s[i], end="")
    else:
        print(s[i])

P117 6877 简单异或密码

始终是Running Error,不知道为什么?

以下代码Running Error,不知道为什么?
s = input()
m = bin(int(input()))
m = m[2:]
lst1 = []
for i in range(len(s)):
    x = bin(ord(s[i]))
    x = x[2:]
    n = len(x)
    y = '0' * (8 - n) + x
    lst2 = []
    for j in range(8):
        lst2.append(int(y[j]) ^ int(m[j]))
    lst1.append(lst2)
for i in range(len(lst1)):
    for j in range(len(lst1[i])):
        print(str(lst1[i][j]), end='')
    print('', end=' ')

第四章 信息系统

4.1 搭建信息系统的前期准备

4.2 搭建信息系统

4.3 完善信息系统

必修1第四、五章及必修2的编程为具体应用,平台无法提供测试。

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