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))
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 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))
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
I have to write a function recursively to convert a given decimal string ad return a binary. I can't change the first 3 lines of the function(n = Len(a) ... return str(bin(int(a)))) and I don't understand why my solution doesn't work. Does anyone have any suggestions?
{str} -> {str}
def converttobin(a: str) -> str:
n = len(a)
if n == 1:
return str(bin(int(a)))
else:
return converttobin(str(int(a) % 2)) + str(int(a) % 2)
Instead of sending the remainder, send the quotient str((int)a//2) to the function call.
For decimal to binary conversion, we take remainders as the current output and further apply the conversion on the quotient.
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
I am trying to find the percentage of questions right but my percentage code is returning (100, 1) but I want it to return 100. My code is
accuracy = 100 # Setting a default.
def percentage(part, whole):
return(round((part/whole)*100),1)
and the code to print is
accuracy = percentage(questionsright, questionscompleted)
print("Your accuracy is now " + str(accuracy) + "% .")
Does anybody know why it isn't returning 100? Please Help.
You have parenthesis in the wrong places in this function:
def percentage(part, whole):
return(round((part/whole)*100),1)
Without the change, your function was returning an ordered tuple of two elements where the first element is round((part/whole)*100) and the second is 1.
Here is the corrected function:
def percentage(part, whole):
return round((part/whole)*100,1)
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
I'm sorry; it seems that this error is pretty common, yet I can't see how I may have had done an indentation error, there's no tabs, only spaces..
def impots(revenus):
imp=0
if revenus < 9690:
return(imp)
elif revenus < 26764:
return ((0.14*(revenus-9690))
elif revenus < 71754:
return (0.30*(revenus-26764)+2390,36)
else :
return (°)
could you help me ? Thanks and sorry again
You were missing a ")" after revenus-9690.
def impots(revenus):
imp=0
if revenus < 9690:
return(imp)
elif revenus < 26764:
return ((0.14*(revenus-9690)))
elif revenus < 71754:
return (0.30*(revenus-26764)+2390,36)
else :
return (°)