Python Exercises - Homework

Bài Tập 1: Tính Tích của n Số (Product of n Numbers)

Đề bài: Nhập n số nguyên. Tính và in tích của tất cả các số.

Problem: Enter n integers. Calculate and print the product of all numbers.

Ví dụ:

Enter count: 4
Numbers: 2, 3, 4, 5

Output:

Product: 120

Bài Tập 2: Dãy Số Nhảy Bước (Skip Counting)

Đề bài: Nhập ba số: start, stop, step. In các số từ start đến stop với bước nhảy step.

Problem: Enter three numbers: start, stop, step. Print numbers from start to stop with step increment.

Ví dụ:

Start: 2
Stop: 20
Step: 3

Output:

2
5
8
11
14
17
20

Bài Tập 3: Tính n Giai Thừa Bằng Vòng Lặp (Calculate n Factorial with Loop)

Đề bài: Nhập số n. Tính n! (n giai thừa) = 1 × 2 × 3 × ... × n.

Problem: Enter n. Calculate n! (n factorial) = 1 × 2 × 3 × ... × n.

Ví dụ:

Enter n: 5

Output:

Factorial: 120

Bài Tập 4: Đếm từ a đến b (Count from a to b)

Đề bài: Nhập hai số a và b. In các số từ a đến b.

Problem: Enter two numbers a and b. Print numbers from a to b.

Ví dụ:

Enter a: 3
Enter b: 7

Output:

3
4
5
6
7

Bài Tập 5: Đếm Ngược (Countdown)

Đề bài: Nhập một số n. Đếm ngược từ n về 0 và in mỗi số trên một dòng.

Problem: Enter a number n. Count down from n to 0 and print each number on a line.

Ví dụ:

Enter n: 5

Output:

5
4
3
2
1
0

Bài Tập 6: Tổng Số Chẵn (Sum of Even Numbers)

Đề bài: Nhập n số nguyên. Tính tổng CHỈ các số chẵn.

Problem: Enter n integers. Calculate sum of ONLY even numbers.

Ví dụ:

Enter count: 5
Numbers: 10, 15, 22, 7, 8

Output:

Sum: 40

Bài Tập 7: Đếm Số Chia Hết cho 2 HOẶC 3 (Count Numbers Divisible by 2 OR 3)

Đề bài: Nhập n số nguyên. Đếm có bao nhiêu số chia hết cho 2 hoặc 3.

Problem: Enter n integers. Count how many are divisible by 2 or 3.

Ví dụ:

Enter count: 5
Numbers: 10, 13, 9, 7, 12

Output:

Count: 3

Bài Tập 8: Đếm Số Âm và Số 0 (Count Negative and Zero)

Đề bài: Nhập n số nguyên. Đếm có bao nhiêu số âm và bao nhiêu số 0.

Problem: Enter n integers. Count how many are negative and how many are zero.

Ví dụ:

Enter count: 6
Numbers: -3, 0, 7, -5, 0, 12

Output:

Negative: 2
Zero: 2

Bài Tập 9: Trung Bình Số Dương (Average of Positive Numbers)

Đề bài: Nhập n số nguyên. Tính trung bình CHỈ các số dương. Nếu không có số dương, in 'No positive numbers'.

Problem: Enter n integers. Calculate average of ONLY positive numbers. If no positive numbers, print 'No positive numbers'.

Ví dụ:

Enter count: 5
Numbers: -3, 10, -5, 20, 30

Output:

Average: 20.0

Bài Tập 10: In Số Trong Khoảng (Print Numbers in Range)

Đề bài: Nhập n số nguyên. Chỉ in các số trong khoảng 10-50 (bao gồm 10 và 50).

Problem: Enter n integers. Print only numbers in range 10-50 (inclusive).

Ví dụ:

Enter count: 6
Numbers: 5, 25, 60, 10, 50, 3

Output:

25
10
50

Bài Tập 11: Tìm Số Lớn Thứ Hai (Find Second Largest)

Đề bài: Nhập n số nguyên (n >= 2). Tìm số lớn thứ hai.

Problem: Enter n integers (n >= 2). Find the second largest number.

Ví dụ:

Enter count: 5
Numbers: 15, 42, 8, 42, 23

Output:

Second largest: 23

Bài Tập 12: Đếm Số Có Hai Chữ Số (Count Two-Digit Numbers)

Đề bài: Nhập n số nguyên. Đếm có bao nhiêu số có hai chữ số (10-99 hoặc -99 đến -10).

Problem: Enter n integers. Count how many have two digits (10-99 or -99 to -10).

Ví dụ:

Enter count: 6
Numbers: 5, 25, 100, -50, 3, 99

Output:

Count: 3

Bài Tập 13: Tìm Khoảng Cách Lớn Nhất (Find Maximum Gap)

Đề bài: Nhập n số nguyên liên tiếp. Tìm khoảng cách lớn nhất giữa hai số liên tiếp.

Problem: Enter n consecutive integers. Find the maximum gap between two consecutive numbers.

Ví dụ:

Enter count: 5
Numbers: 3, 7, 10, 12, 20

Output:

Max gap: 8

Bài Tập 14: Số May Mắn (Lucky Numbers)

Đề bài: Nhập n số nguyên. In 'Lucky' nếu số chia hết cho 7 HOẶC có chữ số tận cùng là 7, ngược lại in 'Not lucky'.

Problem: Enter n integers. Print 'Lucky' if divisible by 7 OR ends with 7, otherwise print 'Not lucky'.

Ví dụ:

Enter count: 4
Numbers: 14, 17, 25, 7

Output:

Lucky
Lucky
Not lucky
Lucky

Bài Tập 15: Kiểm Tra Dãy Tăng (Check Increasing Sequence)

Đề bài: Nhập n số nguyên. Kiểm tra xem dãy có tăng dần không (mỗi số lớn hơn số trước).

Problem: Enter n integers. Check if sequence is increasing (each number greater than previous).

Ví dụ:

Enter count: 5
Numbers: 3, 7, 10, 15, 20

Output:

Increasing: Yes

Bài Tập 16: Xác Thực Mật Khẩu Đơn Giản (Simple Password Validation)

Đề bài: Người dùng có 3 lần thử để nhập đúng mật khẩu. Mật khẩu là 'python123'. In 'Access granted' hoặc 'Access denied'.

Problem: User has 3 attempts to enter correct password. Password is 'python123'. Print 'Access granted' or 'Access denied'.

Ví dụ:

Password: abc
Wrong! Try again
Password: xyz
Wrong! Try again
Password: python123
Access granted

Output:

Access granted

Bài Tập 17: In Số Lớn Hơn Trung Bình (Print Numbers Greater Than Average)

Đề bài: Nhập n số nguyên. Tính trung bình, sau đó nhập lại n số và chỉ in các số lớn hơn trung bình.

Problem: Enter n integers. Calculate average, then enter n numbers again and print only those greater than average.

Ví dụ:

Enter count: 5
Numbers: 10, 20, 30, 40, 50
Enter numbers again:
10, 20, 30, 40, 50

Output:

40
50

Bài Tập 18: Đếm Chữ Số (Count Digits)

Đề bài: Nhập một số nguyên. Đếm số lượng chữ số của số đó (bao gồm cả số âm).

Problem: Enter an integer. Count the number of digits (including negatives).

Ví dụ:

Enter number: -4567

Output:

Digits: 4

Bài Tập 19: Đoán Số Có Giới Hạn (Number Guessing with Limit)

Đề bài: Chương trình nghĩ ra một số từ 1-50 (người dùng nhập số bí mật). Người chơi có tối đa 7 lần đoán. Mỗi lần đoán sai, cho gợi ý 'cao hơn' hoặc 'thấp hơn'. Nếu đoán đúng hoặc hết lượt, kết thúc game.

Problem: Program thinks of a number from 1-50 (user enters secret number). Player has max 7 guesses. For each wrong guess, give hint 'higher' or 'lower'. If guessed correctly or out of attempts, end game.

Ví dụ:

Secret number: 25
Guess: 30
Lower!
Guess: 20
Higher!
Guess: 25
Correct!

Output:

Lower!
Higher!
Correct! You won in 3 attempts.

Bài Tập 20: Số Palindrome (Palindrome Number)

Đề bài: Nhập một số nguyên dương. Kiểm tra số đó có phải số palindrome không (đọc xuôi ngược giống nhau).

Problem: Enter a positive integer. Check if it's a palindrome number (reads same forwards and backwards).

Ví dụ:

Enter number: 12321

Output:

Palindrome