Click here to Skip to main content
15,749,203 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
It keeps showing this("Traceback (most recent call last):
File "C:/Users/Kenneth Sodjahin/OneDrive - EECD EDPE/Pictures/Python/molecular weight of an", line 27, in <module>
File "C:/Users/Kenneth Sodjahin/OneDrive - EECD EDPE/Pictures/Python/molecular weight of an", line 2, in Molecular_Weight1
TypeError: can't multiply sequence by non-int of type 'float'")

What I have tried:

def Molecular_Weight1(enter1,enter2,enter3,enter4,enter5):
    return carbon

def Molecular_Weight2(enter1,enter2,enter3,enter4,enter5):
    return hydrogen

def Molecular_Weight3(enter1,enter2,enter3,enter4,enter5):
    return nitrogen

def Molecular_Weight4(enter1,enter2,enter3,enter4,enter5):
    return oxygen

def Molecular_Weight5(enter1,enter2,enter3,enter4,enter5):
    return sulfur

enter1=input("Enter the number of Carbon:")
enter2=input("Enter the number of Hydrogen:")
enter3=input("Enter the number of Nitrogen:")
enter4=input("Enter the number of Oxygen:")
enter5=input("Enter the number of Sulfur:")

print("The molecular weight of that Amino Acid is:",Sum_of_Molecular_Weights)

Updated 20-Oct-22 17:24pm

1 solution

So little code and so much wrong.

Why on earth are you passing all 5 entered values to every Molecular_Weight# function when each one only ever uses a single value?

Also, your Molecular_Weights functions should be named for what they are calculating, each only taking a single argument, not 5 of them. This is a problem when you're passing 5 values to each function when you should be passing only 1.

All of your "enter#" variables should be renamed to what value they are holding, not "enter". They will also be holding strings, not calculable values. There is a huge difference between 123 and "123", and you're passing in the latter.

You're assigning the calculated total to a variable called "Sum_of_Weights", but never use that variable name again in your code.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900