def score(a, b, c): """ Returns the score given the amounts of each of the symbols. Doesn't care which is which. """ return min(a, b, c) * 7 + a ** 2 + b ** 2 + c ** 2 print "Welcome to the Science Points Calculator!" # we don't care which symbol is which, so we just need three variables. # easiest way to do that is with a List type, declared like this: scores = [0, 0, 0] # now the three variables can be referred to with scores[0], scores[1] and scores[2] # let's call int() right on the input so it's stuffed away as an int. scores[0] = int(input("How many cogs do you have?")) scores[1] = int(input("How many tablets do you have?")) scores[2] = int(input("How many compasses do you have?")) wild = int(input("How many wild symbols do you have?")) # we're not going to give the responsibility of assigning wild symbols to the score() function. # we're going to do it ourselves. # we want them sorted from lowest to highest so we can always identify the lowest value and highest value. # every List is actually an *object* and you can call methods on the object like this: object.method(). # in this case the object is called 'scores' (our List) and the method is 'sort'. scores.sort() while wild > 0: # let's see what scores higher: adding it to the lowest number, or adding it to the highest number. if score(scores[0] + 1, scores[1], scores[2]) > score(scores[0], scores[1], scores[2] + 1): scores[0] += 1 else: scores[2] += 1 # we may have to re-sort because we may have gone from 3, 3, 3 to 4, 3, 3. scores.sort() # decrement the number of wild symbols left to apply. wild -= 1 # we need to pass the individual scores into our score function. print "Congratulations! Your science score is a whopping " + str(score(scores[0], scores[1], scores[2])) + " points!"
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question