459,720 views
9 votes
9 votes
Write a program that accepts the lengths of three sides of a triangle as an input from the user: A, B, C

Validate the user input so that the user can only enter positive values for sides A, B, C. All three must be true:

A > 0
B > 0
C > 0

User Hbak
by
2.4k points

1 Answer

11 votes
11 votes

Answer:

The program in Python is as follows:

A = int(input("A: "))

B = int(input("B: "))

C = int(input("C: "))

while A<=0 or B <= 0 or C <= 0:

A = int(input("A: "))

B = int(input("B: "))

C = int(input("C: "))

print("Valid inputs")

Step-by-step explanation:

Get input for A, B and C

A = int(input("A: "))

B = int(input("B: "))

C = int(input("C: "))

The loop is repeated until inputs for A, B and C are above 0

while A<=0 or B <= 0 or C <= 0:

Get input for A, B and C

A = int(input("A: "))

B = int(input("B: "))

C = int(input("C: "))

Print valid inputs when user inputs are correct

print("Valid inputs")

User Adek
by
3.2k points