Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,646 members, 7,820,253 topics. Date: Tuesday, 07 May 2024 at 12:11 PM

CBT In Python. V2 By Fleshbone - Programming (2) - Nairaland

Nairaland Forum / Science/Technology / Programming / CBT In Python. V2 By Fleshbone (4643 Views)

Who Wants To Learn Programming In Python Easily Without Stress? READ THIS / *New Video: Data Types and Data Structures in Python [Tutorials] / Web Programming Tutorial In Python. (2) (3) (4)

(1) (2) (Reply) (Go Down)

Re: CBT In Python. V2 By Fleshbone by Nobody: 10:12am On May 29, 2017
TheLordIsGr8:


Hello Kay. I wish to make an observation about your naming scheme.

You created a repository. The name of the repo shouldn't have any extensions. It looks like the repo is a python file which is not the case. The name of your repo should be the project name. I will think something like "Nairaland CBT." The exam part is redundant in so far as T stands for Test. Unless you have something else in mind.

For your code file which you called "The main code", you should give the file a good descriptive name and add an extension. Remember, no spaces in file names. Don't even use dashes. Underscores are your best friend.

Thanks man.. I'll make necessary correction.. It's imperative for one to be conventional about naming ..
Muchas gracias
Re: CBT In Python. V2 By Fleshbone by phililp(m): 6:34pm On May 30, 2017
guys am waiting to see the gui..
Re: CBT In Python. V2 By Fleshbone by Nobody: 12:37am On Jun 07, 2017
phililp:
guys am waiting to see the gui..
Sorry Man, have been quite for some time.. I Just Got hold of some JavaScript Materials to gain more ground as against the Andela both-camp thing(I'm hoping i get called). My time has been going to JavaScript of late.. I Haven't worked on it but i will soonest...Hw far, you applied for the andela fellow... too right?
Re: CBT In Python. V2 By Fleshbone by Nobody: 12:56am On Jun 07, 2017
cc TheLordIsGr8
cc fleshbone

concerning the python GUI using tkinter.. i discovered it takes every input in the Entry widget as letter characters in a string even when integers are solely imputed.. And i couldn't convert it with "int(...)" .Has anyone experienced some stuff like this. Or do we have a way to collect data as input aside the
self.value_entry = Entry(self) 
widget.
Re: CBT In Python. V2 By Fleshbone by phililp(m): 10:39pm On Jun 07, 2017
kayoph:

Sorry Man, have been quite for some time.. I Just Got hold of some JavaScript Materials to gain more ground as against the Andela both-camp thing(I'm hoping i get called). My time has been going to JavaScript of late.. I Haven't worked on it but i will soonest...Hw far, you applied for the andela fellow... too right?


not this circle... i applied the previous but cudnt make it... so am taking my time.. to study python then JS

1 Like

Re: CBT In Python. V2 By Fleshbone by Adex001(m): 12:20pm On Jun 08, 2017
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()
Re: CBT In Python. V2 By Fleshbone by fleshbone(m): 10:06am On Jun 12, 2017
kayoph:
cc TheLordIsGr8
cc fleshbone

concerning the python GUI using tkinter.. i discovered it takes every input in the Entry widget as letter characters in a string even when integers are solely imputed.. And i couldn't convert it with "int(...)" .Has anyone experienced some stuff like this. Or do we have a way to collect data as input aside the
self.value_entry = Entry(self) 
widget.





class lbs2kgs(Frame):
def __init__(self, master = None):
Frame.__init__(self, master)
self.pack()
self.lbs = StringVar()
lbs_entry = Entry(self, width = 7, textvariable = self.lbs)
lbs_entry.pack(side = LEFT)
Label(self, text = "lbs"wink.pack( side = LEFT)
Button(self, text = "Calculate", command = self.calc).pack(side = LEFT)
lbs_entry.focus()
for c in self.master.winfo_children():
c.pack_configure(padx = 5, pady = 5)

def calc(self):
try:
value = float(self.lbs.get())
print "The number of kgs is", 0.453592 * value
except ValueError: pass
if __name__ == "__main__":
lbs2kgs().mainloop()








Sorry for the late reply sir. but am sure this small code above can solve your problem.

Am sorry once again.
Re: CBT In Python. V2 By Fleshbone by Nobody: 4:12pm On Jun 12, 2017
fleshbone:


Sorry for the late reply sir. but am sure this small code above can solve your problem.

Am sorry once again.

Yh thanks bro.. I went on to read the tkinter variable classes today after i saw your post... I think the problem was Using "StringVar"... it was supposed to be "IntVar"... Although i didn't pass any of that earlier in my code.. But i think not specifying the variable makes python take it automatically as a string..



Ah "sir" ke? na you be boss o cheesy .. Thanks man.

1 Like

Re: CBT In Python. V2 By Fleshbone by fleshbone(m): 6:07pm On Jun 12, 2017
kayoph:

Yh thanks bro.. I went on to read the tkinter variable classes today after i saw your post... I think the problem was Using "StringVar"... it was supposed to be "IntVar"... Although i didn't pass any of that earlier in my code.. But i think not specifying the variable makes python take it automatically as a string..



Ah "sir" ke? na you be boss o cheesy .. Thanks man.

Yea! I think yo can also juggle the type by forcing the string into int.

For reason whereby people would still fill a string into and integer field, one can easily control the error without the app crashing due to exceptions!

1 Like

Re: CBT In Python. V2 By Fleshbone by phililp(m): 12:55am On Jun 16, 2017
Adex001:
Philip, the return all... is the variable all a global variable? don't seem to understand that part


return all return everything that is returnable in the function wink
Re: CBT In Python. V2 By Fleshbone by Nobody: 5:22pm On May 27, 2018
Pls can one provide with the best open source online cbt? thanks in anticipation
Re: CBT In Python. V2 By Fleshbone by phililp(m): 7:01pm On May 27, 2018
Was suprised seeing a comment from this thread.. Where are all this my genius...

Meanwhile dude above me, there are tons of online study materials... The question is what do u want to learn
Re: CBT In Python. V2 By Fleshbone by Nobody: 11:35am On May 28, 2018
phililp:
Was suprised seeing a comment from this thread.. Where are all this my genius...

Meanwhile dude above me, there are tons of online study materials... The question is what do u want to learn
Want to setup an online cbt practice center
Re: CBT In Python. V2 By Fleshbone by phililp(m): 10:52pm On May 28, 2018
jovialportal:
Want to setup an online cbt practice center

Alright, goodluck with that undecided

(1) (2) (Reply)

I Need A Thrift Collection Software / Step-by-step Method Of Writing Contiki Programs / Udemy Payment Crisis

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 70
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.