Cho list và giá trị kiểm tra, hiển thị tất cả giá trị trong list lớn hơn giá trị cho trước.
Ví dụ
Input: A=[10, 20, 30, 40, 50] Given value=20 Output: No Input: A=[10, 20, 30, 40, 50] Given value=5 Output: Yes
Thuật toán
Bước 1: Tạo list nhập từ người dùng. Bước 2: Nhập giá trị kiểm tra. Bước 3: Duyệt list dùng for loop. Bước 3.1: So sánh tất cả giá trị với giá trị kiểm tra. Bước 4: Dừng.
Ví dụ mã
def checknumber(A, val):
# Duyệt list
for i in A:
if val >= i:
return False
return True
# Driver code
A = list()
n1 = int(input("Enter the size of the List ::"))
print("Enter the Element of List ::")
for i in range(int(n1)):
k = int(input(""))
A.append(k)
val = int(input("Enter the checking value"))
if checknumber(A, val):
print("All the values are greater than ", val)
else:
print("Values are not greater than ", val)
Kết quả
Enter the size of the List ::5 Enter the Element of List :: 10 20 30 40 50 Enter the checking value 10 Values are not greater than 10 Enter the size of the List ::6 Enter the Element of List :: 10 20 30 40 50 60 Enter the checking value 9 All the values are greater than 9