[Tutor] searching data from a list read from a file

2011-05-15 Thread Lea Parker
Hello J

 

When you have time I would like some advice on where to go. I have created a
program that reads charge account numbers from a file. The user is to enter
a charge account number from the list presented and the program should then
tell them whether they have entered a valid or invalid number. My problem at
this stage (and yes there a probably more than this one), is when I run the
program it tells me the charge account number is always invalid even when I
put a correct number in. Below is my code because I am thinking that perhaps
it is an indent issue maybe.

 

This program reads the contents of a file into a list. Asks the user

to enter a charge account number and will determine the validity of the

number entered to return a message of either valid or invalid.

 

Written by: Leonie Parker 11428070

Subject:ITC Principles of programming

Assignment: 2b

 

def main():

try:

# Open file for reading

infile = open('charge_accounts.txt', 'r')

 

# Read the contents of the file inot a lsit

account_number = infile.readlines()

 

#Convert each element into an int

index = 0

while index != len(account_number):

account_number[index] = int(account_number[index])

index += 1

 

# Print the contents of the list

print account_number

 

#Get an account number to search for

search = raw_input('Enter a charge account number: ')

 

#Determine whether the product number is in thelist

if search in account_number:

print search, 'charge account number is VALID'

else:

print search, 'charge account number is INVALID'

 

infile.close()



except ValueError:

print 'file open error message'

  

#Call the main function

main()

 

 

 

Thanks in advance 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Help with exceptions please

2011-05-13 Thread Lea Parker
Hello

 

I have another assignment I am trying to fine tune. The idea is to make sure
exceptions work. I have come up with a problem when testing my code. When I
enter a golf score for a player the program returns the 'error that has
occurred'. I only want it to do this if someone doesn't enter an number.

 

Could I have some comments on my code for the first program of my assignment
if you have some time please. 

 

Assignment Question:  The Springfork Amateur Golf club has a tournament
every weekend.

The club president has asked you to write two programs:

1. A program that will read each player's name and golf score as keyboard

input and then to save these records in a file named golf.txt. (Each record

will have a field name for the player's name and a field for the player's

score.

2. A program that reads the records from the golf.txt and displays them.

 

 

 

def main():

 

try:

# Get the number of players

golf_scores = int(raw_input('How many players playing this weekend?
'))

 

# Open a file to hold player names and scores

player_data = open('golf.txt', 'w')

 

# Get the players name and score and write it to the file

for count in range(1, golf_scores + 1):

# Get the name name and score for player

print 'Enter the name and score for player #' + str(count)

name = raw_input('Name: ')

score = int(raw_input('Score: '))



# Write the data as a record to the file golf.txt

player_data.write(name + '\n')

player_data.write(score + '\n')

 

# Display a blank line

print

 

# Close the file

player_data.close()

print 'Players and their score have been written to golf.txt.'

 

except IOError:

print 'An error occured trying to write information to file.'

 

except ValueError:

print 'A numberic value must be entered.'

 

except:

print 'An error occured.'

 

 

 

# Call the main function

main()

 

Thanks in advance.

Lea

 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Fixed help with exceptions (Lea Parker)

2011-05-13 Thread Lea Parker
Thank you, Wayne gave me a suggestion which helped me relook at things and
correct the problem I presented. This has added other food for thought for
me such as not allowing the program to accept negative inputs for the score
however, I will have a play to see if I can fix this first and then ask
again if I cannot.

Thanks again.

Lea

-Original Message-
From: tutor-bounces+lea-parker=bigpond@python.org
[mailto:tutor-bounces+lea-parker=bigpond@python.org] On Behalf Of
tutor-requ...@python.org
Sent: Saturday, 14 May 2011 12:58 PM
To: tutor@python.org
Subject: Tutor Digest, Vol 87, Issue 44

Send Tutor mailing list submissions to
tutor@python.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/tutor
or, via email, send a message with subject or body 'help' to
tutor-requ...@python.org

You can reach the person managing the list at
tutor-ow...@python.org

When replying, please edit your Subject line so it is more specific than
Re: Contents of Tutor digest...


Today's Topics:

   1. Re: short url processor (ian douglas)
   2. Help with exceptions please (Lea Parker)
   3. Re: short url processor (ian douglas)
   4. Re: Overriding a method in a class (Terry Carroll)


--

Message: 1
Date: Fri, 13 May 2011 17:42:31 -0700
From: ian douglas ian.doug...@iandouglas.com
To: Alan Gauld alan.ga...@btinternet.com
Cc: tutor@python.org
Subject: Re: [Tutor] short url processor
Message-ID: 4dcdcff7.5010...@iandouglas.com
Content-Type: text/plain; charset=iso-8859-1; Format=flowed

On 05/13/2011 05:03 PM, Alan Gauld wrote:
 How do you know they are going to stdout? Are you sure they aren't 
 going to stderr and stderrr is not mapped to stdout (usually the 
 default). Have you tried redirecting stderr to a file for example?

 As I say, just some thoughts,


Thanks for your thoughts, Alan. I had done some testing with cmdline
redirects and forget which is was, I think my debug log was going to stdout
and the apache-style log was going to stderr, or the other way around...

After a handful of guys in the #python IRC channel very nearly convinced me
that all but 3 stdlib libraries are utter worthless crap, and telling me to
download and use third-party frameworks just to fix a simple logging issue,
I overrode log_request() and log message() as such:

class clientThread(BaseHTTPRequestHandler): #[[[

 def log_request(code, size):
 return

 def log_message(self, format, *args):
 open(LOGFILE, a).write(%s\n % (format%args))


... and now the only logging going on is my own, and it's logged to my
external file. Overriding log_request means that BaseHTTPServer no longer
outputs its apache-style log, and overriding log_message means my other
logging.info() and logging.debug() messages go out to my file as expected.

-id

-- next part --
An HTML attachment was scrubbed...
URL:
http://mail.python.org/pipermail/tutor/attachments/20110513/b45aa5f8/attach
ment-0001.html

--

Message: 2
Date: Sat, 14 May 2011 10:48:51 +1000
From: Lea Parker lea-par...@bigpond.com
To: tutor@python.org
Subject: [Tutor] Help with exceptions please
Message-ID: 001201cc11d0$b1912150$14b363f0$@bigpond.com
Content-Type: text/plain; charset=us-ascii

Hello

 

I have another assignment I am trying to fine tune. The idea is to make sure
exceptions work. I have come up with a problem when testing my code. When I
enter a golf score for a player the program returns the 'error that has
occurred'. I only want it to do this if someone doesn't enter an number.

 

Could I have some comments on my code for the first program of my assignment
if you have some time please. 

 

Assignment Question:  The Springfork Amateur Golf club has a tournament
every weekend.

The club president has asked you to write two programs:

1. A program that will read each player's name and golf score as keyboard

input and then to save these records in a file named golf.txt. (Each record

will have a field name for the player's name and a field for the player's

score.

2. A program that reads the records from the golf.txt and displays them.

 

 

 

def main():

 

try:

# Get the number of players

golf_scores = int(raw_input('How many players playing this weekend?
'))

 

# Open a file to hold player names and scores

player_data = open('golf.txt', 'w')

 

# Get the players name and score and write it to the file

for count in range(1, golf_scores + 1):

# Get the name name and score for player

print 'Enter the name and score for player #' + str(count)

name = raw_input('Name: ')

score = int(raw_input('Score: '))



# Write the data as a record to the file golf.txt

player_data.write(name + '\n

[Tutor] return values function

2011-04-22 Thread Lea Parker
Hello

 

I am hoping someone can put me on the right track. The code below includes
the assignment question at the beginning.

 

I seem to have been able to calculate average ok, but what I can't seem to
do is sort it so it will return a grade for each result.

 

Can you give me some advice to head me in the right direction please. My
code is:

 

Write a program that asks the user to enter 5 sets tests scores. The
program

should then display the 'letter grade' (A, B, C, D, F) for each test score,
and

the overall average test schore. Write the following functions in the
program:

* Calc_average: This function should take five test scores as parameters,
and

return the average score.

*determine_grade; this function should take a single test score as a
parameter,

and return a letter grade for the test. The letter grade should be on the

following grade scale: 90-100: A, 80-89: B, 70-79: C, 60-69: D, 60: F. 

 

 

def main():

 

#Get users first test result

test1 = int(raw_input('Enter the score for test 1: '))



#Get users second test result

test2 = int(raw_input('Enter the score for test 2: '))



#Get users third test result

test3 = int(raw_input('Enter the score for test 3: '))



#Get users forth test result

test4 = int(raw_input('Enter the score for test 4: '))



#Get users fifth test result

test5 = int(raw_input('Enter the score for test 5: '))

 

#Get the sum of the test results

cal_average = sum(test1, test2, test3, test4, test5)/5

 

#Display the total of tests

print 'Together your tests average is: ', cal_average

print 'Your grade is: ', grade

 

# The sum function to total all tests

def sum(test1, test2, test3, test4, test5):

result = test1 + test2 + test3 + test4 + test5

return result

 

 

def determine_grade(score):

#Determine the grade for each score

if score 101 and score 89:

score = A

elif score 90 and score 79:

score = B

elif score 80 and score 69:

score = C

elif score 70 and score 59:

score = D

else:

score = F

return score

 

 

 

# Call the main function

main()

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] return values function thanks

2011-04-22 Thread Lea Parker
Hi Alan

Thanks once again for your help.

Lea

-Original Message-
From: tutor-bounces+lea-parker=bigpond@python.org
[mailto:tutor-bounces+lea-parker=bigpond@python.org] On Behalf Of
tutor-requ...@python.org
Sent: Friday, 22 April 2011 5:32 PM
To: tutor@python.org
Subject: Tutor Digest, Vol 86, Issue 77

Send Tutor mailing list submissions to
tutor@python.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/tutor
or, via email, send a message with subject or body 'help' to
tutor-requ...@python.org

You can reach the person managing the list at
tutor-ow...@python.org

When replying, please edit your Subject line so it is more specific than
Re: Contents of Tutor digest...


Today's Topics:

   1. Re: Jokes on Python Language (Marc Tompkins)
   2. Re: learnpython.org - Free Interactive Python Tutorial
  (Ron Reiter)
   3. Re: Plotting a Linear Equation (Alan Gauld)
   4. return values function (Lea Parker)
   5. Re: return values function (Alan Gauld)


--

Message: 1
Date: Thu, 21 Apr 2011 13:35:38 -0700
From: Marc Tompkins marc.tompk...@gmail.com
To: tutor@python.org
Subject: Re: [Tutor] Jokes on Python Language
Message-ID: banlktinh4ddbshb1t6nlodvqdevxndu...@mail.gmail.com
Content-Type: text/plain; charset=iso-8859-1

On Thu, Apr 21, 2011 at 4:49 AM, Ratna Banjara mast.ra...@gmail.com wrote:

 Hello all,

 Does anybody knows jokes related to Python Language?
 If the answer is yes, please do share it...


Of course, there's the AWESOME webcomic xkcd (www.xkcd.com) which is
excellent reading even when he's not talking about Python... but in
particular, there are several great strips about Python itself (or at least,
they mention Python in a fond way):

http://xkcd.com/353/
http://xkcd.com/413/
http://xkcd.com/409/
http://xkcd.com/521/
-- next part --
An HTML attachment was scrubbed...
URL:
http://mail.python.org/pipermail/tutor/attachments/20110421/43418337/attach
ment-0001.html

--

Message: 2
Date: Thu, 21 Apr 2011 20:22:39 +0300
From: Ron Reiter ron.rei...@gmail.com
To: tutor@python.org
Subject: Re: [Tutor] learnpython.org - Free Interactive Python
Tutorial
Message-ID: banlktimcdlrfibq5cbqhlpcyzsbfthm...@mail.gmail.com
Content-Type: text/plain; charset=iso-8859-1

For those of you who didn't notice the title, here is the link:
www.learnpython.org

Also, please note that there is still not enough content to actually learn
from the website yet. I am hoping people will help me with writing tutorials
so the site will be useful as soon as possible.

On Wed, Apr 20, 2011 at 9:16 PM, Ron Reiter ron.rei...@gmail.com wrote:

 Hey.

 I've created a website for learning Python interactively online. Check 
 it out, and I would really appreciate it if you can also contribute
tutorials.

 Thanks!

 --
 -- Ron




--
-- Ron
-- next part --
An HTML attachment was scrubbed...
URL:
http://mail.python.org/pipermail/tutor/attachments/20110421/dad10c29/attach
ment-0001.html

--

Message: 3
Date: Thu, 21 Apr 2011 22:40:51 +0100
From: Alan Gauld alan.ga...@btinternet.com
To: tutor@python.org
Subject: Re: [Tutor] Plotting a Linear Equation
Message-ID: ioq891$6pq$1...@dough.gmane.org
Content-Type: text/plain; format=flowed; charset=iso-8859-1;
reply-type=original

Emanuel Woiski woi...@gmail.com wrote

 easy:

I love your sense of humour!

 import pylab as pl
 import numpy as np
 x1,x2,n,m,b = 0.,10.,11,2.,5.
 x = np.r_[x1:x2:n*1j]
 pl.plot(x,m*x + b); pl.grid(); pl.show()

Now, given this is a list for beginners to Python, could you try explaining
what you did there and how the OP, or anyone else for that matter, might use
it?

Or were you really just trying to establish that if you try hard you can
write Python that is as difficult to read as Perl?

  I want to use matplotlib (or similar) to plot an equation in
  (y=mx+b) or standard form (Ax + By = C).  I could make  two points 
 out of those manually, but I was wondering if anyone knew of  an 
 easier way. Thanks.

Alan G.




--

Message: 4
Date: Fri, 22 Apr 2011 16:59:18 +1000
From: Lea Parker lea-par...@bigpond.com
To: tutor@python.org
Subject: [Tutor] return values function
Message-ID: 000301cc00ba$ccffb950$66ff2bf0$@bigpond.com
Content-Type: text/plain; charset=us-ascii

Hello

 

I am hoping someone can put me on the right track. The code below includes
the assignment question at the beginning.

 

I seem to have been able to calculate average ok, but what I can't seem to
do is sort it so it will return a grade for each result.

 

Can you give me some advice to head me in the right direction please. My
code is:

 

Write a program that asks the user to enter 5 sets tests scores. The
program

should then display the 'letter grade' (A, B, C, D, F) for each

[Tutor] Help - accumulator not working (Lea)

2011-04-15 Thread Lea Parker
Hello

 

I am trying to create this program for a uni assignment. I cannot get it to
add the expenses to the accumulator I have set. Would you mind having a look
and letting me know if I have something in the wrong place or indented
incorrectly. Perhaps I am missing something.

 

There could be other things wrong but I need to fix this first and then I
can focus on the next thing. I have difficulty trying to fix lots of things
at once so if you could just comment on the problem and I will ask again if
I can't work out the next problem I have. I like to have a go myself first.
J

 

My code is:

 

This program is to calculate if the user is over or under budget

for the month

 

 

def main():

  

# Create an accumulator

total_expense = 0.0

 

# Ask user for the monthly budget

budget = float(raw_input('Enter the amount of your budget for the month:
$'))



 

# Calculate a series of expenses

expense = float(raw_input('Enter your first expense $'))



 # Accumlate expense

total_expense = total_expense + expense

 

# Continue processing as long as the user

# does not enter 0

while expense != 0:

 

#Get another expense

expense = float(raw_input('Enter the next expense or 0 to finish
$'))

   

#Calculate surplus

surplus = budget - total_expense

 

#Display results

print 'Your total expenses for the month $', total_expense

print 'Your surplus amount after expenses $', surplus

 

# Call the main function.

main()

 

Thank you.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] than Re: Contents of Tutor digest... Tutor Digest, Vol 86, Issue 56

2011-04-15 Thread Lea Parker
Thank you message 4 this has solved my problem I can now work out the next
part of my program. Thank you so much.

-Original Message-
From: tutor-bounces+lea-parker=bigpond@python.org
[mailto:tutor-bounces+lea-parker=bigpond@python.org] On Behalf Of
tutor-requ...@python.org
Sent: Saturday, 16 April 2011 8:47 AM
To: tutor@python.org
Subject: Tutor Digest, Vol 86, Issue 56

Send Tutor mailing list submissions to
tutor@python.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/tutor
or, via email, send a message with subject or body 'help' to
tutor-requ...@python.org

You can reach the person managing the list at
tutor-ow...@python.org

When replying, please edit your Subject line so it is more specific than
Re: Contents of Tutor digest...


Today's Topics:

   1. Help to explain commenting (Andr?s Chand?a)
   2. Re: Python on TV (Alan Gauld)
   3. Help - accumulator not working (Lea) (Lea Parker)
   4. Re: Help - accumulator not working (Lea) (Joel Goldstick)


--

Message: 1
Date: Fri, 15 Apr 2011 18:21:43 +0200
From: Andr?s Chand?a and...@chandia.net
Subject: [Tutor] Help to explain commenting
Message-ID:
957d7e2abbfe95f19b83cef056261697.squir...@mail.chandia.net
Content-Type: text/plain; charset=iso-8859-1



Hello everybody,
I could finally complete succesfully the code I was working with. As I'm
quite new to python, many of the things I have in my code are copied from
different sources, and I do not undertand all of them, well, I have to
deliver this code for a project, and in the best documented way that I
could, I already commented all that I know, and I suppouse wrongly in some
parts.

So the request is, if you can take a look at the code, comment the parts
that are not yet commented, correct the errors, and propouse some
improvement in the parts you think diserves it.

I attach the code in a tgz file, if
the attached can not be seen then this link: 
http://www.chandia.net/compart/NMT-2.4-20110415.tar.gz

Thanks in advance to all
of you and to the people that already helped me.
___
andr?s
chand?a

P
No imprima innecesariamente. ?Cuide el medio ambiente!
-- next part --
A non-text attachment was scrubbed...
Name: NMT-2.4-20110415.tar.gz
Type: application/x-gzip
Size: 4177 bytes
Desc: not available
URL:
http://mail.python.org/pipermail/tutor/attachments/20110415/937a8c20/attach
ment-0001.bin

--

Message: 2
Date: Fri, 15 Apr 2011 20:35:14 +0100
From: Alan Gauld alan.ga...@btinternet.com
To: tutor@python.org
Subject: Re: [Tutor] Python on TV
Message-ID: ioa6lh$sb7$1...@dough.gmane.org
Content-Type: text/plain; format=flowed; charset=iso-8859-1;
reply-type=response

bob gailer bgai...@gmail.com wrote

 The show should be here - Pause at 1 minute 20 for the Python 
 screnshot:

 http://fwd.channel5.com/gadget-show/videos/challenge/surprise-special
 -part-4

 I am told the video ... cannot be viewed from your currrent country 
 ...

I don't know if YouTube will be any more obliging but try this:

http://www.youtube.com/watch?v=oDNZP1X30WElist=SL

Python can be seen at around 29 mins 45 secs...

Enjoy (I hope)

Alan G.




--

Message: 3
Date: Sat, 16 Apr 2011 07:52:22 +1000
From: Lea Parker lea-par...@bigpond.com
To: tutor@python.org
Subject: [Tutor] Help - accumulator not working (Lea)
Message-ID: 01cbfbb7$666bd140$334373c0$@bigpond.com
Content-Type: text/plain; charset=us-ascii

Hello

 

I am trying to create this program for a uni assignment. I cannot get it to
add the expenses to the accumulator I have set. Would you mind having a look
and letting me know if I have something in the wrong place or indented
incorrectly. Perhaps I am missing something.

 

There could be other things wrong but I need to fix this first and then I
can focus on the next thing. I have difficulty trying to fix lots of things
at once so if you could just comment on the problem and I will ask again if
I can't work out the next problem I have. I like to have a go myself first.
J

 

My code is:

 

This program is to calculate if the user is over or under budget

for the month

 

 

def main():

  

# Create an accumulator

total_expense = 0.0

 

# Ask user for the monthly budget

budget = float(raw_input('Enter the amount of your budget for the month:
$'))



 

# Calculate a series of expenses

expense = float(raw_input('Enter your first expense $'))



 # Accumlate expense

total_expense = total_expense + expense

 

# Continue processing as long as the user

# does not enter 0

while expense != 0:

 

#Get another expense

expense = float(raw_input('Enter the next expense or 0 to finish
$'))

   

#Calculate surplus

surplus = budget

Re: [Tutor] Contents of Tutor digest Vol 86 Issue 57

2011-04-15 Thread Lea Parker
Hi  Michael Scott

Thank you and yes I agree there is room for user error. I am going to add a
validator but I wanted to get the first part right. I appreciate your
comment on the white space too.

Being a beginner I find it easier to write the main thing I want the code to
do and then add extra to make it work efficiently. Perhaps not what a
programmer does but it helps me this way.

Thanks so much.

Leonie

-Original Message-
From: tutor-bounces+lea-parker=bigpond@python.org
[mailto:tutor-bounces+lea-parker=bigpond@python.org] On Behalf Of
tutor-requ...@python.org
Sent: Saturday, 16 April 2011 9:43 AM
To: tutor@python.org
Subject: Tutor Digest, Vol 86, Issue 57

Send Tutor mailing list submissions to
tutor@python.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/tutor
or, via email, send a message with subject or body 'help' to
tutor-requ...@python.org

You can reach the person managing the list at
tutor-ow...@python.org

When replying, please edit your Subject line so it is more specific than
Re: Contents of Tutor digest...


Today's Topics:

   1. Re: Help - accumulator not working (Lea) (michael scott)
   2. Re: Help - accumulator not working (Lea) (Alan Gauld)
   3. Re: than Re: Contents of Tutor digest... Tutor Digest,  Vol
  86, Issue 56 (Lea Parker)


--

Message: 1
Date: Fri, 15 Apr 2011 15:46:32 -0700 (PDT)
From: michael scott jigenbak...@yahoo.com
To: tutor@python.org
Subject: Re: [Tutor] Help - accumulator not working (Lea)
Message-ID: 670739.27615...@web130203.mail.mud.yahoo.com
Content-Type: text/plain; charset=utf-8

Hi Lea, how are you today?

Well please keep in mind that nothing is wrong with your code,  its doing
exactly what you asked it to do. But I would call your attention to  your
while loop, you want to accumulate things, but may I ask exactly what are
you accumulating in your loop?

Also quite by accident I entered 00 as my budget and I got a negative
surplus, lol. Perhaps you should implement something that ensures that a
(stupid) user like myself does not enter a 0- or negative value for the
budget. Just a thought...

To help me attempt to understand the small programs I write, I pretend that
I'm the computer and I literally compute  the program as if I was the
interpreter, I follow each line of my code to truly understand it. Perhaps
with these gentle nudges you will solve your problem :)

 
What is it about you... that intrigues me so?





From: Lea Parker lea-par...@bigpond.com
To: tutor@python.org
Sent: Fri, April 15, 2011 5:52:22 PM
Subject: [Tutor] Help - accumulator not working (Lea)


Hello
 
I am trying to create this program for a uni assignment. I cannot get it to
add the expenses to the accumulator I have set. Would you mind having a look
and letting me know if I have something in the wrong place or indented
incorrectly. 
Perhaps I am missing something.
 
There could be other things wrong but I need to fix this first and then I
can focus on the next thing. I have difficulty trying to fix lots of things
at once so if you could just comment on the problem and I will ask again if
I can?t work out the next problem I have. I like to have a go myself first.
J
 
My code is:
 
This program is to calculate if the user is over or under budget for the
month
 
 
def main():
  
# Create an accumulator
total_expense = 0.0
 
# Ask user for the monthly budget
budget = float(raw_input('Enter the amount of your budget for the month:

$'))

 
# Calculate a series of expenses
expense = float(raw_input('Enter your first expense $'))

 # Accumlate expense
total_expense = total_expense + expense
 
# Continue processing as long as the user
# does not enter 0
while expense != 0:
 
#Get another expense
expense = float(raw_input('Enter the next expense or 0 to finish
$'))
   
#Calculate surplus
surplus = budget - total_expense
 
#Display results
print 'Your total expenses for the month $', total_expense
print 'Your surplus amount after expenses $', surplus
 
# Call the main function.
main()
 
Thank you.
-- next part --
An HTML attachment was scrubbed...
URL:
http://mail.python.org/pipermail/tutor/attachments/20110415/d62c34c3/attach
ment-0001.html

--

Message: 2
Date: Sat, 16 Apr 2011 00:27:22 +0100
From: Alan Gauld alan.ga...@btinternet.com
To: tutor@python.org
Subject: Re: [Tutor] Help - accumulator not working (Lea)
Message-ID: ioak8p$4sq$1...@dough.gmane.org
Content-Type: text/plain; format=flowed; charset=iso-8859-1;
reply-type=original


Lea Parker lea-par...@bigpond.com wrote

 I am trying to create this program for a uni assignment. I cannot get 
 it to add the expenses to the accumulator I have set.

You have

[Tutor] Help - 2nd validator won't work

2011-04-15 Thread Lea Parker
Hello

 

I now need to get the validator to work on my expense input. If the user
puts in a negative I want an error to come up. I have managed it for the
budget input but cannot seem to get it to work for the expense.

 

Thanks in advance again for your  wonderful help.

 

 

 

This program is to calculate if the user is over or under budget

for the month

 

 

def main():

  

# Create an accumulator

total_expense = 0.00

   

 

# Ask user for the monthly budget

budget = float(raw_input('Enter the amount of your budget for the month:
'))

# Validation variable for budget

while budget 0:

print 'ERROR: the budget cannot be a negative amount'

budget = float(raw_input('Enter the correct budget for the month:
'))



 

# Ask user for expense

expense = float(raw_input('Enter your first expense '))

total_expense += expense



# Continue processing as long as the user does not enter 0

while expense != 0:

 

#Get another expense

expense = float(raw_input('Enter expense or 0 to finish '))

total_expense += expense

   



# Validation variable for expense

while expense 0:

print 'ERROR: the budget cannot be a negative amount'

expense = float(raw_input('Enter the correct budget for the
month: '))

total_expense += expense





#Calculate surplus

budget_difference = budget - total_expense

 

#Display results

print 'Your total expenses for the month ', total_expense

if budget_difference=0:

print 'You are under budget by ', budget_difference, 'dollars.'

else:

print 'You are over budget by ', budget_difference, 'dollars.' 

 

# Call the main function.

main()

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 85, Issue 91

2011-03-25 Thread Lea Parker
Message 3 - I solved my problem. Yah Me!!!

Thanks 

P.S I hope this is the right way to let you know so you don't waste  your
time.

Lea

-Original Message-
From: tutor-bounces+lea-parker=bigpond@python.org
[mailto:tutor-bounces+lea-parker=bigpond@python.org] On Behalf Of
tutor-requ...@python.org
Sent: Friday, 25 March 2011 4:28 PM
To: tutor@python.org
Subject: Tutor Digest, Vol 85, Issue 91

Send Tutor mailing list submissions to
tutor@python.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/tutor
or, via email, send a message with subject or body 'help' to
tutor-requ...@python.org

You can reach the person managing the list at
tutor-ow...@python.org

When replying, please edit your Subject line so it is more specific than
Re: Contents of Tutor digest...


Today's Topics:

   1. Re: Guessing Game Program (Malcolm Newsome)
   2. Re: Guessing Game Program (Donald Bedsole)
   3. Error in programming (Lea Parker)


--

Message: 1
Date: Thu, 24 Mar 2011 23:37:18 -0500
From: Malcolm Newsome malcolm.news...@gmail.com
To: 'Donald Bedsole' drbeds...@gmail.com,   Tutor@python.org
Subject: Re: [Tutor] Guessing Game Program
Message-ID: 00f401cbeaa6$54049bd0$fc0dd370$@gmail.com
Content-Type: text/plain;   charset=us-ascii

Hey Don!

I posted an eerily similar request to another python group about two weeks
ago!  I, too, am very new to programming and the guessing game was my first
shot at writing a script from scratch!

Below is my code (improved with some help from others).  I still would like
to make some improvements to it also.  But, perhaps there will be some ideas
in it that can help you as well!  Looking forward to learning and growing!

All the best!

Malcolm 



# guess.py
# a simple number guessing game

import random

#helper
method--
---
def nope_message(random_num):
return Nope! I'm smarter than you!\nI was thinking of the number: %d %
int(random_num)

def right_message(retried=False): 
message = That was right! I guess you ARE smarter than me

if retried:
message += ... even though it took you another try!

return message

def reread_input(message):
return int(input(You were too %s. Type another number:  % message))

def retry(message, random_num):
guess_iflow = reread_input(message)

if guess_iflow == random_num:
return right_message(True)
else:
return nope_message(random_num)

#---
--

def main():
print Do you think you're smarter than me?
print I guess we'll see!
print I'm thinking of a number between 1 - 100.  Can you guess what it
is?

random_num = random.randint(1, 100)

guess = int(input(Type a number between 1 - 100: ))

error = guess  1, guess  100


if guess == random_num:
print right_message()
elif guess  random_num:# user gets second chance if number is too low
print retry(low, random_num)
elif guess  random_num:# user gets second chance if number is too high
print retry(high, random_num)
else:
print nope_message(random_num)


if __name__ == __main__: 
main()








-Original Message-
From: tutor-bounces+malcolm.newsome=gmail@python.org
[mailto:tutor-bounces+malcolm.newsome=gmail@python.org] On Behalf Of
Donald Bedsole
Sent: Thursday, March 24, 2011 10:55 PM
To: tutor
Subject: [Tutor] Guessing Game Program

Hi folks,

This is a little program I've written to bring together some things I've
been trying to learn (not an attempt, of course, to make an interesting
game)..  I've been working my way through a beginner's tutorial, and except
for a very basic program I wrote in C++ one time, I think this is the first
program I've ever done from scratch.  Of course, I've incorporated ideas
I've learned from folks on the Internet, my tutorial, and this list.

Im sure I've broken some rules along the way, but it does work without any
errors (that I have found).

So, how could I improve it?  Is it readable to you, or a mess?

Thanks for your time,

Don


#Author D.Bedsole
#drbedsole at gmail.com
#3/24/10
#License: Public Domain


import random
from sys import exit

#A guessing game where user must guess a number between 1 and 10



def start_up():
print Hello, and welcome to the Guessing Game. Here are the rules:\n
print Try to guess the correct number.  It is between 1 and 10.
print You have ten chances.
print To quit the game just type 'quit' (w/o the quotes) at the
prompt.\n
print Here we go!\n



def ran_num():
the_number = random.randint(1,10)
return the_number

def guess_loop(the_number):
start_number = 0
while start_number  10:
print Please guess a number

[Tutor] Error in programming

2011-03-24 Thread Lea Parker
Hello

 

Just wondering if you have some time to cast your eyes over another  basic
program.

 

# Prompt user for data

def main():

print 'This program is to calculate your ticket sales to the softball
game'

print   #blank line

 

# Value of each level of seat

a_seat = 15.00

b_seat = 12.00

c_seat = 9.00

 

# Obtain data

sales_a = int (raw_input('Enter the number of class A tickets sold '))

sales_b = int (raw_input('Enter the number of class B tickets sold '))

sales_c = int (raw_input('Enter the number of class C tickets sold ')) 

income_generated(a_seat, b_seat, c_seat, sales_a, sales_b, sales_c)

 

# Obtain data to determine income generated from sales

def income_generated(a_seat, b_seat, c_seat, sales_a, sales_b, sales_c):

total_sales = times the seat value by the number of seats sold for
each seat

and add totals togeter(sale_a * a_seat) + (sale_b * b_seat) + (sale_c
* c_seat)

 

#Display result to user

print int ('Your total sales for the softball game are: $ ',
total_sales)

 

# Call the main function

main()

 

I get the following errors:

  RESTART


 

This program is to calculate your ticket sales to the softball game

 

Enter the number of class A tickets sold 5

Enter the number of class B tickets sold 5

Enter the number of class C tickets sold 10

 

Traceback (most recent call last):

  File F:/Backups/MY Documents26.2.11/Documents/Lea University/CSU/ITC10 -
Programming Principles/2011/Assessment Tasks/Assessment 1b and
1c/Stadium_Seating.py, line 29, in module

main()

  File F:/Backups/MY Documents26.2.11/Documents/Lea University/CSU/ITC10 -
Programming Principles/2011/Assessment Tasks/Assessment 1b and
1c/Stadium_Seating.py, line 18, in main

income_generated(a_seat, b_seat, c_seat, sales_a, sales_b, sales_c)

  File F:/Backups/MY Documents26.2.11/Documents/Lea University/CSU/ITC10 -
Programming Principles/2011/Assessment Tasks/Assessment 1b and
1c/Stadium_Seating.py, line 23, in income_generated

and add totals togeter(sale_a * a_seat) + (sale_b * b_seat) + (sale_c
* c_seat)

NameError: global name 'sale_a' is not defined

 

 

My way of thinking is firstly I need to fix line 29 which is main(), I tried
to do this by adding the brackets around text output in line 26. This seemed
to allow me to type main against margin rather than it wanting to indent but
didn't fix the problem. Your suggestions would be appreciated.

 

Thank

Lea

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Help - want to display a number with two decimal places

2011-03-04 Thread lea-parker
HelloI have created the following code but would like the program to include two decimal places in the amounts displayed to the user. How can I add this?My code:# Ask user to enter purchase pricepurchasePrice = input ('Enter purchase amount and then press the enter key $')
# Tax ratesstateTaxRate = 0.04countrySalesTaxRate = 0.02
# Process taxes for purchase price
stateSalesTax = purchasePrice * stateTaxRatecountrySalesTax = purchasePrice * countrySalesTaxRate
# Process total of taxestotalSalesTax = stateSalesTax + countrySalesTax
# Process total sale pricetotalSalePrice = totalSalesTax + purchasePrice
# Display the dataprint '%-18s %9d' % ('Purchase Price',purchasePrice)print '%-18s %9d' % ('State Sales Tax',astateSalesTax)print '%-18s %9d' % ('Country Sales Tax',countrySalesTax)print '%-18s %9d' % ('Total Sales tax',totalSalesTax)print '%-18s %9d' % ('Total Sale Price',totalSalePrice)Thank you in advance for your help.Lea___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python using version 3.1

2010-12-18 Thread Lea Parker
Hello

I am working through a purchased text book Python programming for beginners.
Chapter two shows how to create a basic program using triple-quoted strings.

I am having problems working out what I have done incorrectly. The game over
block writing should stay on the same line but the bottom half of the word
over comes up next to the top half of the word over. Hope that makes sense.

My code is as follows:

# Game Over - Version 2
# Demonstrates the use of quotes in strings

print(Program 'Game Over' 2.0)

print(Same, message, as before)

print(Just,
  a bit,
  bigger)

print(Here, end= )

print(it is...)

print(
  

_      __  ___
   / | /| /  |/   | |  ___|
   | |/ / | |/ /|   / | | |__
   | |  _/  |   / / |__/| | |  __|
   | |_| |  / /   | |  / /  | | | |___
   \_/ /_/|_| /_/   |_| |_|

   _  _  _   _
   / __ \ | |   / / |  ___| |  _  \
   ||  || | |  / /  | |__   | |_| |
   ||  || | | / /   |  __|  |  _  /
   ||__|| | |/ /| |___  | |  \ \
   \/ |___/ |_| |_|   \_\
   
 
) 

input(\n\nPress the enter key to exit.) 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor