Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 10 months ago.
Improve this question
I am trying to create a program where the user is asked to input their credit score and based upon if it is less than or = to 650, they will have to put either 10% or 20% downpayment on the house. The problem I'm having is when running my code instead of printing the downpayment amount it just prints the decimal "0.1" or "0.2" multiple times as shown below. I've included my simple program below.
credit_score = float(input("What is your credit score? "))
house_price = 1000000
if credit_score <= 650:
print('down_payement = ' + str(0.2) * house_price)
else:
print('down_payement = ' + str(0.1) * house_price)
Convert to string after multiplication:
credit_score = float(input("What is your credit score? "))
house_price = 1000000
if credit_score <= 650:
print('down_payement = ' + str(0.2 * house_price))
else:
print('down_payement = ' + str(0.1 * house_price))
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last year.
Improve this question
May I know why there be a invalid syntax on my f variable on the first elif loop?
def bsd():
if price_of_properties <= 180000:
price = 180000*0.1
f = '{0:.2f}'.format(price)
print("BSD is $" + str(f))
elif price_of_properties > 180000 <= 360000:
price = (((180000*0.1) + (price_of_properties - 180000 + (180000* 0.2)))
f = '{0:.2f}'.format(price)
print("BSD is $" + str(f))
elif price_of_properties > 360000 <= 100000:
price = (((180000*0.1) + (180000*0.2) +(price_of_properties - 180000 + (640000* 0.3)))
f = '{0:.2f}'.format(price)
print("BSD is $" + str(f))
Your second and third assignments to the price variable have unbalaned parentheses ((more opens than closes).
This will cause an error on the following lines though I think Python 3.11 may fix that, reporting errors more accurately. You can probably fix this by adding a closing parenthesis on each of those two lines. Or removing the first. But check the formulae after you do so, in case you make the wrong choice.
And, yes, the extra opening parenthesis in that first paragraph was intended :-)
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
def blood_pressure(systolic, diastolic):
mean_pressure = (systolic + (2 * diastolic)) / 3
risk = float(1.0)
risk_return = round((risk * mean_pressure), 2)
if diastolic < 80:
if systolic < 120:
return(risk_return)
else:
risk += 0.1
return(risk_return)
return
print(blood_pressure(121,75))
when I run this code, it outputs the number as if it went though the first conditional if systolic < 120, instead of the else conditional. I need it to add the 0.1 to the original risk but its not going through properly. Sorry this is really basic I am just getting into coding. What is going wrong?
I think you calculate risk_return too early:
def blood_pressure(systolic, diastolic):
mean_pressure = (systolic + (2 * diastolic)) / 3
risk = 1.0
if diastolic < 80 and systolic >= 120:
risk += 0.1
return round((risk * mean_pressure), 2)
print(blood_pressure(121,75))
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
Here is the code
wagesAmount = float(input("Enter Wages Amount: "))
numberOfHours = float(input("Enter Number Of Hours Worked: "))
totalWagesAmount = (wagesAmount) * (numberOfHours)
if totalWagesAmount > "0":
printtotalWagesAmount
I need to add an else statement as well but I was just trying to troubleshoot this issue first
"0" means it's a string . so when u wanna do if something > 0: thats means that 0 is integer and you say (if somthing > "0" string. so you
wagesAmount = float(input("Enter Wages Amount: "))
numberOfHours = float(input("Enter Number Of Hours Worked: "))
totalWagesAmount = (wagesAmount) * (numberOfHours)
if totalWagesAmount > 0:
print (totalWagesAmount)
You have to remove the "" on 0 because "0" != 0
if totalWagesAmount > 0:
Writing "0" means its string because of dynamic typing in python.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
The question asks to write a program that approximates pi using the forumla pi = 4/1 - 4/3 + 4/5 - 4/7 + .....
I have to prompt the user for the number of terms in the series, and the calculate the approximation. This is the program I tried
import math
def main():
dummy = 4.0
term = 0.0
n = 0.0
print("This program approximates the value of pi")
n = eval(input("Enter the number of terms you want in the approximation: ")
for i in range(1, n+1)
term = 4/(2n+1)
dummy = dummy + ((-1)**n) * term
print("The approximation is ", dummy)
print("The difference between pi and the approximation is ", math.sqrt((math.pi - dummy)**2))
However, when I try to run it I get the error message "Invalid syntax" and the variable "term" is highlighted in red.
Missing operator * here:
term = 4/(2n+1)
change to
term = 4/(2*n+1)
You forgot the colon at the end of this line:
for i in range(1, n+1):
^ missing
Whenever you get a syntax error on a line that looks correct, try looking at the line before the error to see if that's correct.
You also forgot the ) at the end of this line:
n = eval(input("Enter the number of terms you want in the approximation: ")
You miss ":" at the end of the for statement:
for i in range(1, n+1):
term = 4/(2*n+1)
dummy = dummy + ((-1)**n) * term
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
So I'm trying to program something and there's something odd going on, when trying to run my code I get a syntaxerror on line 3 but when I run only that specific line of code everything works perfectly. How is this even possible? It's written in python if that matters
p = float(input("What is the initial investment? "))
r = float(input("What is the nominal interest rate as a decimal? ")
n = float(input("How many times a year will the interest be compounded? "))
t = float(input("How many years will the interest be compounded"))
a = p * (1 + r / n) ** (n*t)
print "The final amount after %f years is %f" %t %a
Try this, (missed brackets in 2nd line).
r = float(input("What is the nominal interest rate as a decimal? "))
You are missing a closing bracket on line 2. Correct that, and the error should go away.
#Instead of
r = float(input("What is the nominal interest rate as a decimal? ")
#Do this
r = float(input("What is the nominal interest rate as a decimal? "))
#This guy is missing - - - - - - - - - - - - - - - - - - - - - - - - ^