how to shuffle questions in python

2024/7/6 21:36:04

please anyone help me i have posted my whole work down can anyone tell me how to shuffle theses five questions it please i will be very thankful.

print("welcome to the quiz")
Validation = Falsewhile Validation ==False:name=input("Please enter your name")age=int(input("Please enter your age"))print("Use keboard to play the quiz")play=input("Are you ready for the online safety questions")if play.capitalize()== "Yes":if age >16:print("This quiz might be easier for you")print("welcome to the quiz")Validation = False)question1=input("Q1:What is CEOP?/A:Child Exploitation and Online Protection/B:Child Exploitation and Organised Protectors/C:Criminal Exploration and Online Protection")score = 0if question1.capitalize() == "A":print("WELL DONE")score = score + 5elif question1.capitalize() =="B":print("Wrong Answer")elif question1.capitalize() =="C":print("Wrong Answer")else:print("Wrong Answer")print("so far, you have",score,"marks")question2=input("Q2:When you get an email from someone you do not know, what should you do?/A:Reply and say hello/B:Delete it and mark as spam/C:Forward to your friends")if question2.capitalize() == "B":print("WELL DONE")score = score + 10elif question2.capitalize() =="A":print("Wrong Answer")elif question2.capitalize() =="C":print("Wrong Answer")else:print("Wrong Answer")print("so far, you have",score,"marks")question3=input("Q3:How secret should you keep your passwords?/A:Give them to strangers/B:Give them only to your best friends/C:Never give out passwords except to your parents")if question3.capitalize() == "C":print("WELL DONE")score = score + 15elif question3.capitalize() =="B":print("Wrong Answer")elif question3.capitalize() =="A":print("Wrong Answer")else:print("Wrong Answer")print("so far, you have",score,"marks")question4=input("Q4:When an online contact who frightens you asks to meet you in person what should you do?/A:Arrange to meet them with your best friend/B:Arrange to meet them/C:Report to CEOP")if question4.capitalize() == "C":print("WELL DONE")score = score + 20elif question4.capitalize() =="B":print("Wrong Answer")elif question4.capitalize() =="A":print("Wrong Answer")else:print("Wrong Answer")print("so far, you have",score,"marks")question5=input("Q5:If an email asks you to enter your bank account details because of a problem with your account what should you do?/A:Reply to the email/B:Contact the bank to check if they sent the email/C:Enter your bank account details")if question5.capitalize() == "B":print("WELL DONE")score = score + 25elif question5.capitalize() =="C":print("Wrong Answer")elif question5.capitalize() =="A":print("Wrong Answer")else:print("Wrong Answer")    print ("Thank you for doing the quiz", name,".You scored", score, "marks in the quiz")Validator=Trueelse:Validation=False
Answer

You can't shuffle them the way they are hard-coded. Store the questions is a list, and use the random.shuffle function on that list. You could do something like

validation = False
while validation ==False:# input ageif age > 16:validation = Falsequestions = [('question 1 text', 'A'),('question 2 text', 'C')...]random.shuffle(questions)for question_text, correct_answer in questions:user_input = input(question_text)if user_input.capitalize() == correct_answer:score += 5print("well done")else:print("wrong answer")validation = True
https://en.xdnf.cn/q/120505.html

Related Q&A

Selenium python do test every 10 seconds

I am using selenium (python) testing and I need to test my application automatically every 10 seconds.How can I do this?

Type Object has no attribute

I am working on a program, but I am getting the error "Type object Card has no attribute fileName. Ive looked for answers to this, but none that Ive seen is in a similar case to this.class Card: R…

Generate random non repeating samples from an array of numbers

I made a battleships game and I now need to make sure that the computer doesnt attack at the same spot twice.My idea of it is storing each shots co-ordinates in a variable which gets added to whenever …

How to get back fo first element in list after reaching the end? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 5 years ago.Improve…

Collision detection on the y-axis does not work (pygame)

I am trying to get the collision detection in my code to work. I am using vectors and I want the player sprite to collide and stop when it collides with a sprite group called walls. The problem is that…

Search for string within files of a directory

I need help writing a light weight Python (v3.6.4) script to search for a single keyword within a directory of files and folders. Currently, I am using Notepad++ to search the directory of files, altho…

Extract parent and child node from python tree

I am using nltks Tree data structure.Below is the sample nltk.Tree.(S(S(ADVP (RB recently))(NP (NN someone))(VP(VBD mentioned)(NP (DT the) (NN word) (NN malaria))(PP (TO to) (NP (PRP me)))))(, ,)(CC an…

Click button with selenium and python

Im trying to do web scraping with python on and Im having trouble clicking buttons. Ive tried 3 different youtube videos using Xpath, driver.find_element_by_link_text, and driver.find_element. What am …

Combinations of DataFrames from list

I have this:dfs_in_list = [df1, df2, df3, df4, df5]I want to concatenate all combinations of them one after the other (in a loop), like:pd.concat([df1, df2], axis=1) pd.concat([df1, df3], axis=1) p…

Python: iterate through dictionary and create list with results

I would like to iterate through a dictionary in Python in the form of:dictionary = {company: {0: apple,1: berry,2: pear},country: {0:GB,1:US,2:US} }To grab for example: every [company, country] if coun…