Reputation: 882
I'm trying to solve a very basic problem from URI online judge in Python 3, I have solved the problem and run on IDE it's showing output as expected but while I'm submitting it's showing RunTime Error
The Problem:
Make a program that reads three floating point values: A, B and C. Then, calculate and show:
a) the area of the rectangled triangle that has base A and height C.
b) the area of the radius's circle C. (pi = 3.14159)
c) the area of the trapezium which has A and B by base, and C by height.
d) the area of the square that has side B.
e) the area of the rectangle that has sides A and B.
Input
The input file contains three double values with one digit after the decimal point.
Output
The output file must contain 5 lines of data. Each line corresponds to one of the areas described above, always with a corresponding message (in Portuguese) and one space between the two points and the value. The value calculated must be presented with 3 digits after the decimal point.
My Solution
value_of_a = float(input())
value_of_b = float(input())
value_of_c = float(input())
pi = 3.14159
area_of_the_rectangle_triangle = 0.5 * value_of_a * value_of_c
area_of_the_radius_circle = pi * value_of_c * value_of_c
area_of_the_trapezium = 0.5 * (value_of_a + value_of_b) * value_of_c
area_of_the_square = value_of_b * value_of_b
area_of_the_rectangle = value_of_a * value_of_b
print("TRIANGULO: %.3f" % area_of_the_rectangle_triangle)
print("CIRCULO: %.3f" % area_of_the_radius_circle)
print("TRAPEZIO: %.3f" % area_of_the_trapezium)
print("QUADRADO: %.3f" % area_of_the_square)
print("RETANGULO: %.3f" % area_of_the_rectangle)
Can any one please tell me where I have made the mistake!
Upvotes: 0
Views: 1984
Reputation: 1
You can use input().split() to split multiples variables that were given on a sigle input line.
#input 10 a 30
VarA, VarB, VarC = input().split()
#resulting on
#VarA = '10'
#VarB = 'a'
#VarC = '30'
Upvotes: 0
Reputation: 811
try
inputs = [float(input()) for i in range(3)]
value_of_a = inputs[0]
value_of_b = inputs[1]
value_of_c = inputs[2]
or
inputs = input()
inputs = [float(value) for value in inputs.split(' ')]
value_of_a = inputs[0]
value_of_b = inputs[1]
value_of_c = inputs[2]
Syntax for output
print("{0} {1} {2} {3} {4} ".format(area_of_the_rectangle_triangle,area_of_the_radius_circle,area_of_the_trapezium,area_of_the_square,area_of_the_rectangle))
Upvotes: 1