Re: [Tutor] python books
I know it's not in PDF, but I thought it would be worth mentioning Python for Software Design: How to Think Like a Computer Scientisthttp://www.greenteapress.com/thinkpython/index.html. I discovered this exactly a week after it was released, ordered it, and have been extremely happy with it so far. I am a student currently learning Java (unfortunately) and am really enjoying the original, knowledgeable examples and good presentation this book has to offer. Definitely one of my better book purchases, and significantly better than the Python Bible if I remember correctly. -Ian On Tue, Apr 14, 2009 at 4:12 AM, Alan Gauld alan.ga...@btinternet.comwrote: sudhanshu gautam sudhanshu9...@gmail.com wrote I am new in python , so need a good books , previously read python Bible and swaroop but not satisfied . so tell me good books in pdf format those contents good problems also Does it have to be in PDF? There are many, many excellent Python web sites with lots of information if you can use HTML. The most obvious starting points for you would be the official Python tutorial and Dive Into Python and also, maybe, the Thinking in Python web book. FWIW my tutorial is also available in PDF, but if you have read the other resources it is likely too basic for you. -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Inspiration/examples
I am just as interested in this. So far I've found http://openbookproject.net/pybiblio/practice/ from the openbookproject. -Ian On Sun, Mar 22, 2009 at 6:02 PM, Mathias Andersson zep...@gmail.com wrote: Hi all! Im currently trying to learn how to use python. But my only problem seems to be at what to make? So anyone have a nifty list or some ideas on things to program, school tasks or algorithms to try and implement. Beginner- to mid-skill level. Thanks in advance. /Mathias ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Simple User Entry Verification
Newbie here who can't figure out why this doesn't work: start = input(Please enter the starting number.\n) print(type(start)) while type(start)!=float: start = input(Sorry, that number was invalid.\nPlease enter the starting number.\n) print(type(start)) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Simple User Entry Verification
I'm sorry I wasn't more specifc. I will try to next time. Thanks Alan for you help. (Both of you.) -Ian On Sat, Mar 14, 2009 at 9:13 PM, R. Alan Monroe amon...@columbus.rr.comwrote: Success (as in number is entered) = Success Failure (as in a letter is entered) = failure Working as designed :) Python is _supposed_ to throw an exception when trying to convert text to float. Have you learnt about try/except statements yet? If not, that's your next stop. Alan ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Convert String to Int
Actually, nobody told me how to catch it before it occurs, though this after error stuff is new to me. Could you send an example of how to catch it beforehand? Just for the record? Thanks. Ian On Sun, Jan 18, 2009 at 8:35 PM, Marc Tompkins marc.tompk...@gmail.comwrote: On Sun, Jan 18, 2009 at 5:15 PM, Ian Egland echol...@gmail.com wrote: I know that, should you want to get an int from the user, you use int(input(Question!)). However, what if the user wasn't that savvy and didn't realize he/she HAD to enter a number? Program crash. Is there a way that I can get the input as a string, check and see if it's convertible to an integer, convert it if it is and ask them to try again if it's not? You have two options: to test the input ahead of time, or to catch the crash. Believe it or not, number two is usually the preferred method (there's a programming axiom It's better to ask forgiveness than permission) In Python, you put the operations that have a potential for disaster inside a try/except block, like so: try: int(input(Question!)) do whatever... except: ask again... do the next thing When Python crashes, an Exception is generated, which carries all sorts of useful information about just what went wrong. It's good form to try to guess what the error might be before catching it (how many times have you been frustrated by some commercial program that says Out of memory {or some other catch-all} any time ANYTHING bad happens? It's because the programmer assumed that the only errors that would ever come up would be memory-related. Don't be that guy.) For example, do a test run like so: int('hello') Traceback (most recent call last): File input, line 1, in module ValueError: invalid literal for int() with base 10: 'hello' Now you know that invalid input would result in a ValueError, so change my above code to: try: int(input(Question!)) do whatever... except ValueError: ask again... do the next thing Someone else will no doubt already have posted how to test your input ahead of time - I thought I'd chime in with the other method... -- www.fsrtechnologies.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Best Python3000 Tutorial for Beginner
Hello all, I just joined this mailing list. I am a beginner to programming in general and would really appreciate a tutorial for Python3000 that at least covers the basics. I have tried reading the manual, but I think it was written for more experienced programmers wishing to switch to python rather than a beginner looking for where to start. Most of the other tutorials I have found were for earlier versions of Python, and because Python 3.0 was released on my birthday, I decided I was meant to learn that release. ;-) Anyway, any help would be appreciated. I will do my best to return the favor. -Ian ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Help with elif
Wow, that was a quick response! Thanks all! I have looked at a couple tutorials and whipped this up. However, attempting to run it in IDLE results in a syntax error leaving my elif highlighted in red. What's wrong? I've looked at the code and can't find any syntax errors- though I've just started. print([Temperature Converter, First Edition]) print(Created on January 17th, 2009 by Ian Egland) temp1 = int(input(Please enter a temperature: )) scale = input(Convert to (F)ahrenheit or (C)elcius?) if scale == F: temp2 = (9/5)*temp1+32 print(temp1, C =, temp2, F elif scale == C: # Error appears here. temp2 = (5/9)*(temp1-32) print(temp1, F =, temp2, C else: print(Sorry, you must enter either an F or a C. Case-sensitive. Please try again. In regards to learning python, I've found that after I get somewhat-familiar with a language, I want a programming problem to solve with what I've learned. While learning Java, http://www.javabat.com has been my best friend. (That is, as close to a best friend as programming website can be.) Is there something like this for Java? Is one in the works? -Ian ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Fixed
Found it- wasn't closing the ()'s in the print()'s. Thanks anyway, sorry for filling your inbox. -Ian ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] New 2 Python- Script 'kill' function/Ubuntu File Browser hide hidden files
Hello, I am new to Python (and OO programming in general) and I have a script that I made through a tutorial. # -*- coding: utf-8 -*- # Copyright (C) 2007-2008 Ian Egland # From the Non-Programmer's Guide to Python By Josh Cogliati # 5.3 Exercise 1 # Modify the password guessing program to keep track of how many times the user has entered the password wrong. # If it is more than 3 times, print That must have been complicated. tries = 3 password = What is the password? while password != thepassword: print You have, tries, remaining. print What is the password? password = raw_input( ) if password == thepassword: print You got the password in only, 3 - tries, tries! else: tries = tries - 1 if tries == 0: print Sorry... but that was wrong. (again) Your not as smart as I thought... else: print I am sorry, that was incorrect. Please try again. quit Now I cant see anything wrong with it... except that I don't think that quit is the right function as when I run it this happens. Python 2.5.1 (r251:54863, Oct 5 2007, 13:36:32) [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2 Type copyright, credits or license() for more information. Personal firewall software may warn about the connection IDLE makes to its subprocess using this computer's internal loopback interface. This connection is not visible on any external interface and no data is sent to or received from the Internet. IDLE 1.2.1 No Subprocess You have 3 remaining. What is the password? is this it? I am sorry, that was incorrect. Please try again. You have 2 remaining. What is the password? really? I am sorry, that was incorrect. Please try again. You have 1 remaining. What is the password? omg one more left Sorry... but that was wrong. (again) Your not as smart as I thought... You have 0 remaining. What is the password? ...huh? I am sorry, that was incorrect. Please try again. You have -1 remaining. What is the password? lol I am sorry, that was incorrect. Please try again. You have -2 remaining. What is the password? I am using the while function, so I know that it will loop the script forever unless I kill the application, but I don't know the command to kill it. Also, I am doing this in Ubuntu linux and hidden files are defined as .filename. However, they are displayed in IDLE- so I have to scroll past about 5 columns of hidden folders till I get to the 'visible' ones, which contain my scripts. Any ideas on how to get IDLE not to reconize any file/folders with the prefix '.'? Thanks a million. I really am a nooB. -- -Ian My Website: http://www.64digits.net/ My Signature Page: http://www.64digits.net/signature/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] New 2 Python- Script 'kill' function/Ubuntu File Browser hide hidden files
Thanks, you helped more than you know. -Ian On Jan 13, 2008 3:58 PM, bob gailer [EMAIL PROTECTED] wrote: Ian Egland wrote: Hello, I am new to Python (and OO programming in general) and I have a script that I made through a tutorial. # -*- coding: utf-8 -*- # Copyright (C) 2007-2008 Ian Egland # From the Non-Programmer's Guide to Python By Josh Cogliati # 5.3 Exercise 1 # Modify the password guessing program to keep track of how many times the user has entered the password wrong. # If it is more than 3 times, print That must have been complicated. tries = 3 password = What is the password? while password != thepassword: print You have, tries, remaining. print What is the password? password = raw_input( ) if password == thepassword: print You got the password in only, 3 - tries, tries! else: tries = tries - 1 if tries == 0: print Sorry... but that was wrong. (again) Your not as smart as I thought... else: print I am sorry, that was incorrect. Please try again. quit Now I cant see anything wrong with it... except that I don't think that quit is the right function as when I run it this happens. quit is a function. The line above is a reference to the function rather than a call to the function. To call a function you must always add () e.g. quit(). Your goal here is to break out of the while loop. You can accomplish that with the break statement in place of the quit function call. I'd code this differently, to take advantage of the for loop and to reduce redundant code. I also corrected spelling, introduced a constant and enhanced things so try is singular or plural as needed. MAXTRY = 3 for tries in range(MAXTRY, 0, -1): if tries == 1: print You have 1 try remaining. else: print You have, tries, tries remaining. print What is the password? password = raw_input( ) if password == thepassword: attempts = MAXTRY - tries + 1 if attempts == 1: print You got the password in only 1 try! else: print You got the password in only, attempts, tries! break elif tries 1: print I am sorry, that was incorrect. Please try again. else: print Sorry... but that was wrong. (again) You're not as smart as I thought... That is more than you requested, and I hope it all helps your learning. [snip] -- -Ian My Website: http://www.64digits.net/ My Signature Page: http://www.64digits.net/signature/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] How to stop a script.
Hi everyone... I litterally just started python and did the following 'hello world' related tutorial. http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro http://hkn.eecs.berkeley.edu/%7Edyoo/python/idle_intro Being the kind of person who like to experiment, I tried changing the following script from: print Hello World! print Here are the ten numbers from 0 to 9, just in case you can't count. for i in range(10): print i, print I'm done! to: print Hello World! print Here are the ten numbers from 0 to 9, just in case you can't count. for i in range(1000): print i, print I'm done! Now I am stuck staring at IDLE as it prints out all 10million numbers. Is there a way other than closing the shell to stop a script midway through execution? -Ian ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Fwd: How to stop a script.
Thanks, I will keep that in mind the next time I experiment. :-P -Ian -- Forwarded message -- From: Tiger12506 [EMAIL PROTECTED] Date: Dec 28, 2007 5:42 PM Subject: Re: [Tutor] How to stop a script. To: tutor@python.org Ctrl+c will issue a KeyboardInterrupt which breaks out of programs such as the one you described. (The only situation it doesn't is when the program catches that exception. You won't see that 'til you get your sea legs ;-) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor