Python help needed please [solved] | Sololearn: Learn to code for FREE!


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.

8/31/2021 3:19:16 AM

Anas Dharar

8 Answers

New Answer

+6 check this out please


But Rushikesh , what about answers? If i want answer from user.... What should i do?


Oh thanks a lot Rushikesh ! Thank you


Anas (50% Active) Please have a look again


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


⠀⠀⠀ if You learning the dictionarys You can use glichs for


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)


If this is solved.... remember mark a response as valid