I was creating an if-else loop based on the type of variable, to either convert a list of numbers to kilograms, or simply one number, and for some reason I cannot call the variable I created into my main() function. I am a beginner to python and any help would be appreciated. Here is my code:
# Testing Code
def kgToLb(weight):
# Return the converted weight (kg)
newWeight = []
if type(weight) == list:
for w in range(len(weight)):
return newWeight.append(weight[w] * 2.20462)
return newWeight == weight * 2.20462
def main():
weightList = [-22, 11, 0, 8.2, -8.2]
answerKgsList = [-9.979044, 4.989522, 0, 3.71946186, -3.71946186]
# Test data
for w in range(0, len(weightList)):
kgToLb(weightList)
correctWeight = weightList == answerKgsList[w]
print(correctWeight)
print(newWeight)
print("The converted weight is " + str(newWeight[w]) + ". " + str(correctWeight))
main()
I tried to change the if-else format to see if it would change anything to no avail.