Note: This isn't as much a golfing challenge; it is more so asking for golfing suggestions.
Recently I had a Python assignment for my web development class, in order to check whether we could code. Since I already feel comfortable in Python, I decided to try and golf it, and I was wondering if people could point out things that I missed.
I already know that there are extra spaces in some places, but I'm more interested in conceptual things, like using
while r: when r is a variable, and then waiting for it to "run out"!
import random from collections import Counter s=l='' c=['yellow','blue','white','green','Black', 'purple', 'silver', 'cyan', 'magenta', 'red'] n=[10,15,1,10,6,15,10,25,1,12,5,10,4,6,5,12,0,10,1,1] o=i=0 for y in c:l+=y*(random.randint(n[o],n[o+1]));o+=2 l=list(l) print("Welcome to the CIMS Gumball Machine Simulator\nYou are starting with the following gumballs:") for b in c:print(str(l.count(b)) + " "+b);random.shuffle(l) print("Here are your random purchases:") while 'r' in l: random.shuffle(l); r=l.pop(); s+=r for j in c: if j == r:print(j.capitalize()) print("You purchased %i gumballs, for a total of $%.2f \nMost common gumball(s):" % (len(s),len(s)*25/100)) a=Counter(s).most_common() m=[x for x in a] while m == m[i]: for j in c: if j == a[i]:print(j.capitalize(), end=" ") if(i<(len(m)-1)):i+=1 else:break
Also: I'm sorry if this isn't an appropriate question for the code golf page, since it is not a challenge and will remove it on request.