Laxman Donthula
Laxman Donthula

Reputation: 13

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)

Upvotes: 1

Views: 82

Answers (4)

Talha Tayyab
Talha Tayyab

Reputation: 27810

What about :

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

sum((a, b, c))==3

Upvotes: 0

0x0fba
0x0fba

Reputation: 1620

Take the lowest thanks to the min() function.

If the lowest value is >= 20 then you're sure that all the values are >= 20.

A = 21
B = 22
C = 19

min(A,B,C) >= 20  # False

Upvotes: 1

Vin
Vin

Reputation: 1037

This is another way:

abc = all(a, b, c)

Upvotes: 2

blhsing
blhsing

Reputation: 107075

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)))

Upvotes: 3

Related Questions