Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Functions example
- # by Colin
- # Houses - Sopley, Ibsley, Hurn, Holmsley, Beaulieu
- """
- The function count_points() counts how many points have been earned by pupils in College. The name of the house is passed as a string parameter and the number of points earned is returned as an integer
- Write code using the function count_points() to find the number of points awarded to pupils in Hurn and assign this value to a variable with identifier hurn_points
- """
- """
- def function_name(parameter):
- #do stuff with the parameter
- return
- def double(anumber):
- return anumber*2
- print(double(5))
- """
- # Functions example
- # by Colin
- # Houses - Sopley, Ibsley, Hurn, Holmsley, Beaulieu
- """
- # Here we go!
- import random
- houses = ["Sopley", "Ibsley", "Hurn", "Holmsley", "Beaulieu"]
- points_awarded =[] # empty list
- for i in range(100):
- points_awarded.append(random.choice(houses))
- def count_points(house):
- points_count = points_awarded.count(house)
- return points_count
- hurn_points = count_points("Sopley")
- print (hurn_points)
- """
- Exam only needs this line
- hurn_points = count_points("Hurn")
- """
- """
- Looking for a bit more fun?
- Can you change the function to print out a count of all the houses and points?
- Output to look like this
- Hurn 20
- Sopley 20
- Ibsley 20
- Holmsley 20
- Beaulieu 20
- Total 100
- """
- Feedback please to Mr Benson or me!
- """
- # my first stab at the extension
- def count_points(house):
- if house == "All":
- print ("Hurn ", points_awarded.count("Hurn"))
- print ("Ibsley ", points_awarded.count("Ibsley"))
- print ("Beaulieu ", points_awarded.count("Beaulieu"))
- print ("Sopley ", points_awarded.count("Sopley"))
- print ("Holmsley ", points_awarded.count("Holmsley"))
- print ("Total ",len(points_awarded))
- else:
- points_count = points_awarded.count(house)
- return points_count
- hurn_points = count_points("All")
- Please talk to me if you have a go at this, I think there are some things wrong, but the gist is there!
- Colin
Add Comment
Please, Sign In to add comment