from microbit import * # indentations in text are importantfrom microbit import * # need to remember to add random import import random display.clear() # chemistry - first 20 elements # randomly selects an element # shows the symbol, name, atomic number (AN) & atomic weight (AW) lookup = { "H": ["H", "Hydrogen", 1, 1], "He": ["He", "Helium", 2, 4], "Li": ["Li", "Lithium",3,7], "Be": ["Be", "Beryllium",4,9], "B": ["B", "Boron",5,11], "C": ["C", "Carbon",6,12], "N": ["N", "Nitrogen",7,14], "O": ["O", "Oxygen",8,16], "F": ["F", "Fluorine",9,19], "Ne": ["Ne", "Neon",10,20], "Na": ["Na", "Sodium",11,23], "Mg": ["Mg", "Magnesium",12,24], "Al": ["Al", "Aluminium",13,27], "Si": ["Si", "Silicon",14,28], "P": ["P", "Phosphorus",15,31], "S": ["S", "Sulphur",16,32], "Cl": ["Cl", "Chlorine",17,35], "Ar": ["Ar", "Argon",18,40], "K": ["K", "Potassium",19,39], "Ca": ["Ca", "Calcium",20,40], } # 1000 = 1 sec delay_1 = 300 delay_2 = 2000 while True: display.clear() # chose an element at random x = random.choice(list(lookup)) # then chose all the information associated with it info = lookup.get(x) # display symbol display.scroll(info[0], delay=150) sleep(delay_1) # display name (speed up scroll a bit) display.scroll(info[1], delay=120) sleep(delay_1) # display atomic number # (Note: change number into string using 'str') display.scroll("AN=" + str (info[2]), delay=150) sleep(delay_1) # display atomic weight / mass display.scroll("AM=" + str (info[3]), delay=150) # longer delay before next random element chosen sleep(delay_2)