Reputation: 29
Trying to get the code to output one of these responses...if the original house value is 200,000 and they give the exterior a '0' the house is now worth 190,000, etc...I also want to be able to "store" this new home value as they will be assessing other rooms on this virtual house tour, so that in the next room their score can add/subtract to the house value they gave it from the previous room and so on.
ans4=input("By the way, what value do you give to the exterior? 0,1,2,3?")
if ans4 in ['0']:
print("the house is now valued at " + ((number1)-10000))
if ans4 in ['1']:
print("the house is now valued at " + ((number1)-0))
if ans4 in ['2']:
print("the house is now valued at " + ((number1)+10000))
if ans4 in ['3']:
print("the house is now valued at " + ((number1)+20000))
Upvotes: 1
Views: 25
Reputation: 73
First of all, you have 3 opening "(" and two closing ")" near prints. This will not compile.
Another error is that you add string ("the house is now valued at") to an integer (number1). This is not allowed.
I am not sure, if I understand your question, but this is how I would have done it:
ans4=input("By the way, what value do you give to the exterior? 0,1,2,3?")
if ans4 in ['0']:
new_value = number1 - 10000
if ans4 in ['1']:
new_value = number1
if ans4 in ['2']:
new_value = number1 + 10000
if ans4 in ['3']:
new_value = number1 + 20000
print("the house is now valued at: ", new_value)
If you have python >= 3.6, you can use f-strings to make the printing with mixed format easier:
ans4=input("By the way, what value do you give to the exterior? 0,1,2,3?")
if ans4 in ['0']:
new_value = number1 - 10000
if ans4 in ['1']:
new_value = number1
if ans4 in ['2']:
new_value = number1 + 10000
if ans4 in ['3']:
new_value = number1 + 20000
print(f"the house is now valued at: {new_value}")
Upvotes: 1