+ 10
Python help needed please [solved]
In this code, i want random keys to be printed from the dictionary, and the user must input the value of that key. Please help me do this. https://code.sololearn.com/c5oq1hRB3113/?ref=app
8 Answers
+ 6
https://code.sololearn.com/cb0ONTA1XTKc/?ref=app
check this out please
+ 3
But Rushikesh , what about answers? If i want answer from user.... What should i do?
+ 3
Oh thanks a lot Rushikesh !
Thank you
+ 2
Anas (50% Active)
Please have a look again
+ 2
Easy đ€đ€đ€
quizs = dict()
seen = list()
while True:
# bag data struct impl using dict+set
quiz, answer = random.choice(quizs.items())
if quiz in seen:
continue # avoid ask for dupes
seen += quiz # register dupe
if len(seen) > len(quizs):
break # all seen. end game
#... ask user
user_answer = input(quiz)
#... check user answer
print("You win" if answer is user_answer else "You loose")
is all you need
+ 1
â â â if You learning the dictionarys You can use glichs for
+ 1
use this to make it generate diffrent questions every time:
import random
def generate_sheet(howlong):
out = dict()
for i1 in range(howlong):
ques = '{}{}{}'.format(
str(random.randint(10,500)),
random.choice(list('+-')),
str(random.randint(10,500)),)
ans = eval(ques)
out[ques] = ans
return out #this function returns a dict
use it like this
questions = generate_sheet(howlong=10)
0
If this is solved.... remember mark a response as valid