I am a new programmer working on my very first Python program ever.
I am building a little quiz game in Python. The code contains ten possible quiz questions. In order to win, the user must get four of them correct in a row. To make the game more playable, I've set the questions to be assigned to a random number generator.
So far, so good, but I'm not sure how to ask the program to go BACk and run the number generator again after the user has completed the first question. I don't think I quite understand how to frame the loop?
Here's my code. I imagine there's a more elegant way to write this, but with each question having different multiple choice options, I wasn't sure of the best way to throw everything in an elegant loop.
How can I tweak this so the user actually gets more than one question? Thanks so much everybody!
import random
#Intro message
print("Welcome to Where In The World Is The Civil ConFLiCT Trophy?")
print("Brought to you by Extra Points.")
user_name = input ("What is your name?")
print("Okay, " + str(user_name) + ". Here is the deal.")
print("")
print("Bob Diaco has stolen the critically important college football landmark, the Civil ConFLiCT Trophy.")
print("That trophy belongs in a musuem! Or at least, somewhere in the catacombs of the UCF athletic department.")
user_choice = input ("Will you help us find it?")
#decision tree around "will you help us find it"
if user_choice == "no":
print("then why the hell did you play this game?")
elif user_choice == "yes":
print("Great. Let's follow our first clue.")
else:
print("Please answer yes or no. I'm too stupid to program anything else.")
#here is where I'm gonna try to put my question variables
question_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
user_score = 0
wrong_answer = "Sorry, that was incorrect. Now Bob Diaco got away."
right_answer = "Correct! To the next clue!"
#The goal here is for the user to answer four questions correctly.
#Each correct answer should increase their score by one. A failed answer should end the game.
computer_action = random.choice(question_list)
if computer_action == 1:
print("Diaco is on the run towards the school with the smallest enrollment in FBS. Where should we go?")
print("A. Navy.")
print("B. Tulsa.")
print("C. SMU.")
print("D. Rice.")
user_answer_1 = input("Please answer A, B, C or D.")
if user_answer_1 == "B":
print(right_answer)
user_score + 1
computer_action = random.choice(question_list)
else:
print(wrong_answer)
elif computer_action == 2:
print("That dastardly Diaco absconded with the trophy and is off to the city that hosted the Salad Bowl, which was a real college football game that we didn’t make up.")
print("A. Phoenix, AZ")
print("B. Cleveland, OH")
print("C. Evansville, IN")
print("D. Santa Fe, NM.")
user_answer_2 = input("Please answer A, B, C or D.")
if user_answer_2 == "A":
print(right_answer)
user_score + 1
computer_action = random.choice(question_list)
else:
print(wrong_answer)
elif computer_action == 3:
print("Now Diaco has fled to the campus of the last D-1 school to drop football completely. Note: I said D-1, NOT FBS! ")
print("A. Hofstra.")
print("B. Idaho.")
print("C. Jacksonville.")
print("D. Seton Hall.")
user_answer_3 = input("Please answer A, B, C or D.")
if user_answer_3 == "C":
print(right_answer)
user_score + 1
computer_action = random.choice(question_list)
else:
print(wrong_answer)
elif computer_action == 4:
print("Bob Diaco has taken the trophy and fled to the only school on this list where John Heisman did NOT coach.")
print("A. Wooster")
print("B. Oberlin")
print("C. Auburn")
print("D. Rice")
user_answer_4 = input("Please answer A, B, C or D.")
if user_answer_4 == "A":
print(right_answer)
user_score + 1
computer_action = random.choice(question_list)
else:
print(wrong_answer)
elif computer_action == 5:
print("So close! But we just missed it. Now Diaco has taken the trophy to where Amos Alonzo Stagg coached immediately after leaving Chicago. ")
print("A. Northwestern")
print("B. Notre Dame")
print("C. San DIego State")
print("D. Pacific")
user_answer_5 = input("Please answer A, B, C or D.")
if user_answer_5 == "D":
print(right_answer)
user_score +1
computer_action = random.choice(question_list)
else:
print(wrong_answer)
elif computer_action == 6:
print("Gasp, we missed it again! Now, the trophy is hiding at the stadium with the smallest capacity in FBS. Or at least, according to Wikipedia.")
print("A. Coasta Carolina.")
print("B. Charlotte.")
print("C. Ball State.")
print("D. Nevada.")
user_answer_6 = input("Please answer A, B, C or D.")
if user_answer_6 == "B":
print(right_answer)
user_score + 1
computer_action = random.choice(question_list)
else:
print(wrong_answer)
elif computer_action == 7:
print("Aww hamburgers, the trophy is on the move again! This time, it’s allegedly bound for the campus of the P5 program with the worst bowl winning percentage!")
print("A. Wake Forest.")
print("B. Duke.")
print("C. Indiana.")
print("D. Iowa State.")
user_answer_7 = input("Please answer A, B, C or D.")
if user_answer_7 == "C":
print(right_answer)
user_score + 1
computer_action = random.choice(question_list)
else:
print(wrong_answer)
elif computer_action == 8:
print("Rats, it looks like we just missed it! Now I hear the trophy is headed to the campus with the highest winning percentage in all of FBS football.")
print("A. Ohio State.")
print("B. Michigan.")
print("C. Notre Dame.")
print("D. Boise State.")
user_answer_8 = input("Please answer A, B, C or D.")
if user_answer_8 == "D":
print(right_answer)
user_score + 1
computer_action = random.choice(question_list)
else:
print(wrong_answer)
elif computer_action == 9:
print("Legend has it, the trophy was mailed to the campus of the FBS record holder for most passing touchdowns in a single game.")
print("A. Hawaii.")
print("B. Houston.")
print("C. Texas Tech.")
print("D. Wisconsin.")
user_answer_9 = input("Please answer A, B, C or D.")
if user_answer_9 == "B":
print(right_answer)
user_score + 1
computer_action = random.choice(question_list)
else:
print(wrong_answer)
elif computer_action == 10:
print("Rumor has it, the trophy is off to the city where Woody Hayes got his first head coaching job!.")
print("A. Columbus, OH.")
print("B. Oxford, OH.")
print("C. Granville, OH.")
print("D. Athens, OH.")
user_answer_10 = input("Please answer A, B, C or D.")
if user_answer_10 == "C":
print(right_answer)
user_score + 1
computer_action = random.choice(question_list)
else:
print(wrong_answer)
if user_score == 4:
print("Congrats! You've finally aprehended Bob Diaco and the mythical Civil ConFliCT Trophy. It can now be sent to the College Football Hall of Fame to be properly enjoyed by everybody. Except UConn, probably.")
print("")
Aucun commentaire:
Enregistrer un commentaire