TZC 初中信息技术(python)题单————题解

初中信息技术(Python)题单

八年级上册,高中信息技术必修的前置内容。TZOJ中学信息技术(Python)题目分类

TZC 初中信息技术(python)题单————题解_第1张图片

第一单元 Python程序设计基础

第1课 初识Python

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

print("Hello, World!")

P5 7182 我的第一个程序

n = input()
print("Hello,", n)

P6 6933 演讲打招呼

m = input()
n = input()
print("Hello everyone, I'm", m)
print("I'm", n, "years old")

第2课 常用数据类型

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

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

7166P9 7166 列表索引问题简单版2

s = input()
n = int(input())
print(s[n-1])

P10 7169 字符串切片1

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

7170P10 7170 字符串切片2

lista = input()
print(lista[2:11:3])

7172P10 7172 字符串切片4

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

P10 7173 字符串切片5

lista = input()
print(lista[-2:-6:-1])

7174P10 7174 字符串切片6

lista = input()
print(lista[-3:-10:-3])

P10 6783 三角形的周长

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

第3课 算数运算符和表达式

P14 7020 温度转换1

F = int(input())
C = 5 / 9 * ( F -32)
#print("%.0f" % C)
print( format(C , '.0f'))

P16 6785 3位数的每一位

n = int(input())
a = n // 100
b = n // 10 % 10
c = n % 10
print( a , b , c, sep = ',')

s = input()
print(s[0], s[1], s[2], sep=',')

6784P16 6784 温度转换2

C = float(input())
F = 9 / 5* C + 32
#print("%.2f" % F)
print(format(F,'.2f'))

第二单元 Python程序基本结构

第4课 顺序结构程序设计

P20 1491 C语言实验题――三角形面积

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(format(s, '.3f'))

P21 7132 圆的面积

r = int(input())
s = 3.14 * r ** 2
print("%.2f" % s)

P21 7133 圆的周长

r = int(input())
l = 3.14*r*2
print("%.2f" % l)

第5课 分支结构设计

P23 6810 两个数较大

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

P23 6811 两个数较小

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

P25 6812 Alice的登录账号密码

user = input()
pwd = input()
if user == "admin" and pwd=="Python@16":
    print("Login successful")
else:
    print("Username or password is wrong")

P26 6792 出租车收费

x = float(input())
if int(x) != x:
    x = int(x) + 1
if x <= 3:
    y = 10
else:
    y = 10 + (x - 3) * 2
print(int(y))

P26 6793 三角形判断2

a = float(input())
b = float(input())
c = float(input())
if a + b > c and a + c > b and b + c > a:
    p = (a + b + c) / 2
    area = (p * (p - a) * (p - b) * (p - c)) ** 0.5
    print("%.3f" % area)
else:
    print("Not triangle")

第6课 多分支结构程序设计

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

P29 5909 三个数的最小值

a = int(input())
b = int(input())
c = int(input())
min_val = min(a, min(b, c))
print(min_val)

P30 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!")

P31 6821 运动会名次

score = int(input())
if score == 1:
    print(7)
elif score == 2:
    print(5)
elif score == 3:
    print(4)
elif score == 4:
    print(3)
elif score == 5:
    print(2)
elif score == 6:
    print(1)
else:
    print("Error")

第7课 多分支结构的应用实例

P34 6822 浙江省汽车牌号所在地查询

sign = input()
if sign == 'A':
    print("Hangzhou")
elif sign == 'B':
    print("Ningbo")
elif sign == 'C':
    print("Wenzhou")
elif sign == 'D':
    print("Shaoxing")
elif sign == 'E':
    print("Huzhou")
elif sign == 'F':
    print("Jiaxing")
elif sign == 'G':
    print("Jinhua")
elif sign == 'H':
    print("Quzhou")
elif sign == 'J':
    print("Taizhou")
elif sign == 'K':
    print("Lishui")
elif sign == 'L':
    print("Zhoushan")
else:
    print("Input error")

P35 6823 空气质量查询

aqi = int(input())
if 0 <= aqi <= 50:
    print("Good")
elif aqi <= 100:
    print("Moderate")
elif aqi <= 150:
    print("Unhealthy for Sensitive Groups")
elif aqi <= 200:
    print("Unhealth")
elif aqi <= 300:
    print("Very Unhealthy")
else:
    print("Hazardous or Beyond Index")

第8课 循环结构--for循环

P37 7179 输出字符串的各个字符

s = input()
n = len(s)
for i in range(n):
    print(s[i])

或:

s = input()
for i in s:
    print(i)

P38 5952 求1到n中的奇数的和

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

P38 7184 输出列表中的各个元素

lst = input().split()
for x in lst:
    print("current fruit:", x)

P39 7185 通过成员资格运算符输出列表元素

lst = input().split()
for x in lst:
    print(x, len(x)

P39 7186 通过索引遍历输出列表元素

lst = input().split()
for i in range(len(lst)):
    print(i, lst[i])

第9课 for循环的应用实例

P42 6824 数麦粒

n = int(input())
s = 1
item = 1
for i in range(2, n+1):
    item *= 2
    s += item
w = (s * 0.03) / 1000000
print(s)
print(format(w, '.2f'))

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

第10课 循环结构--while循环

P46 7187 多个数求和1

s = 0
count = 0
a = input()
while a != '':
    a = float(a)
    s += a
    count = count + 1
    a = input()
print(count)
print(format(s, '.2f'))


P47 7188 多个数求和2

s = 0
count = 0
a = input()
while a != 'quit':
    a = float(a)
    s += a
    count = count + 1
    a = input()
print(count)
print(format(s, '.2f'))

P48 7189 Alice的登录账号密码2

user = input("Please input your username:\n")
while True:
    if user != "admin":
        user = input("Please input your username:\n")
    else:
        psw = input("Please input your password:\n")
        if psw == "Python@16":
            break
print("Login successful!")

第11课 while循环的应用实例

P51 7192 猜数游戏3

n = int(input())
count = 1
while n != 66:
    if n > 66:
        print("bigger")
    else:
        print("smaller")
    count = count + 1
    n = int(input())
print("right, num:", count)

P51 6825 储蓄问题

p = float(input())
q = float(input())
year = 0
while p < q:
    p *= 1.03
    year = year + 1
print(year)

第三单元 算法与程序设计

第12课 Python的函数

P55 5348 函数补充:字符串长度

def strlen(a):
    n = len(a)
    return n

P56 7193 函数补充:打印信息

def printinfo(name, age):
    print("Name:", name)
    print("Age:", age)

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

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

P59 6861 函数补充:第几天

def fcount(y, m, d):
    lst = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
    if m == 1:
        days = d
    elif m == 2:
        days = lst[1] + d
    elif m == 3:
        days = sum(lst[1:3]) + d
    elif m == 4:
        days = sum(lst[1:4]) + d
    elif m == 5:
        days = sum(lst[1:5]) + d
    elif m == 6:
        days = sum(lst[1:6]) + d
    elif m == 7:
        days = sum(lst[1:7]) + d
    elif m == 8:
        days = sum(lst[1:8]) + d
    elif m == 9:
        days = sum(lst[1:9]) + d
    elif m == 10:
        days = sum(lst[1:10]) + d
    elif m == 11:
        days = sum(lst[1:11]) + d
    else:
        days = sum(lst[1:12]) + d
    if m > 2 and (y % 4 == 0 and y % 100 != 0 or y % 400 == 0):
        days = days + 1
    return days

第13课 Python的模块

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

P65 6828 列表元素循环左移问题

n = int(input())
lst = [int(x) for x in input().split()]
k = int(input())
# 不知道为什么用切片不行,lst = lst[k:] + lst[:k],而只能用下面的循环
for i in range(1, k+1):
    a = lst.pop(0)
    lst.append(a)
for i in range(len(lst)):
    if i != len(lst)-1:
        print(lst[i], end=" ")
    else:
        print(lst[i])

第14课 枚举算法

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

P70 6829 零钱兑换

n = int(input())
count = 0
for i in range(n//20 + 1):
    for j in range(n//10 + 1):
        for k in range(n//5 + 1):
            if i * 20 + j * 10 + k * 5 == n:
                count = count + 1
print(count)

P70 6830 寻找完全数

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

第15课 Python的图形界面设计

你可能感兴趣的:(python刷题题单,python)