from random import randint elements = ['Hydrogen', 'H'] + ['Helium', 'He'] + ['Lithium', 'Li'] + ['Boron', 'B'] \ + ['Carbon', 'C'] + ['Nitrogen', 'N'] + ['Oxygen', 'O'] + ['Florine', 'F'] + ['Neon', 'Ne'] \ + ['Sodium', 'Na'] + ['Magnesium', 'Mg'] + ['Aluminum', 'Al'] + ['Silicon', 'Si'] + ['Phosphorus', 'P'] \ + ['Sulfur', 'S'] + ['Chlorine', 'Cl'] + ['Potasium', 'K'] + ['Calcium', 'C'] + ['Chromium', 'Cr'] \ + ['Iron', 'Fe'] + ['Nickel', 'Ni'] + ['Copper', 'Cu'] + ['Zinc', 'Zn'] + ['Bromine', 'Br'] \ + ['Silver', 'Ag'] + ['Tin', 'Sn'] + ['Gold', 'Au'] + ['Mercury', 'Hg'] + ['Lead', 'Pb'] + ['Uranium', 'U'] while True: x = randint(0,60) y = 0 if x % 2 == 0: y = x + 1 z = raw_input("What is the name of the element with the symbol %s? " % elements[y]) else: y = x - 1 z = raw_input("What is the symbol for %s? " % elements[y]) p = elements[x] if z.lower() == p.lower(): print("You were correct!") else: print("No, it is %s") % elements[x]
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question