Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Multiplying two elements in a list

How can I multiply two elements in a list?
I am reading a text file, and printing the following:

for i in range(len(listeisotoper)):
    print("Isotop type:"+listeisotoper[i][0])
    print("Isotopisk masse u: "+listeisotoper[i][1])
    print("Naturlig forekomst: "+listeisotoper[i][2])
    print("xxx"+"g/mol")
    print("\n")

However i cannot fathom how i can multiply the listeisotoper[i][1] * listeisotoper[i][2]
and then have it print the number with decimal points.
Any suggestions?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It isn’t clear question for me, but may be this code will help you

for i in range(len(listeisotoper)):
    print("Isotop type:"+listeisotoper[i][0])
    print("Isotopisk masse u: "+listeisotoper[i][1])
    print("Naturlig forekomst: "+listeisotoper[i][2])
    mult_res = float(listeisotoper[i][1]) * float(listeisotoper[i][2]) 
    print(f"Mult = {mult_res:.1f}")
    print("xxx"+"g/mol")
    print("\n")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading