Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 66 additions & 70 deletions PythonTrivia.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,48 @@
import random
import re
import ast

## FUNCTIONS HERE

def Category(response):#search function
res = re.search(('"category":"(.+?)","type"'),str(response))#function
if res:
found = res.group(1)
return found

def typefunc(response):#search function
res = re.search(('"type":"(.+?)","difficulty'),str(response))#function
if res:
found = res.group(1)
return found

def difficultyfunc(response):#search function
res = re.search(('"difficulty":"(.+?)","question":'),str(response))#function
if res:
found = res.group(1)
return found

def questionfunc(response):#search function
res = re.search(('","question":"(.+?)","correct_answer"'),str(response))#function
if res:
found = res.group(1)
return found

def goodfunc(response):#search function
res = re.search(('"correct_answer":"(.+?)","incorrect_a'),str(response))#function
if res:
found = res.group(1)
return found

def badfunc1(response):
res = re.search(('"incorrect_answers":(.+?)}'),str(response))#function
if res:
found = res.group(1)
return found


## MAINLOOP HERE

restart="y"
while restart=="y":
combo=0
Expand All @@ -15,79 +57,33 @@
maxcombo=0
loop=0
while loop<=0:
loop= int(input("how much questions do you want"))
loop= int(input("How many questions do you want?"))
repopt=["y","n"]
for i in range(1,loop+1,1):
import html
link ="https://opentdb.com/api.php?amount=1"
response = urlopen(link)
raw = response.read()
content = html.unescape(str(raw))


def category(response):#search function
res = re.search(('"category":"(.+?)","type"'),str(response))#function
if res:
found = res.group(1)
return found
category = category(content)


def typefunc(response):#search function
res = re.search(('"type":"(.+?)","difficulty'),str(response))#function
if res:
found = res.group(1)
return found
tipe= typefunc(content)


def difficultyfunc(response):#search function
res = re.search(('"difficulty":"(.+?)","question":'),str(response))#function
if res:
found = res.group(1)
return found
difficulty= difficultyfunc(content)
print("correct awnsers:",correct," incorrect awnsers:",incorrect)

category = Category(content)
tipe = typefunc(content)
difficulty = difficultyfunc(content)

print("correct answers:",correct," Incorrect answers:",incorrect)
print("combo:",combo, " Question number",i,"/",loop)
print("type:",tipe," category:",category," Difficulty:" ,difficulty)

print("Type:",tipe," Category:",category," Difficulty:" ,difficulty)

def questionfunc(response):#search function
res = re.search(('","question":"(.+?)","correct_answer"'),str(response))#function
if res:
found = res.group(1)
return found
question = questionfunc(content)
print(question)


def goodfunc(response):#search function
res = re.search(('"correct_answer":"(.+?)","incorrect_a'),str(response))#function
if res:
found = res.group(1)
return found
good = goodfunc(content)


def badfunc1(response):
res = re.search(('"incorrect_answers":(.+?)}'),str(response))#function
if res:
found = res.group(1)
return found
bad1= badfunc1(content)
bad1 = badfunc1(content)


options =ast.literal_eval(bad1)
options.append(good)
random.shuffle(options)
random.shuffle(options)
random.shuffle(options)
random.shuffle(options)
random.shuffle(options)
random.shuffle(options)
random.shuffle(options)


for n in range(6):
random.shuffle(options)

a =options[0]
b =options[1]
Expand All @@ -109,49 +105,49 @@ def badfunc1(response):
print("d)",d)
respond = "false"
while respond == "false":
res = input("Awnser:")
res = input("Answer:")
res=res.lower()
if tipe=="boolean":
valids=["a","b"]
if res in valids:
if res==check:
print("Correct awnser!")
print("Correct answer!")
correct=correct+1
combo=combo+1
else:
print ("wrong awnser")
print ("Wrong answer")
combo = 0
incorrect = incorrect+1
respond="true"
else:
res=print("incorrect awnser, please put the awnser in abc format:")
res=print("Incorrect answer, please put the answer in abc format:")
elif tipe==("multiple"):
valids=["a","b","c","d"]
if res in valids:
if res==check:
print("Correct awnser!")
print("Correct answer!")
correct=correct+1
combo=combo+1
else:
print ("wrong awnser")
print ("Wrong answer")
combo = 0
incorrect = incorrect+1
respond="true"
else:
res=print("incorrect awnser, please put the awnser in abc format:")
res=print("Incorrect answer, please put the answer in abc format:")
if maxcombo<combo:
maxcombo = combo

print("FINAL RESULTS---")
print("correct awnsers:",correct," incorrect awnsers:",incorrect)
print("combo:",combo, " Question number",i,"/",loop)
print("max combo:",maxcombo)
print("Correct answers:",correct," Incorrect answers:",incorrect)
print("Combo:",combo, " Question number",i,"/",loop)
print("Max Combo:",maxcombo)
reserror=1
while reserror==1:
restart=input("play again? (y/n)")
restart=input("Play again? (y/n)")
if restart in repopt:
reserror=0
if restart ==repopt[0]:
print("you decided to stay, now suffer")
print("You decided to stay, now suffer")
else:
print("invalid awnser, please repeat uwu")
print("Invalid answer, please repeat uwu")