Click here to Skip to main content
15,898,035 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 amino.py", line 27, in <module>
Sum_of_Weights=Molecular_Weight1(enter1,enter2,enter3,enter4,enter5)
+Molecular_Weight2(enter1,enter2,enter3,enter4,enter5)
+Molecular_Weight3(enter1,enter2,enter3,enter4,enter5)
+Molecular_Weight4(enter1,enter2,enter3,enter4,enter5)
+Molecular_Weight5(enter1,enter2,enter3,enter4,enter5)
File "C:/Users/Kenneth Sodjahin/OneDrive - EECD EDPE/Pictures/Python/molecular weight of an amino.py", line 2, in Molecular_Weight1
carbon=float(12.011*enter1)
TypeError: can't multiply sequence by non-int of type 'float'")

What I have tried:

def Molecular_Weight1(enter1,enter2,enter3,enter4,enter5):
    carbon=float(12.011*enter1)
    return carbon

def Molecular_Weight2(enter1,enter2,enter3,enter4,enter5):
    hydrogen=float(1.00794*enter2)
    return hydrogen

def Molecular_Weight3(enter1,enter2,enter3,enter4,enter5):
    nitrogen=float(14.00674*enter3)
    return nitrogen

def Molecular_Weight4(enter1,enter2,enter3,enter4,enter5):
    oxygen=float(15.9994*enter4)
    return oxygen

def Molecular_Weight5(enter1,enter2,enter3,enter4,enter5):
    sulfur=float(32.066*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:")

Sum_of_Weights=Molecular_Weight1(enter1,enter2,enter3,enter4,enter5)+Molecular_Weight2(enter1,enter2,enter3,enter4,enter5)+Molecular_Weight3(enter1,enter2,enter3,enter4,enter5)+Molecular_Weight4(enter1,enter2,enter3,enter4,enter5)+Molecular_Weight5(enter1,enter2,enter3,enter4,enter5)
print("The molecular weight of that Amino Acid is:",Sum_of_Molecular_Weights)

```
Posted
Updated 20-Oct-22 17:24pm
v2

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