def main(): q1 = questions.Question( "What year did the Beatles make it big in america? ", "A. 1965", "B. 1945", "C, 1956", "D, 1964") q2 = questions.Question( "Which famous musician from the Beatles was murdered in 1980? ", "A. Ringo Starr", "B. John Lennon", "C. George Harrison", "D. Geezer Butler") q3 = questions.Question("How many sides does a hexagon have?" "A. 4", "B. 6", "C. 9", "D. 7") q4 = questions.Question( "Who wrote the Harry Potter series?" "A. J.K. Rowling", "B. Stephen King", "C. George R. R. Martin", "D. Thomas Kinkaid") q5 = questions.Question( "Whos the main character of the Harry Potter series?" "A. Tigger", "B. John Wayne Gacy", "C. Harry Potter", "D. Morpheus") q6 = questions.Question( "Which band wrote the hit song: T.N.T?" "A. Led Zeppelin", "B. AC/DC", "C. The Ramones", "D. The Who") q7 = questions.Question( "How many Queens of the Stone Age albums are there?" "A. 4", "B. 9", "C. 7", "D. 6") q8 = questions.Question( "Who wrote the Game of Thrones books?" "A. Stephen King", "B. JK Rowling", "C. James Patterson", "D. George RR Martin") q9 = questions.Question( "The Beatles kick started which musical explosion?" "A. The British Invasion", "B. The Grunge scene" "C. The Garage Rock Revival scene", 'D. Glam Rock') q10 = questions.Question( "What band was did the late Lemmy Kilminster form?" "A. Metallica", "B. Motorhead", "C. Opeth", "D. Kyuss") all_questions = (q1, q2, q3, q4, q5, q6, q7, q8, q9, q10) print("* Player 1 *") player1 = ask(all_questions) print("* Player 1 *") player2 = ask(all_questions) if player1 == player2: print("You two are now tied!") elif player1 > player2: print("Player 1 is winner of this quiz!") else: print("Player 2 is the winner of this quiz!")
def main(): # make questions q1 = questions.Question("What is 2+2?", "A. fish", "B. 5", "C. 4", "D. All of the above", "C") q2 = questions.Question("What is the best food ever created?", "A. pizza", "B. sushi", "C. cheeseburger", "D. Spaghetti", "A") q3 = questions.Question("What is the capital of Illinois?", "A. chicago", "B. crystal lake", "C. springfield", "D. nashville", "C") q4 = questions.Question("What sport do the Packers play?", "A. baseball", "B. football", "C. hockey", "D. tennis", "B") q5 = questions.Question("Who is our current president?", "A. Obama", "B. George W. Bush", "C. Teddy Roosevelt", "D. Trump", "D") q6 = questions.Question("What does, Je parler en Francais, mean?", "A. I speak French", "B. I am French", "C. I love French", "D. Nothing", "A") q7 = questions.Question("What country is Illinois part of?", "A. Canada", "B. USA", "C. Mexico", "D. China", "B") q8 = questions.Question("What country touches the USA?", "A. Russia", "B. Thailand", "C. Canada", "D. Brazil", "C") q9 = questions.Question("Who did Trump beat for the presidency?", "A. Clinton", "B. The Rock", "C. Romney", "D. Obama", "A") q10 = questions.Question("What is Meijer?", "A. A food brand", "B. A school", "C. A computer", "D. A retail store", "D") player1 = 0 # initial scores set to 0 player2 = 0 set_1 = [q1, q3, q5, q7, q9] # sets of questions set_2 = [q2, q4, q6, q8, q10] print("player1: ") # giving player 1 set 1 for query in set_1: print("\n") print(query.get_question()) print(query.get_a1()) print(query.get_a2()) print(query.get_a3()) print(query.get_a4()) guess = input("Please enter the letter for your answer: ").upper().strip(" ") if guess == query.get_answer(): print("You're right!") # if correct then print so player1 += 1 print("Player 1 earned:", str(player1), "point(s).") print("player2: ") for query in set_2: print("\n") print(query.get_question()) print(query.get_a1()) print(query.get_a2()) print(query.get_a3()) print(query.get_a4()) guess = input("Please enter the letter for your answer: ").upper().strip(" ") if guess == query.get_answer(): print("You're right!") player2 += 1 print("Player 2 earned:", str(player2), "point(s).")
def __init__(self): logging.basicConfig() self.loop_flag = True self.bot_state = 0 self.QuestionObject = Q.Question() trial1 = Pipeline([ ('vectorizer', TfidfVectorizer(tokenizer=stemming_tokenizer, stop_words=stopwords.words('english'))), ('classifier', MultinomialNB()), ]) self.detector0 = train(trial1, xtrain, ytrain, xtest, ytest) self.sentiment = sent.classifier()
def get_questions(players): # create list for players questions and answers player = [] # asks player for their questions and answers print(players + ": Please enter 5 questions and answers") for create in range(1, 6): question = input("Question #" + str(create) + ": ") ans1 = input("A: ") ans2 = input("B: ") ans3 = input("C: ") ans4 = input("D: ") # asks user to input the correct answer correct = input("Which letter is the correct answer? ") # upper case the letter correct = correct.upper() # error loop for correct answer while correct != 'A' and correct != 'B' and correct != 'C' and correct != 'D': print() print("Error, Correct answer does not match any \n" + "of the assign answers. Please try again.") correct = input("Which letter is the correct answer? ") correct = correct.upper() print() # sends question and answers to class trivia = questions.Question(question, ans1, ans2, ans3, ans4, correct) # append player 1 list player.append(trivia) # change player1 list to a tuple player = tuple(player) # clears screen for next player for x in range(100): print() # return player tuple return player
def mkQuestion(self, row): try: question, a, b, c, d, e, ca = row except ValueError: self.errors.append( (row[0], "Wrong number of columns for this row.")) return except Exception as e: self.errors.append((row[0], e)) # munge a little ca = ca.lower() ansList = [i.strip() for i in [a, b, c, d, e] if i] try: self.ql.append( questions.Question(question, ansList, ca, self.st, self.getOrd())) except questions.DuplicateError: self.errors.append((question, "This question is a duplicate.")) except questions.QuestionFormatError as e: self.errors.append((question, e))
def upload_q(user, window): #window for uploading questions window.destroy() upload_q_window = tk.Tk() upload_q_window.title('Upload Question') upload_q_window.geometry('700x500') upload_q_window.config(bg=bg) Label(upload_q_window, text="Enter Question:", font=("Ariel black", 16), bg=bg).grid() question = tkst.ScrolledText(upload_q_window, width=35, height=5) question.place(x=0, y=30) Label(upload_q_window, text="Give Description(optional):", font=("Ariel black", 16), bg=bg).place(x=0, y=120) description = tkst.ScrolledText(upload_q_window, width=35, height=10) description.place(x=0, y=160) Label(upload_q_window, text="Provide input if neccessary", font=("Ariel black", 16), bg=bg).place(x=0, y=330) input_area = tkst.ScrolledText(upload_q_window, width=35, height=5) input_area.place(x=0, y=360) back_button = tk.Button(upload_q_window, text="Back Home", width=20, height=2, bg='powder blue', command=lambda: Profile(user, upload_q_window)) back_button.place(x=0, y=450) Label(upload_q_window, text="Provide Solution", font=("Ariel black", 16), bg=bg).place(x=310, y=0) solution = tkst.ScrolledText(upload_q_window, width=35, height=25) solution.place(x=310, y=30) Label(upload_q_window, text="Title: ", font=("Ariel black", 16), bg=bg).place(x=310, y=445) title_entry = Entry(upload_q_window) title_entry.place(x=360, y=450) submit_button = Button( upload_q_window, text="Submit", bg="powder blue", width=15, font=("Ariel black", 15), command=lambda: qt.Question( user, upload_q_window, question.get('1.0', END), solution.get('1.0', END), description.get('1.0', END), title_entry.get(), input_area.get('1.0', END))) submit_button.place(x=500, y=440)
def migrate(): if not os.path.exists("migrated_questions_data"): os.mkdir("migrated_questions_data") files = glob.glob("migrated_questions_data/*") for f in files: os.remove(f) files = glob.glob("questions_data/*") for f in files: m = re.search("(\d{12})\.(\d+)\.question\.xml", f) version = int(m.group(2)) tree = etree.parse(f) question_id = tree.xpath("/*")[0].get("id") sourceId = tree.xpath("/*/source_id")[0].text developerName = tree.xpath("/*/developer_name")[0].text developerEmailAddress = tree.xpath("/*/developer_email")[0].text language = tree.xpath("/*")[0].get("language") dialect = tree.xpath("/*")[0].get("dialect") calendar = tree.xpath("/*")[0].get("calendar") currency = tree.xpath("/*")[0].get("currency") unitSystem = tree.xpath("/*")[0].get("unit_system") title = "" if len(tree.xpath("/*/title")) > 0: title = tree.xpath("/*/title")[0].text parts = [ e for e in tree.xpath("/*/*") if e.tag in ["statement", "mcq", "mrq", "frq"] ] question = questions.Question() question.id = question_id question.version = version question.lastModificationDate = datetime.datetime.now() question.attribution.sourceId = sourceId question.addDeveloper("writer", developerName, developerEmailAddress) if language == "en": question.language.name = "English" if dialect == "american": question.addDialect("American") if dialect == "british": question.addDialect("British") if dialect == "american british": question.addDialect("American") question.addDialect("British") if unitSystem == "si": question.addUnitSystem("SI") if unitSystem == "usc": question.addUnitSystem("USC") if unitSystem == "si usc": question.addUnitSystem("SI") question.addUnitSystem("USC") question.title = title partMap = { "statement": "information", "mcq": "mcq", "mrq": "mcq", "frq": "frq" } for part in parts: p = question.addPart(partMap.get(part.tag, "")) if part.tag == "mcq" or part.tag == "mrq": rp = p.addChoicesResponseFormat() keysAndDistractors = [ e for e in part.xpath("./*") if e.tag in ["key", "distractor"] ] for kd in keysAndDistractors: choice = rp.addChoice() choice.isCorrectAnswer = True if kd.tag == "key" else False question.save("migrated_questions_data/" + question.id + ".question.xml")
class Bot: loop_flag = False QuestionObject = Q.Question() bot_state = None name = None detector0 = None movie = None sentiment = None skip_state = False state_one_visited = False def __init__(self): logging.basicConfig() self.loop_flag = True self.bot_state = 0 self.QuestionObject = Q.Question() trial1 = Pipeline([ ('vectorizer', TfidfVectorizer(tokenizer=stemming_tokenizer, stop_words=stopwords.words('english'))), ('classifier', MultinomialNB()), ]) self.detector0 = train(trial1, xtrain, ytrain, xtest, ytest) self.sentiment = sent.classifier() def conversationNotOver(self): return self.loop_flag def endConversation(self): self.loop_flag = False def question(self): if self.bot_state == 1: if not self.state_one_visited: self.state_one_visited = True return self.QuestionObject.returnquestion( self.bot_state ) + " " + str( self.name ) + ". Do you want to know about a movie or want me to suggest something you would like to watch ? " else: return " Do you want to know about a movie or want me to suggest something you would like to watch ? " return self.QuestionObject.returnquestion(self.bot_state) def extractnames(self, sentences): names = [] for tagged_sentence in sentences: for chunk in nltk.ne_chunk(tagged_sentence): if type(chunk) == nltk.tree.Tree: if chunk.label() == 'PERSON': names.append(' '.join([c[0] for c in chunk])) return names def preprosess(self, response): stop = stopwords.words('english') response = ' '.join([i for i in response.split() if i not in stop]) sentences = nltk.sent_tokenize(response) sentences = [nltk.word_tokenize(sent) for sent in sentences] sentences = [nltk.pos_tag(sent) for sent in sentences] if self.bot_state == 0: names = self.extractnames(sentences) if len(names) == 0: print "Movie Bot : Sorry , I couldn't get you , Could you please tell me your name?" self.name = raw_input('You : ') else: self.name = names[0] if self.bot_state == 1: label = self.detector0.predict([str(response)]) if label == 0: print "Movie Bot : Could you please tell the movie name?" moviename = raw_input('You : ') self.movie = moviename url = "http://www.omdbapi.com/?t=" + str(moviename) json = requests.get(url).json() try: print "Movie Bot : " + "The title of the movie is " + ( json['Title']) + ". It was released in the year " + ( json['Year']) + " and is a " + ( json['Genre'] ) + " movie. It is directed by " + ( json['Director'] ) + ". It has the following awards :" + ( json['Awards']) except: print "Movie Bot : Sorry I couldn't understand" self.skip_state = True elif label == 1: genre = self.detectgenre(response) if genre in movies: self.movie = movies[genre][random.randint( 0, (len(movies[genre]) - 1))] print "Movie Bot : I suggest you to watch " + self.movie else: self.movie = movies['action'][random.randint( 0, (len(movies[genre]) - 1))] print "Movie Bot : I suggest you to watch " + self.movie if self.bot_state == 2: if response.lower() == 'yes' or response.lower() == 'yeah': url = "https://api.nytimes.com/svc/movies/v2/reviews/search.json?api-key=73073227b3f343a384cb585053cd5a32&critics-pick=N&query=" + str( self.movie) try: json = requests.get(url).json() review_url = str( json['results'][0]['link']['url']).replace( 'http://www.', 'https://') except: print "Sorry I am not able to fetch the review for that movie" return print "Movie Bot : You can read the complete review here . " + str( review_url) review = requests.get(review_url) soup = BeautifulSoup(review.text, 'html.parser') soup_review = soup.find_all( "p", class_="story-body-text story-content") review_final = '' for x in soup_review: review_final = review_final + str( unicodedata.normalize('NFKD', x.get_text()).encode( 'ascii', 'ignore')) sent = self.sentiment.classify({'a': review_final}) if sent == 'pos': print "Movie Bot : After analysing the review, I think it is a good movie " if sent == 'neg': print "Movie Bot : After analysing the review, I think it is not a good movie " def detectgenre(self, sentence): url = "https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/ddba8f91-8175-4878-a28e-a91519272397?subscription-key=23183b4aa8e64c2bbb20bdc225dc257e&verbose=true&q=" + sentence try: json = requests.get(url).json() except: print " I am not able to reach my server right now" print "Movie Bot : Can you please tell me which genre movies do you like? " genre = raw_input("You : ") return genre def next_state(self): if not self.skip_state: if self.bot_state == 2: self.bot_state = 0 self.bot_state = self.bot_state + 1 else: self.skip_state = False