Python

Solved
muzan0jackson Posted messages 19 Status Membre -  
jee pee Posted messages 9400 Registration date   Status Modérateur Last intervention   -




Hello, I have a little problem... In my homework, we are asked to randomly choose 10 questions and they should not repeat. I can't manage to do it, so thank you for helping me!!!

9 réponses

jee pee Posted messages 9400 Registration date   Status Modérateur Last intervention   9 945
 
Hello,

For formatting sources, above the editing area of your messages, there are icons for text enhancement. The one that looks like
<> ▼
allows you to apply the corresponding format to the code based on its type (C, Python, Shell, ...).

Here’s a little tutorial: https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code

Please send us your source in this format, not as images:
def f(texte): codage={'a':111,'b':121,'c':211,'d':311,'e':151,'f':411,'g':113,'h':11,'i':21,'j':71,'k':19,'l':81,'m':100,'n':9,'o':1,'p':8,'q':1234,'r':1119,'s':4111,'t':5111,'u':555,'v':321,'w':0,'x':20,'y':30,'z':40,' ':951,"'":753} liste = [] for lettre in texte: valeur = codage.get(lettre) liste.append(valeur) return liste print(f('bonjour')) 

0
muzan0jackson Posted messages 19 Status Membre
 
 import random compteur = 0 start = input("Hello, are you ready to play?: ") if start == "yes": print ("Let's go!!!!") elif start == "Yes" : print ("Let's go!!!!") else : print ("Goodbye...") Questions = [ Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, Q10, Q11, Q12, Q13, Q14] random.shuffle(Questions) print(Questions) Q1 = input("What does NSI stand for?: A-Digital Computer Science B-New Computer Science: ") if Q1 == "A": compteur += 1 print ("Well done!!!") elif Q1 == "a": compteur += 1 print ("Well done!!!") else : print ("Ouch, ouch, ouch...") Q2 = input("What is the purpose of the int variable?: A-It allows conversion to float B-It converts to Unicode C-It allows modifying a variable to an integer D-Nothing, it does not exist: ") if Q2 == "C": compteur += 1 print ("Well done!!!") elif Q2 == "c": compteur += 1 print ("Well done!!!") else : print ("Ouch, ouch, ouch...") Q3 = input("What is the purpose of the str variable?: A-Nothing, it does not exist B-It allows conversion to float C-It allows transforming most variables from another type into strings: ") if Q3 == "C": compteur += 1 print ("Well done!!!") elif Q3 == "c": compteur += 1 print ("Well done!!!") else : print ("Ouch, ouch, ouch...") Q4 = input("What is the purpose of the float variable?: A-It allows conversion to float B-It evaluates the content of its argument as if it were Python code C-Nothing, it does not exist: ") if Q4 == "C": compteur += 1 print ("Well done!!!") elif Q4 == "c": compteur += 1 print ("Well done!!!") else : print ("Ouch, ouch, ouch...") Q5 = input("What is the decimal conversion of this binary number 0011?: A-3 B-4 C-1 D-11: ") if Q5 == "A": compteur += 1 print ("Well done!!!") elif Q5 == "a": compteur += 1 print ("Well done!!!") else : print ("Ouch, ouch, ouch...") Q6 = input("What does F represent in hexadecimal?: A-16 B-11 C-10 D-15: ") if Q6 == "D": compteur += 1 print ("Well done!!!") elif Q6 == "d": compteur += 1 print ("Well done!!!") else : print ("Ouch, ouch, ouch...") Q7 = input("What does D represent in hexadecimal?: A-16 B-13 C-10 D-15: ") if Q7 == "B": compteur += 1 print ("Well done!!!") elif Q7 == "b": compteur += 1 print ("Well done!!!") else : print ("Ouch, ouch, ouch...") Q8 = input("Who invented the first algorithms?: A-Charles Babbage B-George Boole C-Al-Khwârizmi D-Al Mahani: ") if Q8 == "C": compteur += 1 print ("Well done!!!") elif Q8 == "c": compteur += 1 print ("Well done!!!") else : print ("Ouch, ouch, ouch...") Q9 = input("What does A represent in hexadecimal?: A-10 B-11 C-9 D-12: ") if Q9 == "A": compteur += 1 print ("Well done!!!") elif Q9 == "a": compteur += 1 print ("Well done!!!") else : print ("Ouch, ouch, ouch...") Q10 = input("What does C represent in hexadecimal?: A-12 B-10 C-14: ") if Q10 == "A": compteur += 1 print ("Well done!!!") elif Q10 == "a": compteur += 1 print ("Well done!!!") else : print ("Ouch, ouch, ouch...") Q11 = input("What does E represent in hexadecimal?: A-11 B-10 C-14: ") if Q11 == "C": compteur += 1 print ("Well done!!!") elif Q11 == "c": compteur += 1 print ("Well done!!!") else : print ("Ouch, ouch, ouch...") Q12 = input("What does B represent in hexadecimal?: A-12 B-10 C-14 D-11: ") if Q12 == "D": compteur += 1 print ("Well done!!!") elif Q12 == "d": compteur += 1 print ("Well done!!!") else : print ("Ouch, ouch, ouch...") Q13 = input("What does CVS stand for?: A-Comma Salsa Veranda B-Comma Separated Values C-Coca Sauce View: ") if Q13 == "B": compteur += 1 print ("Well done!!!") elif Q13 == "b": compteur += 1 print ("Well done!!!") else : print ("Ouch, ouch, ouch...") Q14 = input("What does ASCII stand for?: A-Armenian Standard Code for Information Interchange B-African Standard Code for Information Interchange C-American Standard Code for Information Interchange: ") if Q14 == "C": compteur += 1 print ("Well done!!!") elif Q14 == "c": compteur += 1 print ("Well done!!!") else : print ("Ouch, ouch, ouch...") print ("Your score is:", compteur,"/10") 
0