Re: Coding help
On 2/23/22 17:02, Richard Pullin via Python-list wrote: I know next to nothing about computer coding nor Python. However, I am working on a mathematical challenge in which coding is required to calculate and generate different potential solutions. Can anyone help? If so, please private message me and we can discuss in more detail. Many thanks, Richard Sure What do you have in mind? -- https://mail.python.org/mailman/listinfo/python-list
Coding help
I know next to nothing about computer coding nor Python. However, I am working on a mathematical challenge in which coding is required to calculate and generate different potential solutions. Can anyone help? If so, please private message me and we can discuss in more detail. Many thanks, Richard -- https://mail.python.org/mailman/listinfo/python-list
Re: Coding Help
Maybe AutoFlowchart can help you! AutoFlowchart is a excellent source code flowcharting tool to generate flowchart from source code. Its flowchart can expand and shrink. and you can pre-define the the width , height,Horizontal spacing and vertical spacing. Move and zoom is also very easy. It can export the flowchart as a Microsoft Word file or a bitmap file. It can help programmers understand, document and visualize source code. As a new product to replace AgFlowchart, it revised the bugs of AgFlowchart and add many features. It supports C,C++,VC++(Visual C++ .NET),Delphi(Object Pascal). Maybe it can help you! http://www.ezprog.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Coding Help
On Nov 10, 3:20 pm, Carsten Haese <[EMAIL PROTECTED]> wrote: > > Maybe it would help you if you added an S6 that does nothing underneath > the "C2 is true" branch of your flow chart. > > -- > Carsten Haesehttp://informixdb.sourceforge.net Think I found a sequence of statements that would work if C1 if C2 else if C4 S2 else S3 else if C3 S1 if C5 # This should be C5. There is an error in the chart. S4 -- http://mail.python.org/mailman/listinfo/python-list
Re: Coding Help
On Sat, 2007-11-10 at 11:54 -0800, [EMAIL PROTECTED] wrote: > Well, its not homework, and if you don't want to be a tutor, you can > be a consultant and earn a lot of money. > > Here is how I thought of solving this, but it does not work: > > While C0 is false > if C1 > if C2 > > now what? Maybe it would help you if you added an S6 that does nothing underneath the "C2 is true" branch of your flow chart. -- Carsten Haese http://informixdb.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Re: Coding Help
Well, its not homework, and if you don't want to be a tutor, you can be a consultant and earn a lot of money. Here is how I thought of solving this, but it does not work: While C0 is false if C1 if C2 now what? -- http://mail.python.org/mailman/listinfo/python-list
Re: Coding Help
Marc 'BlackJack' Rintsch wrote: > On Sat, 10 Nov 2007 09:45:47 -0800, rishiyoor wrote: > >> I need help coding my flowchart. The C's are conditions, the S's are >> statements. The statements do not affect the conditions except for S5 >> which is an increment for C0. The left is True, and the right is >> False. >> >> I would probably use a while loop (or for loop without S5) for the >> first condition C0, and I am thinking of evaluating the rest of the >> conditions using if statements. But if I use if-statements, I am not >> able to accomodate the breaks. >> >> Program >>├───┐ >>┌─< C0 >─┐ │ >>│| │ >>│┌< C1 >──┐ │ >>│ ┌───< C2 >┐ ┌──< C3 >─┐│ >>│ │┌─< C4 >─┐ [S1] ││ >>│ │ [S2] [S3] └┬┘│ >>│ │││┌─< C4 >─┐│ >>│ │││ [S4] ││ >>│ │││└───┬┘│ >>│ └───┬┴┴┘ │ >>│ [S5] │ >>│ └┘ >> Program > > Sounds pretty much like homework to me. It's nothing bad ask about help for a homework as long as noone expects to get the entire solution. To the OP: What is your problem? Florian -- http://mail.python.org/mailman/listinfo/python-list
Re: Coding Help
On Sat, 10 Nov 2007 09:45:47 -0800, rishiyoor wrote: > I need help coding my flowchart. The C's are conditions, the S's are > statements. The statements do not affect the conditions except for S5 > which is an increment for C0. The left is True, and the right is > False. > > I would probably use a while loop (or for loop without S5) for the > first condition C0, and I am thinking of evaluating the rest of the > conditions using if statements. But if I use if-statements, I am not > able to accomodate the breaks. > > Program >├───┐ >┌─< C0 >─┐ │ >│| │ >│┌< C1 >──┐ │ >│ ┌───< C2 >┐ ┌──< C3 >─┐│ >│ │┌─< C4 >─┐ [S1] ││ >│ │ [S2] [S3] └┬┘│ >│ │││┌─< C4 >─┐│ >│ │││ [S4] ││ >│ │││└───┬┘│ >│ └───┬┴┴┘ │ >│ [S5] │ >│ └┘ > Program Sounds pretty much like homework to me. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Coding Help
I need help coding my flowchart. The C's are conditions, the S's are statements. The statements do not affect the conditions except for S5 which is an increment for C0. The left is True, and the right is False. I would probably use a while loop (or for loop without S5) for the first condition C0, and I am thinking of evaluating the rest of the conditions using if statements. But if I use if-statements, I am not able to accomodate the breaks. Program ├───┐ ┌─< C0 >─┐ │ │| │ │┌< C1 >──┐ │ │ ┌───< C2 >┐ ┌──< C3 >─┐│ │ │┌─< C4 >─┐ [S1] ││ │ │ [S2] [S3] └┬┘│ │ │││┌─< C4 >─┐│ │ │││ [S4] ││ │ │││└───┬┘│ │ └───┬┴┴┘ │ │ [S5] │ │ └┘ Program -- http://mail.python.org/mailman/listinfo/python-list
Re: Coding help...very basic
Hello all, I am still needing some help on this code, I have gone a bit further on it. Thank you for the help. I am trying to understand how to make the file searchable and how I am to make the deposit and withdrawl interact with the transaction class. class Account: def __init__(self, initial): self.balance = initial def deposit(self, amt): self.balance = self.balance + amt def withdraw(self, amt): self.balance = self.balance - amt def getbalance(self): return self.balance class Transactoin: def transaction(self, self.transaction = import time time.asctime() raw_input("Is this a deposit or withdrawl?") if withdrawl: elif raw_input("Please enter amount here.") class Deposit(Transaction): def deposit(self, amt): self.balance = self.balance + amt def getbalance(self): return self.balance class Withdrawl(Trasaction): def withdrawl(self, amt): self.balance = self.balance - amt def getbalance(self): return self.balance import pickle pickle.dump ((withdrawl), file ('account.pickle', 'w')) pickle.dump ((deposit), file ('account.pickle', 'w')) print "Your current account total is.", self.balance -- http://mail.python.org/mailman/listinfo/python-list
Re: Coding help...very basic
This is just a basic of what I have so far. The time , a class I will need and the print function. class Account: def __init__(self, initial): self.balance = initial def deposit(self, amt): self.balance = self.balance + amt def withdraw(self,amt): self.balance = self.balance - amt def getbalance(self): return self.balance import time time.asctime() import win32api source_filename = "log.txt" win32api.ShellExecute ( 0 "print" source_filename None "." 0) -- http://mail.python.org/mailman/listinfo/python-list
Re: Coding help...very basic
Thank both for the help. I understand that I should provide code, I am still trying to understand what to do, I don't want the work done, just some ideas of where to go, a general layout perhaps. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Coding help...very basic
Hi, people here usually tend not to be too helpful when asked to do an obvious homework task. So if you really want help, provide some code you've already written and that has actual problems. Then we're glad to help. But don't expect others to do your work. -- Regards, Diez B. Roggisch -- http://mail.python.org/mailman/listinfo/python-list
Coding help...very basic
I need some ideas of how to accomplish this task. I was told that I just need to save the input in a file and make the file searchable, nothing fancy like tying into SQL or Oracle. THis is a basic program and help is greatly appreciated: You've been given an assignment by your supervisor to program a small application to monitor the current status of the cash account in the firm's petty cash fund (the amount of cash kept on hand in the office for incidental purchases). The requirements for the program are to allow users to input the amount of cash deposited, the amount of cash withdrawn and to get a report of the balance at any given time. You will need to also add the date of each deposit and the date of each withdrawal and provide a date with the balance returned upon a given query. The program should be able to provide a printed report and support a command line query. You are to use the object oriented properties of Python to accomplish this task. -- http://mail.python.org/mailman/listinfo/python-list
Re: Need some simple coding help
thx again, this code is nearly doing as we want and we think to have figured out how to change it to meet our requirments. also thx for the tip using a heap... should there be more problems i'll post again! [mx] -- http://mail.python.org/mailman/listinfo/python-list
Re: Need some simple coding help
"mx2k" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Now you enter a value by which the initiative should be increased, > then adding reaction time to that value and then adding the result to > reaction time. Now soring again by lowest,next,'n'th, etc. and then > again showing the output, asking for another number etc. If I correct understand your goal, you might use a priority queue (heap) (there is one in the standard library). You insert all chars with the initial response time as the 'key'. You remove the one who is going to respond first and perform his actions. If he is to get another turn, add his next reaction time to the current value and insert him back into the queue. The next character to act will then be at the front of the queue. Repeat. Terry J. Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Need some simple coding help
mx2k wrote: ah, and sorry for that 'unreadable' code, but that was our first try of coding ever. we're working through the python documentaion right now - and - thanks to the post by STeVe we at last now that we have to construct a class for our purpose. Well, you don't *have* to -- it could be done all with lists as you had. But I think you'll find that it lends itself to a much cleaner solution. Also, if you ever find yourself writing a list of 5 or more if statements, you're probably not going at the problem from the easiest angle. Ask around, tell people what you're trying to do, and what you think your if statements are doing now, and they can probably point you to the easier way. STeVe -- http://mail.python.org/mailman/listinfo/python-list
Re: Need some simple coding help
mx2k wrote: indeed, we're it is our combat timeline. we enter the initiative and reaction time, it should find out the lowest then the next, then the 'n'th etc. and shouw it on the screen like Next action 'Character Name1' at tick No 'Initiative1 2nd action 'Character Name2' at tick No 'Initiative2' [...] 'n'th action 'Character Name n' at tick No 'Initiative n' Now you enter a value by which the initiative should be increased, then adding reaction time to that value and then adding the result to reaction time. Now soring again by lowest,next,'n'th, etc. and then again showing the output, asking for another number etc. Not sure if I got your calculation right, but something like this should work: py> characters [Character('Steve', 3, 2), Character('mx2k', 5, 1)] py> def get_init(character): ... return (character.initiative + character.reaction_time + ... int(raw_input('%s initiative: ' % character.name))) ... py> def print_initiatives(characters, rounds): ... for _ in range(rounds): ... inits = dict([(character, get_init(character)) ... for character in characters]) ... for character in sorted(inits, key=inits.__getitem__): ... print character, inits[character] ... py> print_initiatives(characters, 3) [... I type '5', '6' ...] Character('Steve', 3, 2) 10 Character('mx2k', 5, 1) 12 [... I type '9', '1' ...] Character('mx2k', 5, 1) 7 Character('Steve', 3, 2) 14 [... I type '1', '2' ...] Character('Steve', 3, 2) 6 Character('mx2k', 5, 1) 8 If you want the characters in the opposite order, simply use sorted(inits, key=inits.__getitem__, reverse=True) instead of sorted(inits, key=inits.__getitem__) HTH, STeVe -- http://mail.python.org/mailman/listinfo/python-list
Re: Need some simple coding help
ah, and sorry for that 'unreadable' code, but that was our first try of coding ever. we're working through the python documentaion right now - and - thanks to the post by STeVe we at last now that we have to construct a class for our purpose. Thx for any help mx2k -- http://mail.python.org/mailman/listinfo/python-list
Re: Need some simple coding help
indeed, we're it is our combat timeline. we enter the initiative and reaction time, it should find out the lowest then the next, then the 'n'th etc. and shouw it on the screen like Next action 'Character Name1' at tick No 'Initiative1 2nd action 'Character Name2' at tick No 'Initiative2' [...] 'n'th action 'Character Name n' at tick No 'Initiative n' Now you enter a value by which the initiative should be increased, then adding reaction time to that value and then adding the result to reaction time. Now soring again by lowest,next,'n'th, etc. and then again showing the output, asking for another number etc. -- http://mail.python.org/mailman/listinfo/python-list
Re: Need some simple coding help
mx2k wrote: Hello @ all, we have written a small program (code below) for our own in-developement rpg system, which is getting values for 4 RPG-Characters and doing some calculations with it. now we're trying hard to find out how to get it working with 'n' Characters, so you will be asked to enter a number at the beginning, asking you how many characters you want. anyone out there who could help us? Why don't you try describing what it is you're trying to do in some more detail -- your code is fairly unreadable. I gather you want to do something like: py> class Character(object): ... def __init__(self, name, initiative, reaction_time): ... self.name = name ... self.initiative = initiative ... self.reaction_time = reaction_time ... def __repr__(self): ... return 'Character(%r, %r, %r)' % ( ... self.name, self.initiative, self.reaction_time) ... py> def get_char(): ... return Character(raw_input("Char 1 Name: "), ... int(raw_input("Char 1 Initiative: ")), ... int(raw_input("Char 1 Reaction Time: "))) ... py> n_chars = int(raw_input('Number of Characters: ')) [...I type '2'...] py> characters = [get_char() for _ in xrange(n_chars)] [...I type 'Steve', '3', '2', etc] py> characters [Character('Steve', 3, 2), Character('mx2k', 5, 1)] But it's not clear to me what it is you want done with the characters. It looks like you're maybe trying to go through rounds of combat, sorting characters by initiative...? What exactly is the process you're attempting to follow? If you try to describe the problem in words, you'll probably get more help. (Code is generally good too, but if it's not clear what you're trying to do with the code, no one will be able to make use of it.) STeVe -- http://mail.python.org/mailman/listinfo/python-list
Need some simple coding help
Hello @ all, we have written a small program (code below) for our own in-developement rpg system, which is getting values for 4 RPG-Characters and doing some calculations with it. now we're trying hard to find out how to get it working with 'n' Characters, so you will be asked to enter a number at the beginning, asking you how many characters you want. anyone out there who could help us? also i wonder how i can read the current date/time (we don't understand datetime() )and put it into a variable and print that variable? [mx] and Tschabo doing python since yesterday :) Code follows: # Timeline Tools for an RPG system - Written in Python 2.4 # Created by [mx] networkz @ 27.02.05 - [EMAIL PROTECTED] # Collaboration work of mx2k & Tschabo (von Konsti) # import math #- #defining functions #header text def showtitle(): print '' print ' Timeline System - Alpha Version 0.8.15 ' print '' print '*supports 4 characters *' print '*coding [mx] networkz & Tschabo*' print '*created 2005 *' #print '' print '' #sorting def sortfun(): charlist = [char1[1],char2[1],char3[1],char4[1]] charlist.sort() #dunno if correct, is spamming move[] lists but working correctly if charlist[0] == char1[1]: move1[0:0] = [char1[0],char1[1],char1[2]] if charlist[0] == char2[1]: move1[0:0] = [char2[0],char2[1],char2[2]] if charlist[0] == char3[1]: move1[0:0] = [char3[0],char3[1],char3[2]] if charlist[0] == char4[1]: move1[0:0] = [char4[0],char4[1],char4[2]] if charlist[1] == char1[1]: move2[0:0] = [char1[0],char1[1],char1[2]] if charlist[1] == char2[1]: move2[0:0] = [char2[0],char2[1],char2[2]] if charlist[1] == char3[1]: move2[0:0] = [char3[0],char3[1],char3[2]] if charlist[1] == char4[1]: move2[0:0] = [char4[0],char4[1],char4[2]] if charlist[2] == char1[1]: move3[0:0] = [char1[0],char1[1],char1[2]] if charlist[2] == char2[1]: move3[0:0] = [char2[0],char2[1],char2[2]] if charlist[2] == char3[1]: move3[0:0] = [char3[0],char3[1],char3[2]] if charlist[2] == char4[1]: move3[0:0] = [char4[0],char4[1],char4[2]] if charlist[3] == char1[1]: move4[0:0] = [char1[0],char1[1],char1[2]] if charlist[3] == char2[1]: move4[0:0] = [char2[0],char2[1],char2[2]] if charlist[3] == char3[1]: move4[0:0] = [char3[0],char3[1],char3[2]] if charlist[3] == char4[1]: move4[0:0] = [char4[0],char4[1],char4[2]] #showing next action times # should also be enumerated to 'n'th action # but how to put that into string def shownextaction(): print 'Loop Nr. ', run_nr print '' print '---' print 'Next action', move1[0], 'at tick No', move1[1] print ' 2nd action', move2[0], 'at tick No', move2[1] print ' 3rd action', move3[0], 'at tick No', move3[1] print ' 4th action', move4[0], 'at tick No', move4[1] print '---' #log to textfile def logfile(): outnr = str('Loop Nr. ') + str(run_nr) + str('\n') out1 = str(' Next action ') + str(move1[0])+ str(' at tick No ') + str(move1[1]) + str('\n') out2 = str(' 2nd action ') + str(move2[0])+ str(' at tick No ') + str(move2[1]) + str('\n') out3 = str(' 3rd action ') + str(move3[0])+ str(' at tick No ') + str(move3[1]) + str('\n') out4 = str(' 4th action ') + str(move4[0])+ str(' at tick No ') + str(move4[1]) + str('\n\n') incr_ = str('Entered Number was: ') + str(inc) + str('\n') incre = str('Increasing Character ') + str(move1[0]) + str(' by Value: ') + str(inc) + str(' + ') + str(inc_out) + str('\n\n\n') #timecode= str f = file('timeline.txt', 'a') #f.write(timecode) f.write('Actiontimes of ') f.write(outnr) f.write(out1) f.write(out2) f.write(out3) f.write(out4) f.write(incr_) f.write(incre) f.close() #--- #defining some stuff, calling title showtitle() run_nr= 0 the_end = 'this is the end. exit requested by user.' loops = int(raw_input("Number of Loops: ")) #check if we should run, then asking for input # here it should ask for n characters, then enumerating # variables, i.e. n=6 creates char1-char6 and filling it # like shown below if loops == 0: the_end else: char1 = [raw_input("Char 1 Name: "),int(raw_input("Char 1 Initiative: ")),int(raw_input("Char 1 Reaction Time: "))] char2 = [raw_input("Char 2 Name: "),int(raw_input("Char 2 Initiative: ")),int(raw_input("Char 2 Reaction Time: "))] char3 = [raw_input("Char 3 Name: "),int(raw_input("Char 3 Initiative: ")),int(raw_input("Char 3 Reaction Time: "))] char4
Re: NOOB coding help....
Igorati wrote: #This program will ask for a user to imput numbers. The numbers will then be calculated #to find the statistical mean, mode, and median. Finallly the user will be asked #if he would like to print out the answers. > numbers = [ ] print 'Enter numbers to add to the list. (Enter 0 to quit.)' so 0 is not a valid value ? Since you only want numbers, any alpha char could be used to exit... def getint(): return int(raw_input('Number? ')) What happens if the user type "foo" ? numbers = sorted(iter(getint, 0)) numbers [2, 3, 5, 7] def variable_median(x): return sorted(x)[len(x)//2] def variable_mode(x): counts = {} for item in x: counts[x] = counts.get(x, 0) + 1 return sorted(counts, key=counts.__getitem__, reverse=True)[0] s = variableMean(numbers) y = variableMedian(numbers) t = variableMode (numbers) import pickle pickle.dump((s, y, t), file('avg.pickle', 'w')) Take care of removing hard-coded filenames... (this is ok for testing but should not be released like this) print 'Thank you! Would you like to see the results after calculating' print 'The mode, median, and mean? (Please enter Yes or No)' print 'Please enter Yes or No:' if raw_input == yes: First, raw_input() is a function, you need to use the () operator to *call* (execute) the function. Then, raw_input() returns a string. A string is something between quotes. Yes is a symbol (a variable name, function name or like), not a string. And since this symbol is not defined, you have an exception. What you want to do is to compare the string returned by the raw_input() function to the literral string "Yes". What you're doing in fact is comparing two symbols, one being defined, the other one being undefined... if raw_input() == "Yes": f = open("avg.py","r") Same remark as above about hard-coded file names... avg.py = f.read() Notice that the dot is an operator. Here you trying to access the attribute 'py' of an (actually inexistant) object named 'avg'. What you want is to bind the data returned by f.read() to a variable. data = f.read() print 'The Mean average is:', mean print 'The Median is:', meadian print 'The Mode is:', mode At this time, mean, meadian and mode are undefined symbols. Since you used the pickle module to persist your data, you should use it to unserialize'em too. The pickle module is well documented, so you may want to read the manual. I got the error: Traceback (most recent call last): File "C:\Python24\Lib\New Folder\Wade_StoddardSLP3-2.py", line 9, in ? numbers = sorted(iter(getint, 0)) File "C:\Python24\Lib\New Folder\Wade_StoddardSLP3-2.py", line 7, in getint return int(raw_input('Number? ')) TypeError: 'str' object is not callable Can't tell you since I'm running python 2.3.x here (sorted() is new in 2.4) and this one for my if statement: Traceback (most recent call last): File "C:\Python24\Lib\New Folder\Wade_StoddardSLP3-2.py", line 39, in ? if raw_input == Yes: NameError: name 'Yes' is not defined See above. I cannot understand how I can define yes so that when they type yes the data is printed out. Yes = 'yes' ?-) Also if they type no how do I make the program do nothing. Or is that just infered. May I suggest that you : - subscribe to the 'tutor' mailing-list (it's a ml for absolute beginners) - do some tutorials (there's one with the doc, and many others freely available on the net) - use the interactive python shell to test bits of your code ? HTH Bruno -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list
Re: NOOB coding help....
Igorati said unto the world upon 2005-02-22 03:51: #This program will ask for a user to imput numbers. The numbers will then be calculated #to find the statistical mean, mode, and median. Finallly the user will be asked #if he would like to print out the answers. numbers = [ ] print 'Enter numbers to add to the list. (Enter 0 to quit.)' def getint(): return int(raw_input('Number? ')) numbers = sorted(iter(getint, 0)) numbers [2, 3, 5, 7] def variable_median(x): return sorted(x)[len(x)//2] def variable_mode(x): counts = {} for item in x: counts[x] = counts.get(x, 0) + 1 return sorted(counts, key=counts.__getitem__, reverse=True)[0] s = variableMean(numbers) y = variableMedian(numbers) t = variableMode (numbers) import pickle pickle.dump((s, y, t), file('avg.pickle', 'w')) print 'Thank you! Would you like to see the results after calculating' print 'The mode, median, and mean? (Please enter Yes or No)' print 'Please enter Yes or No:' if raw_input == yes: f = open("avg.py","r") avg.py = f.read() print 'The Mean average is:', mean print 'The Median is:', meadian print 'The Mode is:', mode I got the error: Traceback (most recent call last): File "C:\Python24\Lib\New Folder\Wade_StoddardSLP3-2.py", line 9, in ? numbers = sorted(iter(getint, 0)) File "C:\Python24\Lib\New Folder\Wade_StoddardSLP3-2.py", line 7, in getint return int(raw_input('Number? ')) TypeError: 'str' object is not callable and this one for my if statement: Traceback (most recent call last): File "C:\Python24\Lib\New Folder\Wade_StoddardSLP3-2.py", line 39, in ? if raw_input == Yes: NameError: name 'Yes' is not defined I cannot understand how I can define yes so that when they type yes the data is printed out. Also if they type no how do I make the program do nothing. Or is that just infered. Hi, have you tried examining the objects you are trying to put together to see why they might not fit? For instance, look what happens when you run this, entering 42 at the prompt: ri = raw_input('Gimme!') print type(ri) print type(int(ri)) print ri == 42 print ri == '42' name_not_defined_in_this_code Does looking at the output of that help? Best, Brian vdB -- http://mail.python.org/mailman/listinfo/python-list
Re: NOOB coding help....
#This program will ask for a user to imput numbers. The numbers will then be calculated #to find the statistical mean, mode, and median. Finallly the user will be asked #if he would like to print out the answers. numbers = [ ] print 'Enter numbers to add to the list. (Enter 0 to quit.)' def getint(): return int(raw_input('Number? ')) numbers = sorted(iter(getint, 0)) numbers [2, 3, 5, 7] def variable_median(x): return sorted(x)[len(x)//2] def variable_mode(x): counts = {} for item in x: counts[x] = counts.get(x, 0) + 1 return sorted(counts, key=counts.__getitem__, reverse=True)[0] s = variableMean(numbers) y = variableMedian(numbers) t = variableMode (numbers) import pickle pickle.dump((s, y, t), file('avg.pickle', 'w')) print 'Thank you! Would you like to see the results after calculating' print 'The mode, median, and mean? (Please enter Yes or No)' print 'Please enter Yes or No:' if raw_input == yes: f = open("avg.py","r") avg.py = f.read() print 'The Mean average is:', mean print 'The Median is:', meadian print 'The Mode is:', mode I got the error: Traceback (most recent call last): File "C:\Python24\Lib\New Folder\Wade_StoddardSLP3-2.py", line 9, in ? numbers = sorted(iter(getint, 0)) File "C:\Python24\Lib\New Folder\Wade_StoddardSLP3-2.py", line 7, in getint return int(raw_input('Number? ')) TypeError: 'str' object is not callable and this one for my if statement: Traceback (most recent call last): File "C:\Python24\Lib\New Folder\Wade_StoddardSLP3-2.py", line 39, in ? if raw_input == Yes: NameError: name 'Yes' is not defined I cannot understand how I can define yes so that when they type yes the data is printed out. Also if they type no how do I make the program do nothing. Or is that just infered. -- http://mail.python.org/mailman/listinfo/python-list
Re: NOOB coding help....
Thank you, that does help quit a bit. I am working on the corrections now. To the first poster... don't know what that meant. I thought I made my case understandable. Thank you again. I will work on that. I was attempting to open wade_stoddard... b/c that was my file I was working with, and I was told I had to open it in order to save information to another file so I could recall that information. Thank you again for the help Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: NOOB coding help....
Igorati wrote: list = [ ] a = 1 print 'Enter numbers to add to the list. (Enter 0 to quit.)' while a != 0 : a = input('Number? ') list.append(a) zero = list.index(0) del list[zero] list.sort() A simpler approach is to use the second form of the builtin iter function which takes a callable and a sentinel: py> def getint(): ... return int(raw_input('Number? ')) ... py> numbers = sorted(iter(getint, 0)) Number? 3 Number? 7 Number? 5 Number? 2 Number? 0 py> numbers [2, 3, 5, 7] Note that I've renamed 'list' to 'numbers' so as not to hide the builtin type 'list'. variableMean = lambda x:sum(x)/len(x) variableMedian = lambda x: x.sort() or x[len(x)//2] variableMode = lambda x: max([(x.count(y),y) for y in x])[1] s = variableMean(list) y = variableMedian(list) t = variableMode (list) See "Inappropriate use of Lambda" in http://www.python.org/moin/DubiousPython. Lambdas aside, some alternate possibilities for these are: def variable_median(x): # don't modify original list return sorted(x)[len(x)//2] def variable_mode(x): # only iterate through x once (instead of len(x) times) counts = {} for item in x: counts[x] = counts.get(x, 0) + 1 # in Python 2.5 you'll be able to do # return max(counts, key=counts.__getitem__) return sorted(counts, key=counts.__getitem__, reverse=True)[0] Note also that you probably want 'from __future__ import divsion' at the top of your file or variableMean will sometimes give you an int, not a float. x = (s,y,t) inp = open ("Wade_StoddardSLP3-2.py", "r") outp = open ("avg.py", "w") f = ("avg.py") for x in inp: outp.write(x) import pickle pickle.dump(x, f) If you want to save s, y and t to a file, you probably want to do something like: pickle.dump((s, y, t), file('avg.pickle', 'w')) I don't know why you've opened Wade_StoddardSLP3-2.py, or why you write that to avg.py, but pickle.dump takes a file object as the second parameter, and you're passing it a string object, "avg.py". f = open("avg.py","r") avg.py = f.read() print 'The Mean average is:', mean print 'The Median is:', meadian print 'The Mode is:', mode mean, median, mode = pickle.load(file('avg.pickle')) print 'The Mean average is:', mean print 'The Median is:', meadian print 'The Mode is:', mode HTH, STeVe -- http://mail.python.org/mailman/listinfo/python-list
Re: NOOB coding help....
Could you phrase this in the form of a question, like Jeopardy? On Monday 21 February 2005 08:08 pm, Igorati wrote: > Ok, this is what I have so far: > > #This program will ask for a user to imput numbers. The numbers will then > be calculated > #to find the statistical mean, mode, and median. Finallly the user will be > asked > #if he would like to print out the answers. > list = [ ] > a = 1 > print 'Enter numbers to add to the list. (Enter 0 to quit.)' > while a != 0 : > a = input('Number? ') > list.append(a) > zero = list.index(0) > del list[zero] > list.sort() > > variableMean = lambda x:sum(x)/len(x) > variableMedian = lambda x: x.sort() or x[len(x)//2] > variableMode = lambda x: max([(x.count(y),y) for y in x])[1] > s = variableMean(list) > y = variableMedian(list) > t = variableMode (list) > > x = (s,y,t) > inp = open ("Wade_StoddardSLP3-2.py", "r") > outp = open ("avg.py", "w") > f = ("avg.py") > for x in inp: > outp.write(x) > import pickle > pickle.dump(x, f) > > > print 'Thank you! Would you like to see the results after calculating' > print 'The mode, median, and mean? (Please enter Yes or No)' > raw_input('Please enter Yes or No:') > if raw_input == Yes: > > f = open("avg.py","r") > avg.py = f.read() > print 'The Mean average is:', mean > print 'The Median is:', meadian > print 'The Mode is:', mode > > I am attempting to make it so that I can save the mean, meadian, and mode > and then if the user wants the data to give it to him. Thank you for any > assistance you can provide! > > Wade -- James Stroud, Ph.D. UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 -- http://mail.python.org/mailman/listinfo/python-list
NOOB coding help....
Ok, this is what I have so far: #This program will ask for a user to imput numbers. The numbers will then be calculated #to find the statistical mean, mode, and median. Finallly the user will be asked #if he would like to print out the answers. list = [ ] a = 1 print 'Enter numbers to add to the list. (Enter 0 to quit.)' while a != 0 : a = input('Number? ') list.append(a) zero = list.index(0) del list[zero] list.sort() variableMean = lambda x:sum(x)/len(x) variableMedian = lambda x: x.sort() or x[len(x)//2] variableMode = lambda x: max([(x.count(y),y) for y in x])[1] s = variableMean(list) y = variableMedian(list) t = variableMode (list) x = (s,y,t) inp = open ("Wade_StoddardSLP3-2.py", "r") outp = open ("avg.py", "w") f = ("avg.py") for x in inp: outp.write(x) import pickle pickle.dump(x, f) print 'Thank you! Would you like to see the results after calculating' print 'The mode, median, and mean? (Please enter Yes or No)' raw_input('Please enter Yes or No:') if raw_input == Yes: f = open("avg.py","r") avg.py = f.read() print 'The Mean average is:', mean print 'The Median is:', meadian print 'The Mode is:', mode I am attempting to make it so that I can save the mean, meadian, and mode and then if the user wants the data to give it to him. Thank you for any assistance you can provide! Wade -- http://mail.python.org/mailman/listinfo/python-list