Area-calculator: elif-syntax error and option.upper()


#1

Hello. I have three problems regarding the Area-Calculator project. And I've read previous topics about This problem on the forum, without result. My three problems are:
1: programs says there is a syntax-error regarding the elif-statement. I've tried to write it in different ways, without result. I've used a second if instead of elif, which makes it impossible to calculate area of triangle, because the letter T isn't recognized.
2: Nothing but C is recognized as a valid input from user.
3: Only uppercase letters are recognized, even if .upper() is used. (I should be able to write c or t and still get valid input).

Please have A look at my code, and give feedback about how to solve the problems I have.
Best regards, AnarkoBat


"""This will be a simple program that calculates the area of a triangle, or a circle, depending on the user."""

from math import pi
from time import sleep
from datetime import datetime
now = datetime.now()

print "The calculator is now booting.."

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

sleep(1)

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

option = raw_input("Enter C for Circle and T for Triangle: ")
option = option.upper()

if option == 'C':
    radius = float(raw_input("What is the radius?: "))
    area = pi * (radius**2)
    print "The pie is baking.."
    sleep(1)
    print ("Area: %.2f. \n%s " % (area, hint))

    elif option == 'T':
        base = float(raw_input("Please enter base of triangle: "))
        height = float(raw_input=("What is the height of the triangle?:"))
        area = 0.5*base * height
        print "Uni Bi Tri..."
        sleep(1)

        print ("The Area is: %s " % (area, hint))

else:
    print "Your entered garbage. program will exit."


#2

1) How can elif be used? Argue for why your use would be correct. Can you find a description of how to use elif which supports your argument? What if you use a minimal version of the problem to figure out how elif is used?
2) What would make you compare to other things?
3) Then your normalisation must have failed, or letter case wouldn't make a difference. I would claim that you are immediately converting it to upper case though, so perhaps something is wrong about that observation. Perhaps it's happening in another location where you forgot to normalise (If you aren't storing the un-normalised input, then it's not going to have an effect)


#3

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