lundi 18 mars 2019

How to use input words as integers

So I am trying to set up a way that someone could enter in how they want a sign with the following rules.

The charge for all signs is a minimum of $35.00.

The first five letters or numbers are included in the minimum charge; there is a $4 charge for each additional character.

If the sign is make of oak, add $20.00. No charge is added for pine.

Black or white characters are included in the minimum charge; there is an additional $15 charge for gold-leaf lettering.

So if someone were to get 8 characters with an oak sign and gold lettering the total should be $82 however my code seems to only process the first if statement I put up making it only $47 and the only way I can fix this is if I change the color words into using numbers rather than the actual words. I was wondering if there was a way to still use the words instead of replacing them with numbers

Code that fails with the words:

# Declare and initialize variables here.

Charge = 35.00 
Black = 0.00
White = 0.00
Gold = 15.00
Pine = 0.00
Oak = 20.00
Characters = 0.00
Color = 0.00
Wood = 0.00

numChars = int(input("How many characters would you like on your sign? :"))

color = input("What color would you like your words on your sign to be? Black, White, or Gold :")

woodType = input("What type of wood would you like your sign to be? Pine or Oak :")


# Write assignment and if statements here as appropriate.
if numChars > 5:
    Characters = (numChars - 5) * 4.00 
    if color == Gold:
        Color = 15.00
        if woodType == Oak:
            Wood = 20.00

print("The charge for this sign is $" + str(Charge + Characters + Color + Wood))

Code that works using numbers instead of words:

    # Declare and initialize variables here.

Charge = 35.00 
Black = 0.00
White = 0.00
Gold = 15.00
Pine = 0.00
Oak = 20.00
Characters = 0.00
Color = 0.00
Wood = 0.00

numChars = int(input("How many characters would you like on your sign? :"))

color = int(input("What color would you like your words on your sign to be? Black(1), White(2), or Gold(3) :"))

woodType = int(input("What type of wood would you like your sign to be? Pine(1) or Oak(2) :"))


# Write assignment and if statements here as appropriate.
if numChars > 5:
    Characters = (numChars - 5) * 4.00 
    if color == 3:
        Color = 15.00
        if woodType == 2:
            Wood = 20.00

print("The charge for this sign is $" + str(Charge + Characters + Color + Wood))

Aucun commentaire:

Enregistrer un commentaire