Search code examples
pythonpython-3.xoperators

Can anyone explain how to solve this problem


A program that reads 3 numbers A, B and C and checks if each 3 numbers are greater than or equal to 20. Output should be single line containing a boolean. True should be printed if each number is greater than or equal to 20, Otherwise False should be printed.

I have tried using "and" operator and got result. Are there any other ways to solve this problem.

A=int(input())
B=int(input())
C=int(input())

a= A>=20
b= B>=20
c= C>=20

abc= a and b and c

print(abc)

Solution

  • You can use the all function with a generator expression that iterates over a range of 3 to test if each input value is greater than or equal to 20:

    print(all(int(input()) >= 20 for _ in range(3)))