Skip to content

Instantly share code, notes, and snippets.

@NP-chaonay
Last active August 12, 2020 05:26
Show Gist options
  • Save NP-chaonay/848f5197177045199bd5b68e3c571b7e to your computer and use it in GitHub Desktop.
Save NP-chaonay/848f5197177045199bd5b68e3c571b7e to your computer and use it in GitHub Desktop.
Scripts for random quizes.
#!/usr/bin/env python3
# Name: RandomQuizes
# Description: Scripts for random quizes.
# Author: NP-chaonay (Nuttapong Punpipat)
# Version: Unversioned
# Version Note: N/A
# Revised Date: 2020-08-09 07:27 (UTC)
# License: MIT License
# Programming Language: Python
# CUI/GUI Language: English
# Development Stage :
# [/] Reviewing of Code
# [] Reviewing of Type and Value Checking & Error Handling
# [] Reviewing of Documentations
# [] Testing
import np_chaonay.main as npc_m
import random
# Future functions for np_chaonay.main
def all_str(*iterable):
return ''.join(tuple(map(str,iterable)))
def all_str_print(*iterable,end='\n'):
print(all_str(*iterable),end=end)
# Quizes
quizes=[
#(0,'Multiple choices, choose one',['CHOICE'],1),
#(1,'No checking',''),
#(2,'Full string checking',''),
]
# Operation
while len(quizes)!=0:
index=random.randint(0,len(quizes)-1)
selected_quiz=quizes[index]
del quizes[index]
print('Question: '+selected_quiz[1])
if selected_quiz[0]==0:
print('Choices:')
i=0
for choice in selected_quiz[2]:
i+=1
all_str_print(i,') ',choice)
while True:
ans=input('Solution Choice: ')
if not npc_m.is_integer_string(ans):
npc_m.print_categorical_bracket('ERROR','Answer must be positive integer.')
continue
ans=int(ans)
if ans<=0:
npc_m.print_categorical_bracket('ERROR','Answer must be positive integer.')
continue
elif ans>len(selected_quiz[2]):
npc_m.print_categorical_bracket('ERROR','Answer must be in range of choices.')
continue
else: break
if ans==selected_quiz[3]:
print('RESULT: Correct')
else:
print('Result: Wrong.')
print('Answer: Choice #'+str(selected_quiz[3])+'.')
if selected_quiz[0]==1:
ans=input('Solution: ')
print('Answer: \''+str(selected_quiz[2])+'\'.')
if selected_quiz[0]==2:
ans=input('Solution: ')
if ans==selected_quiz[2]:
print('RESULT: Correct')
else:
print('Result: Wrong.')
print('Answer: \''+str(selected_quiz[2])+'\'.')
print()
print('All quizes comepleted.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment