Quiz on the metric prefixs, symbols, and decimals associated with each other.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | import random
def delete(L,n):
"""returns a list L with value of n deleted"""
new = []
for x in L:
new.append(x)
new.remove(n)
return new
symbol = ["p","n","mu","m","c","d","da","h","k","M","G","T"]
value = [".000000000001",".000000001",".000001",".001",".01",".1","10","100","1000","1000000","1000000000","1000000000000"]
prefix = ["pico","nano","micro","milli","centi","deci","deca","hecto","kilo","mega","giga","tera"]
#12 elements each
print"Please use quotations when entering answers!!!\n"
try:
while(True):#main loop
secList = [symbol,value,prefix]
section = random.choice(secList)
element = random.choice(range(len(symbol)))
otherTwo = delete(secList,section)
print "__"+section[element]+"__"
if(section == symbol):
print "Value:"
elif(section == value):
print "Symbol:"
else:
print "Symbol:"
ansOne = input()
if(str(ansOne) != otherTwo[0][element]):
print "Right Answer is "+otherTwo[0][element]
if(section == symbol):
print "Prefix:"
elif(section == value):
print "Prefix:"
else:
print "Value:"
ansTwo = input()
if(str(ansTwo) != otherTwo[1][element]):
print "Right Answer is "+otherTwo[1][element]+"\n"
else:
print "\n"
del(symbol[element])
del(value[element])
del(prefix[element])
except(IndexError):
print "Quiz Finished!!\n"
|
http://en.wikipedia.org/wiki/SI_prefix#List_of_SI_prefixes
Was challenging(fun) to code and strung together concepts of randomization, lists, logic(no repeats) and functions. Using dictionaries could of made this easier, had I known how to string together 3 values instead of the regular 2.
Improvements: -Calculating score -Making it so that users do not have to type in quotations for everything.
Use raw_input() instead.
A variant for delete(L,n):
but you could avoid it completely by using
(and replacing otherTwo by secList afterwards).
Also, instead of globally catching the IndexError, replace the infinite loop with: