python将大于输出列表,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个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值