jeudi 29 juin 2017

If statement is false but code in it, still runs as well as all the code in the entire script in python - New to Python

This is code to find details about elements by asking the user about which element they want to learn about. The problem is when I run it it prints all of the print statements.

print ('Please type the element number or the name - no caps')
element = input('What element do you want to learn about?')


if element == ('1') or ('hydrogen'):
        print ('Hydrogen #1')
        print ('Gas')
        print ('Non-Metal')
        print ('Weight: 1.008')


if element == ('2') or ('helium'):
    print ('Helium #2')
    print ('Gas')
    print ('Non-Metal')
    print ('Weight: 4.0026')

if element == ('3') or ('lithium'):
    print ('Helium #3')
    print ('Solid')
    print ('Metal')
    print ('Weight: 6.94')

This is what happens when I run it.

Please type the element number or the name - no caps
What element do you want to learn about? 1
Hydrogen #1
Gas
Non-Metal
Weight: 1.008
Helium #2
Gas
Non-Metal
Weight: 4.0026
Helium #3
Solid
Metal
Weight: 6.94

Aucun commentaire:

Enregistrer un commentaire