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'm trying to write a weight converter which splits the given input and act accordingly however if statement is completely ignored. So far my search revealed that it might be a scope problem but I'm pretty green so couldn't apply any solutions to my specific code.
def weight_convert(answer):
seperated = answer.split(" ")
unit = seperated[1]
weight = int(seperated[0])
if unit.lower == "lbs":
converted = weight * 0.45
else:
converted = weight % 0.45
return converted, unit
Try this:
def weight_convert(answer):
seperated = answer.split(" ")
unit = seperated[1]
weight = int(seperated[0])
if unit.lower() == "lbs":
converted = weight * 0.45
else:
converted = weight % 0.45
return converted, unit
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 20 days ago.
Improve this question
In the code sequence below, I have no problem for "int to float", but I have a problem for "float to int".
Am I missing something? Can you help me to understand?
age = 28
weight = 55.6
# int to float
result = float(age)
print(result)
#float to int
result = int(weight)
print(weight)
I was expecting an integer result, but the decimal value keeps returning.
enter image description here
Print the result instead of the weight
#float to int
result = int(weight)
print(result)
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
Check out the screenshot and help this newb with why i'm getting this syntax error with the for loop even though im following the right syntax.
The code :
elif choice == 'AVERAGE':
import statistics
lst = []
n = int(input('Enter number of values to calculate mean of: ')
for i in range(0,n):
ele=int(input())
lst.append(ele)
The Error : Invalid Syntax for the ':' after 'range(0,n)'
You are spacing the items inside the for loop with double Tab, the indentation should be either 4 spaces or a single tab.
And you are missing a parenthesis closing in the n input line
See the modified code below.
elif choice == 'AVERAGE':
import statistics
lst = []
n = int(input('Enter number of values to calculate mean of: '))
for i in range(0,n):
ele=int(input())
lst.append(ele)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
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.
Improve this question
def vector(sample_list):
for item in sample_list:
sums = 0
square = item**2
sums = square + sums
magnitude = sums**0.5
return magnitude
print(vector([2,3,-4]))
Why this code doesn't give the correct magnitude?
It gives the last value of the vector in function call.
change sums=0 position
def vector(sample_list):
sums = 0
for item in sample_list:
square = item**2
sums = square + sums
magnitude = sums**0.5
return magnitude
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 6 years ago.
Improve this question
I'm trying to write a program that calculates BMI by asking what one's weight (in kilograms) and height (in meters) is. Why am I getting an invalid syntax error here?
units = input("What units would you like to use? Enter I for Imperial or M for Metric")
weight = input(int("what's your weight?")
height = input(int("what's your height?")
enter image description here
You've picked the wrong order. You should be having int(input()) not the input(int())
And also you have less ) than you should be. Check that for every opening bracket there is a closing one
You have the wrong order of int and input and did forget the closing parenthesis:
units = input("What units would you like to use? Enter I for Imperial or M
for Metric")
weight = int(input("what's your weight?"))
height = int(input("what's your height?"))
Avoid using input() and use raw_input() instead. You also put int() in the wrong place.
Your code should look something like this:
units = raw_input('What units would you like to use?....')
weight = int(raw_input("what's your weight?"))
height = int(raw_input("what's your height?"))
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 trying to cube the number in this function, but Codecademy says it isn't returning the right result. Could anyone help?
def cube(number):
return number**number
def by_three(number):
if number % 3==0:
return cube(number)
else:
return False
Because it is not a cube. Cube is: number ** 3
Given your cube function, you are doing
n^n
for example, given n = 4, what you are really doing is 4*4*4*4
And it work only on 3 or it's multiple, given the line
if number % 3==0:
In case you are interested in one liner of this function check this out:
def by_three(number):
return number ** 3 if number % 3 == 0 else False
If you are interested in how this is done check ternary operator in python