I've just begun my journey into python (1 week now) and I've written couple of lines incorporating everything I've learned so far. It would be greatly appreciated if anyone could guide me in writing a better formatted (appropriate style) version of this.
I've just written a couple of lines on finding two random rolls that stop when they roll the same number. When the same number is rolled, that number is recorded along with how many rolls it took to get there. I've also made the code to find those values and store them in a list, finding the average of roll number(same number) as well as roll count(How many rolls it took). Here is the code:
import random totalrolls = 0 rollList =  rollcountlist =  while totalrolls < 500: totalrolls = totalrolls + 1 rollcount = 0 roll = random.randint(1,100) rolltwo = random.randint(1,100) while roll != rolltwo: roll = random.randint(1,100) rolltwo = random.randint(1,100) #print roll #print rolltwo rollcount = rollcount + 1 if roll == rolltwo: rollList.append(roll) rollcountlist.append(rollcount) print "Random number that matched was: %s, after %s rolls. " % (roll, rollcount) if totalrolls == 500: print "Finished rolling %s times." % totalrolls averageroll = sum(rollList) / len(rollList) averagerollcount = sum(rollcountlist) / len(rollcountlist) print rollList print rollcountlist print averageroll print averagerollcount