Python, Area Calculator


#1



Hi, I'm stuck with Area Calculator in Python. When the program runs and asks me to type "C" or "T", I type "c" in order to check whether my .upper function works, but it keeps telling me "NameError: name "c" is not defined". But I'm not supposed to define lowercase "c" because it must automatically be changed to uppercase. What's wrong? Thank you!


Replace this line with your code. 
"""Python is especially useful for doing math and can be used to automate many calculations. In this project, you'll create a calculator than can compute the area of a given shape, as selected by the user. The calculator will be able to determine the area of the following shapes:

Circle
Triangle
The program should do the following:

Prompt the user to select a shape
Depending on the shape the user selects, calculate the area of that shape
Print the area of that shape to the user"""

from math import pi
from time import sleep
from datetime import datetime

now = datetime.now()
#Shows current time

print ("The program is running")

print ("Current time: %s/%s/%s %s:%s" % (now.month, now.day, now.year, now.hour, now.minute))

sleep(1)
#Sleeps the program for 1 sec

hint = "Don't forget to include the correct units! \nExiting..."

option = input("Enter C for Circle or T for Triangle: ")
option = option.upper()
#Changes lowercase to uppercase

if option == "C":
  radius = float(input("Enter the radius: "))
  area = pi * radius ** 2
  print ("The pie is baking...")
  sleep(1)
  print ("%.2f" % (area) + "\n%s" % (hint))
  #Prints the area and hint

elif option == "T":
  base = float(input("Enter the base: "))
  height = float(input("Enter the height: "))
  area = (base * height) / 2
  print ("Uni Bi Tri...")
  sleep(1)
  print ("Area: %.2f" % (area) /nhint)
  #Prints the area and hint
  
else:
  print ("You entered garbage, I'm quitting!")


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.