đề thi lập trình Python mức độ trung bình

sallynguyen986 10 views 4 slides May 16, 2025
Slide 1
Slide 1 of 4
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4

About This Presentation

đề thi lập trình Python mức độ trung bình


Slide Content

ĐỀ THI MÔN LẬP TRÌNH PYTHON
ĐỀ SỐ 1 – CƠ BẢN
Câu 1:
a = int(input("Nhập số thứ nhất: "))
b = int(input("Nhập số thứ hai: "))
print("Số lớn hơn là:", max(a, b))
Câu 2:
def is_prime(n):
if n < 2: return False
for i in range(2, int(n**0.5)+1):
if n % i == 0:
return False
return True
n = int(input("Nhập số: "))
print("Là số nguyên tố" if is_prime(n) else "Không phải số nguyên tố")
Câu 3:
for i in range(2, 10):
for j in range(1, 11):
print(f"{i} x {j} = {i*j}")
print()
Câu 4:
def second_largest(lst):
lst = list(set(lst))
lst.sort()
return lst[-2] if len(lst) >= 2 else None
print(second_largest([4, 7, 2, 7, 9]))
ĐỀ SỐ 2 – TRUNG BÌNH
Câu 1:

n = int(input("Nhập n: "))
total = sum(i for i in range(1, n+1) if i % 3 == 0)
print("Tổng:", total)
Câu 2:
def reverse_string(s):
return s[::-1]
print(reverse_string("hello"))
Câu 3:
dssv = []
for _ in range(3):
ten = input("Tên: ")
diem = float(input("Điểm: "))
dssv.append((ten, diem))
dssv.sort(key=lambda x: x[1], reverse=True)
for sv in dssv:
print(sv[0], sv[1])
Câu 4:
s = input("Nhập chuỗi: ")
print("Palindrome" if s == s[::-1] else "Không phải")
ĐỀ SỐ 3 – NÂNG CAO
Câu 1:
def char_count(s):
d = {}
for ch in s:
d[ch] = d.get(ch, 0) + 1
return d
print(char_count("banana"))
Câu 2:
# Xem phần script Python quản lý sản phẩm như ở trên
Câu 3:

with open("data.txt", "r") as f:
text = f.read()
lines = text.splitlines()
words = text.split()
print("Dòng:", len(lines))
print("Từ:", len(words))
print("Ký tự:", len(text))
Câu 4:
lst = list(map(int, input("Nhập các số cách nhau bởi dấu cách: ").split()))
even = [str(x) for x in lst if x % 2 == 0]
with open("chan.txt", "w") as f:
f.write(" ".join(even))
ĐỀ SỐ 4 – ỨNG DỤNG
Câu 1:
class Rectangle:
def __init__(self, w, h):
self.width = w
self.height = h
def area(self):
return self.width * self.height
def perimeter(self):
return 2 * (self.width + self.height)
r = Rectangle(4, 5)
print(r.area(), r.perimeter())
Câu 2:
# ATM mô phỏng với lựa chọn nạp, rút, kiểm tra số dư
Câu 3:
import csv
with open("sinhvien.csv", newline='') as f:
reader = csv.reader(f)
max_sv = max(reader, key=lambda x: float(x[1]))
print("SV điểm cao nhất:", max_sv)

Câu 4:
text = input("Nhập đoạn văn: ")
words = text.split()
sentences = text.split('.')
paragraphs = text.split('\n')
print("Số từ:", len(words))
print("Số câu:", len([s for s in sentences if s.strip()]))
print("Số đoạn:", len([p for p in paragraphs if p.strip()]))