-1

I am VERY new to coding. I seem to be stuck on the if/elif/else and the += operator. When I run my code it works partly. I don't get any errors, but it will not add in the Island and Heater in my code if both or one is "Y".

I made this up myself based off the practice that I had trouble with. I mimiced the solution to the practice problem but I am not getting the same results. Can someone please help me to see what I am doing wrong?

Size = int(input("What size camper do you want? Size in feet. \n"))
Island = input("Do you want and Island? y or n \n")
Heater = input("Do you want tankless water heater? y or n \n")

price = 0

if Size <= 30:
  price += 50000
elif Size <= 40:
  price += 60000
else:
  price += 80000

if Island == "Y or y":
  if Size <=30:
    price += 500
  else:
    price += 800

if Heater == "Y or y":
  if Size <=30:
    price += 1000
  else:
    price += 1500

print(f"Your total for a new camper will be ${price}!")

I tried changing the indents and I originally did not have the else options for the heater and the island.

  • 1
    `Island == "Y or y":` does not do what you think. – trincot Jan 01 '23 at 22:15
  • 1
    As a side note, its best to post fully contained examples when possible. Instead of us guessing about input, you could hard code values for `Size` and etc... – tdelaney Jan 01 '23 at 22:17

1 Answers1

1

The problem is that if Island == "Y or y": checks whether the input is literally the string "Y or y". Use if Island.lower() == "y": instead. Another option is if Island in ("Y", "y"):.

tdelaney
  • 73,364
  • 6
  • 83
  • 116
  • Thank you for that help. I haven't learned about that stuff yet, but it did fix the issue I was having. Fingers crossed I can figure this stuff out. – KawiGirl06 Jan 02 '23 at 11:50