Challenges 4
Challenges 4
4a). A candidate voting system allows people to enter A,B or C. This loops until they enter a Q for quit. The system should the print out the totals of each of the candidates.
Low: Output totals as follows:
Candidate A: 24 votes
Candidate B: 12 votes
Candidate C: 18 votes
Med: do Low and then say you got the most votes. If a draw just put draw.
Candidate A: 24 votes
Candidate B: 12 votes
Candidate C: 18 votes
Candidate A won.
High: do Med but also show the percentage of the votes they received as follows:
Candidate A: 12 votes - 25%
Candidate B: 24 votes - 50%
Candidate C: 12 votes - 25%
Candidate B won.
4b). We are going to make a random number guessing game. The game gets a random integer number between 1 and 100. The user then guesses the number until they get it right.
Low:
To get a random number do:
import random
answer=random.randint(1,100)
Med: Do Low and then print out whether their guess was too high or too low.
High: Do Med but only give them 5 guesses. Let them know each time how many guesses left.
4c). Get someone to enter the continents in a loop and say whether it is a continent or not.
Asia, Africa, North America, South America, Antarctica, Europe, and Australia
Low:
continents=[ "Asia", "Africa", "North America", "South America", "Antarctica", "Europe", "Australia" ]
To loop forever do
while True:
You can use the in keyword to see if a continent is in the list so:
if "Europe" in continents:
print("yes")
else:
print("no")
Med: Do Low but do not allow repeats. The best way is to remove a continent from the array once it has been used.
continent.remove("Europe")
High: Do Med and then make it finish once they get all the continents.
len(continents) tells you how many are still in there, when it is 0 it is over.
Super High: If they repeat a continent then tell them they have already said that.