Re: [Tutor] How to make to exit the loop, while typing Enter
Hi All I was able to exit the while loop , using sys module also I was able to find the maximum no of marks entered , I am adding my code , for comments and suggestions Thanks for the support Joseph John * """ This progorm was to learn 1> How to find which is the maximum mark in list 2> How to exit the while loop, while typing enter """ import sys maxmark = [] counter = 0 while 1: try: mark = int(raw_input("Enter the Values for The Array: ")) maxmark.append(mark) print maxmark except ValueError: #print "From Here to Where " counter = 0 length = len(maxmark) #print length max = maxmark[counter] #print max for counter in range(length): if maxmark[counter] > max: max = maxmark[counter] # print " Ya U are in the if loop and the maximum no is ", max #else: #print "The ", length print "At last the Maximum Marks U got is ", max sys.exit() ~ ~ ~ --- Adam <[EMAIL PROTECTED]> wrote: > > array = [] > > m = 0 > > print "Enter to exit" > > m = int(raw_input("Enter the Values for The > Array : > > ")) > > array.append(m) > > print array > > while m != "": > > m = int(raw_input("Enter the Values for > The > > Array : ")) > > array.append(m) > > print array > > > The problem is that if a value is entered that can't > be converted to an > integer type, like "" or a letter then an exception > is raised. What you > could do is use a try, except. > while 1: > try: > m = int(raw_input("Enter the Values for > The Array: ")) > array.append(m) > print array > except ValueError: > sys.exit() > > alternatively you could do something like this: > m=raw_input("Enter the Values for The Array: ") > if m == "": sys.exit() > try: > int(m) > array.append(m) > print array > except ValueError: > print "Only integer values can be entered into > the array, or press the > enter key to exit." > ___ To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Programming Python, 3rd ed.??
Several months ago I saw an item on the O'Reilly site to the effect that the 3rd. ed. of Programming Python was in the works. I made a note to myself to check back in January. I just did, but could find nothing at all about a 3rd. edition. Anyone know? Thanks, Dick Moores ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] HD/DVD/CD
On Wed, 4 Jan 2006, John Fouhy wrote: > On 04/01/06, Terry Carroll <[EMAIL PROTECTED]> wrote: > > I hope someone more artful than I can show a quick and easy way to convert > > either '758C87F3' or -1972144115 to the '8A73780D' that is your goal. > > Hmm, well, > > >>> i = -1972144115 > >>> '%X' % (pow(2, 32)-(~i+1)) > '8A73780D' Aha, I also figured another way myself in the meantime: >>> import win32api >>> CD_Info = win32api.GetVolumeInformation("D:/") >>> serno = CD_Info[1] >>> serno_str = "%X" % (0x1+serno) >>> serno_str '8A73780D' >>> > >>> cdi = win32api.GetVolumeInformation('D:/') > >>> '%X' % cdi[1] > '49BC31DB' > > So, on my system (ActivePython 2.4, WinXPpro) there is no need for magic. I think you just got lucky that your first digit (4) was in the range 0-7, and so didn't generate a negative. But you *do* point out a fault in my approach. I'll give an incorrect result for a non-negative. I think the correct way is: >>> import win32api >>> CD_Info = win32api.GetVolumeInformation("D:/") >>> serno = CD_Info[1] >>> if serno < 0: ...serno_str = "%X" % (0x1+serno) ... else: ...serno_str = "%X" % serno ... >>> serno_str '8A73780D' >>> ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] HD/DVD/CD
On 04/01/06, Terry Carroll <[EMAIL PROTECTED]> wrote: > I hope someone more artful than I can show a quick and easy way to convert > either '758C87F3' or -1972144115 to the '8A73780D' that is your goal. Hmm, well, >>> i = -1972144115 >>> '%X' % (pow(2, 32)-(~i+1)) '8A73780D' Although my bitwise arithmetic's feeling pretty rusty.. But --- C:\Games\Civilization III\Conquests>dir d: Volume in drive D is CIV3CQST Volume Serial Number is 49BC-31DB ... >>> import win32api >>> cdi = win32api.GetVolumeInformation('D:/') >>> '%X' % cdi[1] '49BC31DB' So, on my system (ActivePython 2.4, WinXPpro) there is no need for magic. I've got Mark Hammond's pywin32 book, but it doesn't talk about win32api.GetVolumeInformation(). -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] HD/DVD/CD
On Tue, 3 Jan 2006, Ron Speerstra wrote: > my question: howtoo read the HD/CD/DVD serial-numbers with Python. I can take you part-way there, at least under Windows. Hopefully someone can finish the job. I'm assuming you want the same serial # that shows up when you do a DIR on the CD, e.g.: >dir d: Volume in drive D is 050512_1752 Volume Serial Number is 8A73-780D Here's some code: >>> import win32api >>> CD_Info = win32api.GetVolumeInformation("D:/") >>> serno = CD_Info[1] >>> serno -1972144115 >>> "%X" % serno '-758C87F3' >>> "%X" % -serno '758C87F3' This is as far as I can get. the hex string, in this case 758C87F3 is the two's complement of the serial number that shows up when I do a "dir d:": >dir d: Volume in drive D is 050512_1752 Volume Serial Number is 8A73-780D Note that: 758C 87F3 + 8A73 780D = 1 Put another way, if you flip every bit in the 758C87F3 string and add one, you'll get the 8A73780D serial no. I hope someone more artful than I can show a quick and easy way to convert either '758C87F3' or -1972144115 to the '8A73780D' that is your goal. I'm betting there's something simple I'm missing. (By the way, it occurs to me; I guess you could just do the "dir" and capture the serial number in the output; but that's inelegant and wasteful.) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] dynamic lists
>> im looking for very simple DES and RSA algorithms writen in python (or >> C), can anyone know where i can find them > > I'll be slightly surprised if you find Python versions(but not amazed! :-) > since performance is usually of high priority for cryptography. Ok, I'm duly surprised but not amazed... ;-) Batteries not included this time but available nonetheless, Python never ceased to catch me out... Mind you I still doubt I'd use Python for anything other than experimental crypto work. (But that might just be my comms background and the need for real-time encryption showing through...) Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] dynamic lists
> im looking for very simple DES and RSA algorithms writen in python (or > C), can anyone know where i can find them I'll be slightly surprised if you find Python versions(but not amazed! :-) since performance is usually of high priority for cryptography. But the RSA site should have C libraries I think. They used to... Note that DES is now considered minimum security since it was broken by brute force in DesChall a few years ago... Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python code pretty-print?
Try getting gvim for MacOS vim includes a Python mode with syntax colouring and you can get it to print it out using an HTML representation. It works well IMHO (on any platform including MacOS). http://www.vim.org/download.php and MacOS specific versions : http://macvim.org/ Scite does the same trick but I don't know how well it runs on MacOS. http://mailman.lyra.org/pipermail/scintilla-interest/2003-May/002756.html Alan G. - Original Message - From: "Lance E Sloan" <[EMAIL PROTECTED]> To: Sent: Tuesday, January 03, 2006 2:12 PM Subject: [Tutor] Python code pretty-print? >A colleague of mine often develops Python code under Mac OS X. He would >like to be able to print the code in an easily readable format. He's found >that kwrite on Linux does a very nice job, but it's inconvenient to copy >his code to a Linux box just to print it out. > > We've found mention (mostly in manpages) of a program called "pyhtmlizer", > but couldn't find source or binary for it. > > Can anybody recommend a similar tool that we can use on Mac OS X? > > Thanks! > > -- > Lance E Sloan, Systems Research Programmer III > U-M WATS: Web Applications, Technologies, and Solutions > Full-service web and database design, development, and hosting. > http://www.itcs.umich.edu/wats/ - "Putting U on the Web" > > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Syntax Errors
Danny! Thanks! It's the tab vs spaces, alright. I use tabs for my spacing and I was touching a part of the code that a co-worker wrote. Guess what he uses? Spaces. Thanks for that insight and I'll be sure to read up on the command line options. On 1/3/06, Danny Yoo <[EMAIL PROTECTED]> wrote: On Tue, 3 Jan 2006, Jason Massey wrote:> I've just finished ripping out a bunch of lines in one of my wxPython> programs. Testing it out I get:>> C:\Python24>tla2.py> File "C:\Python24\tla2.py", line 412 > self.grid.SetCellValue(0,0,"Site")> ^> SyntaxError: invalid syntax>> There's nothing wrong with that line. I didn't even touch it in the> overhaul (refactoring is much too delicate of a word for the surgery I > just did). I can make the error go away by unindenting the line, but> all that happens then is the error gets passed onto the next line down.Hi Jason,Can you show us the line in context? That is, can you show us a few lines above and below?Also, let's make sure we're not running into a silly tab-vs-spaces issue.Can you try running Python with the '-tt' command line option? This willenable Python to strictly treat mixed tabs and spaces as a bad thing. Good luck! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] HD/DVD/CD
On 04/01/06, Ron Speerstra <[EMAIL PROTECTED]> wrote: > my question: howtoo read the HD/CD/DVD serial-numbers with Python. > Volume-name, dir name, file name. no problem etc Are you running Microsoft Windows? If so, are any of the scripts at http://www.microsoft.com/technet/scriptcenter/scripts/python/pyindex.mspx useful to you? -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Syntax Errors
On Tue, 3 Jan 2006, Jason Massey wrote: > I've just finished ripping out a bunch of lines in one of my wxPython > programs. Testing it out I get: > > C:\Python24>tla2.py > File "C:\Python24\tla2.py", line 412 > self.grid.SetCellValue(0,0,"Site") > ^ > SyntaxError: invalid syntax > > There's nothing wrong with that line. I didn't even touch it in the > overhaul (refactoring is much too delicate of a word for the surgery I > just did). I can make the error go away by unindenting the line, but > all that happens then is the error gets passed onto the next line down. Hi Jason, Can you show us the line in context? That is, can you show us a few lines above and below? Also, let's make sure we're not running into a silly tab-vs-spaces issue. Can you try running Python with the '-tt' command line option? This will enable Python to strictly treat mixed tabs and spaces as a bad thing. Good luck! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with choosing books
Hi, What background do you come from? Can you already program in another language? > Hi! I got Foundations of Python Network Programming > I really want to tackle my Foundations book and I want > to get up to speed as quickly as I can. Thanks! If you already program then just work through the Python tutor that comes with Python. That should be all you really need. Ask any specific questions on this list. If you are a complete beginner there is a web site that lists several tutors for non programmers (mine included) and the books you have should help too. Anything you don't understand just ask here. Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to make to exit the loop, while typing Enter
> entries for the list , But if I press Enter it should > exit the while loop without giving errors ,I have > problem in making it work , right now if I press enter > to exit , the program terminates showing error Thats because you can't convert an empty string to an int. If you defer the conversion until you add the mark to the list then it should work OK. > m = int(raw_input("Enter the Values for The Array : > ")) > array.append(m) array.append(int(m)) HTH, Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] HD/DVD/CD
Hi, M-list, my name Ron Speerstra(the Netherlands) my question: howtoo read the HD/CD/DVD serial-numbers with Python. Volume-name, dir name, file name. no problem etc. Gr Ron$ _ Vind alles terug op je PC: MSN Search Toolbar http://toolbar.msn.nl/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Syntax Errors
I've just finished ripping out a bunch of lines in one of my wxPython programs. Testing it out I get: C:\Python24>tla2.py File "C:\Python24\tla2.py", line 412 self.grid.SetCellValue(0,0,"Site") ^ SyntaxError: invalid syntax There's nothing wrong with that line. I didn't even touch it in the overhaul (refactoring is much too delicate of a word for the surgery I just did). I can make the error go away by unindenting the line, but all that happens then is the error gets passed onto the next line down. I've had this happen before on a smaller scale. Python wouldn't like a certain line and I found that if I moved it up in the function the error would go away. Unfortunately this overhaul touched on at least three functions. Oddly enough the function where I did the majority of the work seemed to come out fine. Any pointers on tracing this down? In C I would expect I didn't have a set of matching braces or a missing semi-colon. thanks, jason ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] DES and RSA cryptography algorithms? (Was: Re: dynamic lists)
On Tue, 3 Jan 2006, lfiedor wrote: > im looking for very simple DES and RSA algorithms writen in python (or > C), can anyone know where i can find them I'm changing subject lines. Please try to make your message Subject lines descriptive enough to make it easier to find later. Also, next time, try first searching for these modules in Python's Cheese Shop code repository. It's the spiritual successor to the Vaults of Parnassus, and is steadily becoming very usable. http://cheeseshop.python.org/pypi Yes, there are implementations of those algorithms available. For example: http://cheeseshop.python.org/pypi/pyDes/ shows a pure Python implementation of DES. There's also a nice packaging of those algorithms in the Python Cryptography Toolkit: http://www.amk.ca/python/code/crypto Good luck to you. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] dynamic lists
googled for rsa & python: http://www.python.org/workshops/1995-05/pct.html On 1/3/06, lfiedor <[EMAIL PROTECTED]> wrote: Hiim looking for very simple DES and RSA algorithms writen in python (orC), can anyone know where i can find them___Tutor maillist - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python code pretty-print?
On Tue, 3 Jan 2006, Lance E Sloan wrote: > A colleague of mine often develops Python code under Mac OS X. He would > like to be able to print the code in an easily readable format. He's > found that kwrite on Linux does a very nice job, but it's inconvenient > to copy his code to a Linux box just to print it out. > > We've found mention (mostly in manpages) of a program called > "pyhtmlizer", but couldn't find source or binary for it. Hi Lance, 'pyhtmlizer' is in the twisted package, under twisted.scripts: http://twistedmatrix.com/documents/current/api/twisted.scripts.htmlizer.html You should be able to get the source there. Alternatively, the Python Cookbook has a good recipe for syntax highlighting: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52298 Finally, GNU Enscript might be applicable. GNU Enscript knows how to colorize and pretty print different programming languages, and I believe it's already in Mac OS X. http://www.osxfaq.com/man/1/enscript.ws If you use the --pretty-print, --color, and -Whtml options, you should be able to get some reasonable output with it. Best of wishes! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] dynamic lists
Hi im looking for very simple DES and RSA algorithms writen in python (or C), can anyone know where i can find them ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python code pretty-print?
A colleague of mine often develops Python code under Mac OS X. He would like to be able to print the code in an easily readable format. He's found that kwrite on Linux does a very nice job, but it's inconvenient to copy his code to a Linux box just to print it out. We've found mention (mostly in manpages) of a program called "pyhtmlizer", but couldn't find source or binary for it. Can anybody recommend a similar tool that we can use on Mac OS X? Thanks! -- Lance E Sloan, Systems Research Programmer III U-M WATS: Web Applications, Technologies, and Solutions Full-service web and database design, development, and hosting. http://www.itcs.umich.edu/wats/ - "Putting U on the Web" ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] How to make to exit the loop, while typing Enter
Woops, forgot to reply-all.-- Forwarded message --From: Adam <[EMAIL PROTECTED]>Date: 03-Jan-2006 15:48 Subject: Re: [Tutor] How to make to exit the loop, while typing EnterTo: John Joseph <[EMAIL PROTECTED]> array = []m = 0print "Enter to exit"m = int(raw_input("Enter the Values for The Array : "))array.append(m)print arraywhile m != "":m = int(raw_input("Enter the Values for TheArray : "))array.append(m)print array The problem is that if a value is entered that can't be converted to an integer type, like "" or a letter then an exception is raised. What you could do is use a try, except.while 1: try: m = int(raw_input("Enter the Values for The Array: ")) array.append(m) print array except ValueError: sys.exit()alternatively you could do something like this: m=raw_input("Enter the Values for The Array: ") if m == "": sys.exit()try: int(m) array.append(m) print arrayexcept ValueError: print "Only integer values can be entered into the array, or press the enter key to exit." ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to make to exit the loop, while typing Enter
> I am trying to write a program in which it ask for entries for the list > , But if I press Enter it should exit the while loop without giving > errors Hi John, Do you have ideas why it's getting an error? Can you point at the part of the program that's receiving the "Enter"? As a related question, what result do you expect from: int("") What does Python respond with? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with choosing books
Hi, I guess this has been discussed in detail in December 2005 (last month). you might want to check this thread and the replies in deteails. http://mail.python.org/pipermail/tutor/2005-December/044028.html This might help. --- wood yee <[EMAIL PROTECTED]> wrote: - Hi! I got Foundations of Python Network Programming as a gift but I don't know Python. My library has several books called Beginning Python. One's by Wrox and the other is by the author of the hacking python tutorial. My question is how can I achieve my goal of becoming ready for Foundations of Python Network Programming? Which book should I start with? Is a tutorial better? Any ideas of what syllabus(sp?) to follow? I really want to tackle my Foundations book and I want to get up to speed as quickly as I can. Thanks! > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > __ Yahoo! DSL Something to write home about. Just $16.99/mo. or less. dsl.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Help with choosing books
Hi! I got Foundations of Python Network Programming as a gift but I don't know Python. My library has several books called Beginning Python. One's by Wrox and the other is by the author of the hacking python tutorial. My question is how can I achieve my goal of becoming ready for Foundations of Python Network Programming? Which book should I start with? Is a tutorial better? Any ideas of what syllabus(sp?) to follow? I really want to tackle my Foundations book and I want to get up to speed as quickly as I can. Thanks! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] IOError: (0, 'Error')
On 1/2/06, Kent Johnson <[EMAIL PROTECTED]> wrote: > Bernard Lebel wrote: > > I'm checking out the logging module atm. I'm trying the second example > > in "Basic example": > > > > import logging > > > > logging.basicConfig(level=logging.DEBUG, > > format='%(asctime)s %(levelname)s %(message)s', > > filename='C:\\pylogger.log', > > filemode='w') > > logging.debug('A debug message') > > logging.info('Some information') > > logging.warning('A shot across the bows') > > > > > > However when I run that I don't get any log file, while the doc page > > says I should have a log file. Only the warning is printed, as if I > > had not run the basicConfig method. Any suggestion? > > If I copy and paste your code and run it, it works as expected creating > C:\pylogger.log containing > > 2006-01-02 21:49:21,071 DEBUG A debug message > 2006-01-02 21:49:21,071 INFO Some information > 2006-01-02 21:49:21,071 WARNING A shot across the bows > > This is with Python 2.4.2 on Win2K. What version of Python are you > using? In versions previous to 2.4, basicConfig() doesn't take keyword > args. For the Python 2.3 docs see > http://www.python.org/doc/2.3.5/lib/module-logging.html > > and the example here: > http://www.python.org/doc/2.3.5/lib/node304.html > > Kent Ah yeah, that would be it. I'm using 2.4. Thanks Bernard ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] How to make to exit the loop, while typing Enter
Hi I am trying to write a program in which it ask for entries for the list , But if I press Enter it should exit the while loop without giving errors ,I have problem in making it work , right now if I press enter to exit , the program terminates showing error I am added my script which I wrote Advice requested Thanks Joseph # # How to exit , when user Press Enter # While Entering Data # # define array array = [] m = 0 print "Enter to exit" m = int(raw_input("Enter the Values for The Array : ")) array.append(m) print array while m != "": m = int(raw_input("Enter the Values for The Array : ")) array.append(m) print array ___ Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Thanks , Now able to do Marks entry and display it using Histogram
Glad you got it working, now here are some picky comments about style: > # This program is to see how can we see how many > students got particular mark > # And how u print it An introductory comment is good but in Python a common way to do that is to use documentation strings, typically using triple quotes: """This program is to see how can we see how many students got particular mark And how u print it """ Now if you import your module and do print modulename.__doc__ or even help(modulename) Python will print the doc string for you whioch can be useful and saves you opening the file in an editor to read the comments. You can do the same with functions and classes when you get around to using them... > print " \nFirst Enter the No of Students ... " > print "\n Then No of marks " This is kind of redundant since your raw_input promprts tell us what to do each time. > # defining empty array array > array = [] calling something an array is pretty meaningless, it might be better to call it marks or scores or something else that decribes its purpose rather than its structure. One of the design goals of a good programme should be to hide the details of *how* a program is built from the reader and reveal *why* the program is built the way it is.. The same applies to comments. > # defining i > i = 0 So the comment above is pretty much redundant since we can see that we are defining i.The more important question is - what is i for? Its a counter so why not call it that? > # n is the NO of students which I have to enter the > marks > n = int(raw_input("Enter the no: of students : \n")) So why not call it numStudents or similar, then you wouldn't need the comment and the following code will be much more obvious in its meaning. > # m is the Marks of the students which I have to enter m? I see no 'm'. But I do see a 'marks' variable which is self evident. Looks like to anticipated my comment here! :-) Although being really picky I'd probably suggest mark since it only holds one mark at a time... marks implies (to me at least) some kind of collection. > while i < n: >marks = int(raw_input("Enter the Marks for the > students : \n")) >array.append(marks) >print "Marks are ", marks >i = i+1 > > #print "Array Marks ", array > > # Now to display How many students got the same marks > > j = 0 Why introduice a new counter? Just use the previous one. The more names you have in a programme the harder it is to remember what they are all for - especially if they are single letter names. You finished with the counter above so why not just reinitialise it here. > ## > #To Display the histograph of the students Marks > #25 is the Max marks > # > > for j in range(25): >print j,"x" * array.count(j) >j += 1 Not sure why you increment j since the for loop does that for you. BTW. Another approach to this problem would be to use a dictionary. That way you can count the occurences as they are added: """ This program is to see how can we see how many students got particular mark And how u print it """ scores = {} mark = int(raw_input('mark?(-1 to end) ')) while mark != -1: try: scores[mark] += 1 except KeyError: scores[mark] = 1 # first time for this mark mark = int(raw_input('mark?(-1 to end) ')) for key in scores: print key,' x' scores[key] You can tidy that up and avoid the try/except by using the get() method of a dictionary, but I'll leave that as an excercise! Hint: use a default value of zero.:-) HTH, Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Thanks , Now able to do Marks entry and display it using Histogram
John Joseph said unto the world upon 03/01/06 02:02 AM: > Hi All > Thanks to Shantanoo,Brian,Alan,Owen > Now I am able to enter the marks for each > students , and display the results the frequency of > marks in histogram > Even though I am able to display the > histogram of the marks with students , I would like > to modify it further as I learn more , I am adding the > program which I had done >Thanks to the list , I am getting more > encouragement here ,it is fun over here > Thanks >Joseph John Joseph, great :-) It is a friendly place to learn. I have a suggestion about one way you might take your efforts to improve things. > ## > #To Display the histograph of the students Marks > #25 is the Max marks > # > > for j in range(25): > #print j , "is ",array.count(j) > print j,"x" * array.count(j) > j += 1 Hard-coded magic numbers like 25 here are something it often pays to eliminate. If you know that every test or assignment for the entire future of time is out of 25, then it is fine. But, you can plan for the future and be more general by trying to accommodate varying point totals. If you try that and get stuck, post about it. Good luck with however you choose to improve your approach. Best, Brian vdB ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Thanks , Now able to do Marks entry and display it using Histogram
Hi All Thanks to Shantanoo,Brian,Alan,Owen Now I am able to enter the marks for each students , and display the results the frequency of marks in histogram Even though I am able to display the histogram of the marks with students , I would like to modify it further as I learn more , I am adding the program which I had done Thanks to the list , I am getting more encouragement here ,it is fun over here Thanks Joseph John *** # This program is to see how can we see how many students got particular mark # And how u print it print " \nFirst Enter the No of Students ... " print "\n Then No of marks " # defining empty array array array = [] # defining i i = 0 # n is the NO of students which I have to enter the marks n = int(raw_input("Enter the no: of students : \n")) # m is the Marks of the students which I have to enter while i < n: marks = int(raw_input("Enter the Marks for the students : \n")) array.append(marks) print "Marks are ", marks i = i+1 #print "Array Marks ", array # Now to display How many students got the same marks j = 0 ## #To Display the histograph of the students Marks #25 is the Max marks # for j in range(25): #print j , "is ",array.count(j) print j,"x" * array.count(j) j += 1 ___ To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor