Welcome, guest | Sign In | My Account | Store | Cart

This code is was my first attempt at making a useful program. What it does is store grades in a text file after asking you a few questions like what subject, number of questions right, et cetera.

Python, 49 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#! /usr/bin/python
# keep record of grades. Made by Caleb Herbert. 0.1-PUBLIC
# NOTE! All letter answers are to be written in quotes (including dates)!
print """############################################
# Welcome to Gradebook! v 0.1              # 
# YOUR LIGHT WEIGHT SCHOOL RECORD MANAGER! #
############################################"""              
subject = raw_input("What is your assignment's subject? ")
# ^^This asks your class subject; assigns it to 'subject'; and is used later. 
date = input('What is the date for your assignment? ')
# ^^This is pretty much the same: but asks the date.
amount = input('What is the number of questions? (NOTE: make all #s from now decimals. e.g.: "5.0" ')
# ^^^This is also the same, but make the number a DECIMAL!
correct = input('How many questions did you get correct? ')
# ^^^The same... make all DECIMALS!
calc = divmod(correct, amount)
#  This is a nice homework trick. Divides correct by amount, assigns to 'calc'
calcx = (correct / amount)
# divides correct by amount; assigns to 'calcx'
text = "***%s*** \n %s | %d out of %d | %s or %s \n" % (date, subject, correct, amount, calc, calcx) 
# creates what will be in your file. assigns to 'text'
print text
# prints what it will put in your file (or append).
fle = raw_input('What should I name the file to put the above data into? ')
# prompts for a filename 
A = input('Do you want this to be appended to an existing file? ') 
# decides to either append,or to create new file. assigns answer to 'A'
print 'Thanks! appending to file... '
if A is 'yes': #if you answered yes:
    fyl = open(fle, 'a')
# the phrase 'fyl' is used to combine open('fle, 'a') with future commands
    fyl.write(text)
# the command assigned to 'fyl' writes your data to the filename you said.
    fyl.close()
# closes the file; job is done.
elif A is 'no': # if you said no, this will happen:
    fyl = open(fle, 'w')
# same as before, but saves the file (see the 'w' instead of 'a'?)
    fyl.write(text)
# same
    fyl.close()
# same
else: # and if nothing was valid...
    print 'Error! Invalid transaction! '
# ...error message! 
print 'Done!'
# says it is done
raw_input("Press <RETURN> to quit.")
# makes you type <enter> to quit.

I am thinking of making this script create a LaTeX file to store your grades in. This way, you will be able to look at them in a nice clean table to be ready to print as a reference. I should be able to easily remaster it into a GUI program in no time -- so long as I can find myself a great big list of keywords and methods. Another thing: I might make an Esperanto version of this (that way, I can ask for 40 translations by native Chinese speakers or something.)

Well, this should be useful when showing what stuff you have done to your teacher without having to give tell her all of the time -- you can just store it on the Web for her to go to and see the updates... (Ooh! I may want to add an 'e-mail' or 'publish to web' function!).

If anyone would like to make a thing like this for the iPhone and iPod, let me know - because I don't know C/Objective-C and would like to see how it would be written.

2 comments

onur ozbalc─▒ 13 years, 8 months ago  # | flag

smt simple. i m very new to computer programming.how can you call back the files you stored with your script and how you name them with .py extension or smt different?thx

Caleb Herbert (author) 12 years, 10 months ago  # | flag

onur ozbalci:

Please excuse me for not replying sooner -- I hope you had a happy New Year!

"How can you call back files you stored with your script ..."

If what you mean by 'call back files' is 'read the file you just created within the program', then I don't know right now straight off of the bat. I

haven't put the feature in this script, but you can learn about handling files in Python (such as saving, reading, printing, etc.) at

http://www.devshed.com/c/a/Python/File-Management-in-Python/.

"... and how do you name them with a '.py' extension, or something different?"

Okay -- open my file or a different Python script in Notepad that is named wrong.

Go to 'File'> 'Save as...' and then while making sure that 'Hide extension' (or something similar) is unchecked, just make the file's name 'SOMETHING.py'. It isn't hard.

Thanks, Caleb

P.S. -- Remember the Sage's wise words: "Google's your friend." Also check out: http://letmegooglethatforyou.com/?q=file+management+with+python&l=1 -- it is pretty cool!

Created by Caleb Herbert on Tue, 22 Jan 2008 (PSF)
Python recipes (4591)
Caleb Herbert's recipes (1)

Required Modules

  • (none specified)

Other Information and Tasks