Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import xlwt
- import sys
- ## {{{ http://code.activestate.com/recipes/577058/ (r2)
- def query_yes_no(question, default="yes"):
- """Ask a yes/no question via raw_input() and return their answer.
- "question" is a string that is presented to the user.
- "default" is the presumed answer if the user just hits <Enter>.
- It must be "yes" (the default), "no" or None (meaning
- an answer is required of the user).
- The "answer" return value is one of "yes" or "no".
- """
- valid = {"yes":"yes", "y":"yes", "ye":"yes",
- "no":"no", "n":"no"}
- if default == None:
- prompt = " [y/n] "
- elif default == "yes":
- prompt = " [Y/n] "
- elif default == "no":
- prompt = " [y/N] "
- else:
- raise ValueError("invalid default answer: '%s'" % default)
- while 1:
- sys.stdout.write(question + prompt)
- choice = raw_input().lower()
- if default is not None and choice == '':
- return default
- elif choice in valid.keys():
- return valid[choice]
- else:
- sys.stdout.write("Please respond with 'yes' or 'no' "\
- "(or 'y' or 'n').\n")
- ## end of http://code.activestate.com/recipes/577058/ }}}
- genotype = [0,0]
- homoDom=0;
- heteroDom=0;
- homoRec=0;
- dom=0;
- rec=0;
- bigtable=[]
- print "Genotype\t| Genotype name\t\t| Phenotype"
- print "====================================================="
- for x in range(0,100):
- genotype[0]=int(random.randrange(0,100)/50)
- genotype[1]=int(random.randrange(0,100)/50)
- if genotype[0] == 1:
- if genotype[1] == 1:
- print "RR \t\t| homozygous dominant\t| normal skin"
- bigtable.append(["RR", "homozygous dominant", "normal skin"])
- homoDom+=1
- else:
- print "Rr \t\t| heterozygous dominant\t| normal skin"
- bigtable.append(["Rr", "heterozygous dominant", "normal skin"])
- heteroDom+=1
- else:
- if genotype[1] == 1:
- print "rR\t\t| heterozygous dominant\t| normal skin"
- bigtable.append(["rR", "heterozygous dominant", "normal skin"])
- heteroDom+=1
- else:
- print "rr\t\t| homozygous recessive\t| albino"
- bigtable.append(["rr", "homozygous recessive", "normal skin"])
- homoRec+=1
- print "Statistics:"
- print "RR: "+str(homoDom)+"/100 Rr or rR: "+str(heteroDom)+"/100 rr: "+str(homoRec)+"/100."
- rec=homoRec
- dom=homoDom+heteroDom
- print str(dom)+"/100 were dominant. "+str(rec)+"/100 were recessive."
- print "Look over the results above. \n"
- resp=query_yes_no("Create an Excel worksheet? Press ENTER or y to create one, otherwise n to simply exit.")
- if resp == 'yes':
- print "============================================================="
- print "Creating Excel worksheet..."
- print "============================================================="
- wbk = xlwt.Workbook()
- sheet = wbk.add_sheet('Trait Lab Results')
- # Create a bold font to use
- boldstyle = xlwt.XFStyle()
- # Create a font to use with the style
- font = xlwt.Font()
- font.bold = True
- # Set the style's font to this new one you set up
- boldstyle.font = font
- # Create the header!
- # Starts at zero, goes by row,column
- sheet.write(0,0,'Genotype',boldstyle)
- sheet.write(0,1,'Genotype Name',boldstyle)
- sheet.write(0,2,'Phenotype',boldstyle)
- rowi=1
- # Import the data!
- for result in bigtable:
- sheet.write(rowi, 0, result[0])
- sheet.write(rowi, 1, result[1])
- sheet.write(rowi, 2, result[2])
- rowi+=1
- try:
- wbk.save('TraitLabGenotypesPhenotypesResults.xls')
- print "Done! The Excel spreadsheet is called TraitLabGenotypesPhenotypesResults.xls."
- except IOError:
- print "Error: Excel spreadsheet couldn't be created! :("
Advertisement
Add Comment
Please, Sign In to add comment