Philip, the return all... is the variable all a global variable? don't seem to understand that part
phililp:
hi guys... about a week ago. fleshbone shared with us his first CBT code.. in python 2.7
so i re-wrote the code in python 3...
here it is...
wasnt good as the first though..
pls its open to criticism.. thanks
from time import *
import random
def name():
student_name = str(input('please enter your name:'))
print('Welcome ', student_name, ' wait a while lets get you logged in.')
sleep(2)
return student_name
def chemistry():
questions = {1: ['question 1\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'a'],
2: ['question two\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'b'],
3: ['question three\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'c',],
4: ['question four\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'b'],
5: ['question five\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'd']}
score = 0
answer_char = ['a', 'b', 'c', 'd',]
for i in questions:
quest = questions[i]
print('\n', i,'.', quest[0])
answer = str(input('enter anser here:\n'))
answer = answer.lower()
while answer not in answer_char:
print('only enter one of the options above')
answer = str(input('enter anser here:\n'))
answer = answer.lower()
else:
answer = answer.lower()
if answer == quest[1]:
score += 2
else: pass
print ('your score is:', score)
return all
def mathematics():
questions = {1: ['question 1\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'a'],
2: ['question two\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'b'],
3: ['question three\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'c',],
4: ['question four\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'b'],
5: ['question five\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'd']}
score = 0
answer_char = ['a', 'b', 'c', 'd',]
for i in questions:
quest = questions[i]
print('\n', i,'.', quest[0])
answer = str(input('enter anser here:\n'))
answer = answer.lower()
while answer not in answer_char:
print('only enter one of the options above')
answer = str(input('enter anser here:\n'))
answer = answer.lower()
else:
answer = answer.lower()
if answer == quest[1]:
score += 2
else: pass
print ('you scored', score)
return all
def geography():
questions = {1: ['question 1\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'a'],
2: ['question two\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'b'],
3: ['question three\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'c',],
4: ['question four\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'b'],
5: ['question five\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'd']}
score = 0
answer_char = ['a', 'b', 'c', 'd',]
for i in questions:
quest = questions[i]
print('\n', i,'.', quest[0])
answer = str(input('enter anser here:\n'))
answer = answer.lower()
while answer not in answer_char:
print('only enter one of the options above')
answer = str(input('enter anser here:\n'))
answer = answer.lower()
else:
answer = answer.lower()
if answer == quest[1]:
score += 2
else: pass
print ('you score ', score)
return all
def economics():
questions = {1: ['question 1\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'a'],
2: ['question two\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'b'],
3: ['question three\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'c',],
4: ['question four\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'b'],
5: ['question five\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'd']}
score = 0
answer_char = ['a', 'b', 'c', 'd',]
for i in questions:
quest = questions[i]
print('\n', i,'.', quest[0])
answer = str(input('enter anser here:\n'))
answer = answer.lower()
while answer not in answer_char:
print('only enter one of the options above')
answer = str(input('enter anser here:\n'))
answer = answer.lower()
else:
answer = answer.lower()
if answer == quest[1]:
score += 2
else: pass
print ('you scored ', score)
return all
def agricultural_science():
questions = {1: ['question 1\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'a'],
2: ['question two\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'b'],
3: ['question three\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'c',],
4: ['question four\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'b'],
5: ['question five\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'd']}
score = 0
answer_char = ['a', 'b', 'c', 'd',]
for i in questions:
quest = questions[i]
print('\n', i,'.', quest[0])
answer = str(input('enter anser here:\n'))
answer = answer.lower()
while answer not in answer_char:
print('only enter one of the options above')
answer = str(input('enter anser here:\n'))
answer = answer.lower()
else:
answer = answer.lower()
if answer == quest[1]:
score += 2
else: pass
print ('you scored', score)
return all
def physics():
questions = {1: ['question 1\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'a'],
2: ['question two\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'b'],
3: ['question three\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'c',],
4: ['question four\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'b'],
5: ['question five\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'd']}
score = 0
answer_char = ['a', 'b', 'c', 'd',]
for i in questions:
quest = questions[i]
print('\n', i,'.', quest[0])
answer = str(input('enter anser here:\n'))
answer = answer.lower()
while answer not in answer_char:
print('only enter one of the options above')
answer = str(input('enter anser here:\n'))
answer = answer.lower()
else:
answer = answer.lower()
if answer == quest[1]:
score += 2
else: pass
print ('you scored ', score)
return all
def english():
questions = {1: ['question 1\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'a'],
2: ['question two\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'b'],
3: ['question three\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'c',],
4: ['question four\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'b'],
5: ['question five\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'd']}
score = 0
answer_char = ['a', 'b', 'c', 'd',]
for i in questions:
quest = questions[i]
print('\n', i,'.', quest[0])
answer = str(input('enter anser here:\n'))
answer = answer.lower()
while answer not in answer_char:
print('only enter one of the options above')
answer = str(input('enter anser here:\n'))
answer = answer.lower()
else:
answer = answer.lower()
if answer == quest[1]:
score += 2
else: pass
print ('you scored ', score)
return all
def biology():
questions = {1: ['question 1\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'a'],
2: ['question two\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'b'],
3: ['question three\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'c',],
4: ['question four\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'b'],
5: ['question five\n(A)option A here\n(B)option B here\n(C)option C here\n(D)option D here', 'd']}
score = 0
answer_char = ['a', 'b', 'c', 'd',]
for i in questions:
quest = random.choice(questions.values())
print('\n', i,'.', quest[0])
answer = str(input('enter anser here:\n'))
answer = answer.lower()
while answer not in answer_char:
print('only enter one of the options above')
answer = str(input('enter anser here:\n'))
answer = answer.lower()
else:
answer = answer.lower()
if answer == quest[1]:
score += 2
else: pass
print ('your score is ', score)
return all
def subject_selector():
print('please select the subject you want to start with\n')
subject = str(input('enter A - for Arigultural Science\n'
'enter B - for Biology\n'
'enter M - for Mathematics\n'
'enter C - for Chemistry\n'
'enter P - for Physics\n'
'enter G - for Geography\n'
'enter Eng - for English\n'
'enter Eco - for Economics\n:'))
subject = subject.lower()
choice_char = ['a', 'b', 'm', 'c', 'p', 'g', 'eng', 'eco']
while subject not in choice_char:
print('please select either', str(choice_char))
subject = str(input('enter A - for Arigultural Science\n'
'enter B - for Biology\n'
'enter M - for Mathematics\n'
'enter C - for Chemistry\n'
'enter P - for Physics\n'
'enter G - for Geography\n'
'enter Eng - for English\n'
'enter Eco - for Economics\n:'))
else:
if subject == 'a':
agricultural_science()
elif subject == 'b':
biology()
elif subject == 'm':
mathematics()
elif subject == 'c':
chemistry()
elif subject == 'p':
physics()
elif subject == 'g':
geography()
elif subject == 'eng':
english()
elif subject == 'eco':
economics()
return all
name()
subject_selector()