Python程序检查列表中的所有值是否都大于给定值
给定列表并给出检查值,显示列表中大于给定值的所有值。
示例
Input : A=[10, 20, 30, 40, 50] Given value=20 Output : No Input : A=[10, 20, 30, 40, 50] Given value=5 Output : Yes
算法
Step 1: Create user input list. Step 2: Input checking value. Step 3: Traverse in the list using for loop Step 3.1: compare with all the values with checking value. Step 4: Stop
范例程式码
def checknumber(A, val):
# traverse in the 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)输出结果
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
热门推荐
10 朋友新年祝福语大全 简短
11 新年祝福语简短大方兔年
12 搬新家礼物祝福语简短
13 同学见面花束祝福语简短
14 五一假期祝福语幽默简短
15 离职欢送敬酒祝福语简短
16 对学弟的祝福语简短
17 考老师辞职祝福语简短
18 祝福语驱散霉运的话简短