Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- himport sys
- from random import randint as rd
- class mathquiz:
- operations = ['+','-','x','/']
- #op: operation, se: start-end
- def __init__(self,op,se):
- self.op,self.se = op,se
- def create(self):
- res = (
- rd(int(self.se[0]),int(self.se[1])),
- rd(int(self.se[0]),int(self.se[1]))
- )
- return [res[0],self.op,res[1]]
- def losing(self,poin):
- if poin <= 1:
- return sys.exit('\n[#] Yeahhh, You lose, Trash!')
- def question(self):
- if self.op not in self.operations:
- sys.exit('operations failure')
- poin = 0
- while True:
- a,b,c = self.create()
- b="*" if b and "x" else b;q = f"{a} {b} {c}"
- answer = input('[?] '+q+' = ')
- sys.exit('\n[#] Bye Bye!') if answer == 'q' else answer
- try:
- if answer == '':
- print('[!] Question Skipped, Poin -5')
- poin -= 5
- self.losing(poin)
- continue
- elif eval(q) == int(answer):
- poin += 10
- print (f'[-] Benar! Poin kamu: {poin}')
- else:
- print (f'[!] Salah, Jawaban: {eval(q)}. Poin -3')
- poin -= 3
- self.losing(poin)
- except ValueError:
- print('[!] Your input invalid')
- continue
- if __name__=="__main__":
- run = mathquiz(sys.argv[1],sys.argv[2].split('-'))
- run.question()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement