Write a program that reads the first capital letter ("T", "C", "O", "D" or "I") of the polyhedron the size of a side and which prints the volume of the corresponding polyhedron. If the letter read is not one of the 5 letters, your program prints "Unknown Polyhedron".
This prints almost every input value as the value of "else statement" but it should print the volume of the polyhedron based on the letter that user inputs and also the measure of the side.
import math
p = str(input())
a = float(input())
T = (math.sqrt(2) / 12) * (a ** 3)
C = a ** 3
O = (math.sqrt(2) / 3) * (a ** 3)
D = (15 + 7 * math.sqrt(5)) / 4 * (a ** 3)
I = 5 * (3 + math.sqrt(5)) / 12 * (a ** 3)
if p == (math.sqrt(2) / 12) * (a ** 3) :
print (T)
elif p == a ** 3 :
print(C)
elif p == (math.sqrt(2) / 3) * (a ** 3) :
print(O)
elif p == (15 + 7 * math.sqrt(5)) / 4 * (a ** 3) :
print(D)
elif p == 5 * (3 + math.sqrt(5)) / 12 * (a ** 3) :
print(I)
else :
print('Polyèdre non connu')
Here is a corrected working version of what you want
import math
p = input("Enter type of polyhedral: ")
a = float(input("Enter the value of a: "))
if p == 'T':
volume =(math.sqrt(2) / 12) * (a ** 3)
elif p == 'C':
volume = a**3
elif p == 'O':
volume = (math.sqrt(2) / 3) * (a ** 3)
elif p == 'D':
volume = (15 + 7 * math.sqrt(5)) / 4 * (a ** 3)
elif p == 'I':
volume = 5 * (3 + math.sqrt(5)) / 12 * (a ** 3)
else:
print('Polyèdre non connu')
volume = "Not Yet Defined"
print ("The volume of p=%s is %s" %(p, volume))
Sample output
Enter type of polyhedral: O
Enter the value of a: 12.45
The volume of p=O is 909.71
Enter type of polyhedral: K
Enter the value of a: 12
Polyèdre non connu
The volume of p=K is Not Yet Defined