-2

Code:

housePrice = input("What's the price of House? ")
is_goodCredit = input("Does buyer have good credit? ")

if is_goodCredit:
    downPayment = 0.1 * float(housePrice)
else:
    downPayment = 0.2 * float(housePrice)
    
print(f"Down payment will be {downPayment}")

The VS Code terminal:

PS C:\Users\bandh> & C:/Users/bandh/AppData/Local/Programs/Python/Python311/python.exe c:/Users/bandh/Desktop/Untitled-1.py
What's the price of House? 1000
Does buyer have good credit? true
Down payment will be 100.0
PS C:\Users\bandh> & C:/Users/bandh/AppData/Local/Programs/Python/Python311/python.exe c:/Users/bandh/Desktop/Untitled-1.py
What's the price of House? 1000
Does buyer have good credit? false
Down payment will be 100.0

As you can see when entering "false" the answer should have been 200 but it is showing 100. Why?

wovano
  • 4,543
  • 5
  • 22
  • 49

1 Answers1

2
is_goodCredit = input("Does buyer have good credit? ")

is_goodCredit returns a string. A string, as a condition, is seen as True if the string is not empty. Entering 'false', is seen as True. What you would want to check is whether the string matches 'false', such that:

if is_goodCredit == 'false':
Lexpj
  • 921
  • 2
  • 6
  • 15