In: Computer Science
Exercise 7: Name that Shape Write a program that determines the name of a shape from its number of sides. Read the number of sides from the user and then report the appropriate name as part of a meaningful message. Your program should support shapes with anywhere from 3 up to (and including) 10 sides. If a number of sides outside of this range is entered then your program should display an appropriate error message.
language use : python
1). ANSWER :
GIVENTHAT:
Python code:
#accepting number of sides
n=int(input("Enter the number of sides:"))
#checking if triangle
if(n==3):
#printing triangle
print("That’s a triangle")
#checking if quadrilateral
elif(n==4):
#printing quadrilateral
print("That’s a quadrilateral")
#checking if pentagon
elif(n==5):
#printing pentagon
print("That’s a pentagon")
#checking if hexagon
elif(n==6):
#printing hexagon
print("That’s a hexagon")
#checking if heptagon
elif(n==7):
#printing heptagon
print("That’s a heptagon")
#checking if octagon
elif(n==8):
#printing octagon
print("That’s a octagon")
#checking if nonagon
elif(n==9):
#printing nonagon
print("That’s a nonagon")
#checking if decagon
elif(n==10):
#printing decagon
print("That’s a decagon")
#Else it is an unsupported side
else:
#printing unsupported side
print("That number of sides is not supported by this program.")
Screenshot of code:
Output: