[Tutor] How to print a variable from an if/else statement
Message: 3 Date: Wed, 12 Sep 2012 09:32:38 + From: chrisbv...@gmail.com To: tutor@python.org Subject: [Tutor] How to print a variable from an if/else statement Message-ID: 2057338575-1347442886-cardhu_decombobulator_blackberry.rim.net- 2019341514-@b3.c12.bise6.blackberry Content-Type: text/plain Hello, I'm very new thanks in advance for your help. My If statement is: If age (40): Print(you are young.) Else: Print(You look great.) Basically what I want to do is have a sentence using print that includes the results of the If or Else which is based on the users input of age. I don't know if I'm doing something wrong by doing it this way. I can't figure it out. Thankyou! Chris Sent via BlackBerry by ATT My first time answering the list!!! (sorry for this outburst!) From my limited knowledge your if/else statement is correct BUT your print should start with lower caps, that's why it's not working. You can see here a bunch of examples on how to use it properly - http://docs.python.org/release/3.0.1/library/functions.html?highlight=print#print Hope this helps! Cheers! Joaquim Santos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] new to programming and wondering about an IDE for Python on Linux (Robert Sjoblom)
-- Message: 1 Date: Mon, 27 Feb 2012 20:10:42 +0100 From: Robert Sjoblom robert.sjob...@gmail.com To: Alan Gauld alan.ga...@btinternet.com Cc: tutor@python.org Subject: Re: [Tutor] new to programming and wondering about an IDE for Python on Linux Message-ID: CAJKU7g03k2e+mJU8SZAmQnEjEEtXnk0x87Df9hhLoscq00=p...@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1 I'd appreciate any feedback on this and good tutorials or books on Python 3 and the IDEs suggested. There are many available and I'm wondering what you as users find effective. I fiddled a bit with the Eric Python IDE; Eric5 for Python3 and Eric4 for Python2; overall I'd say that Eclipse was a better experience, but Eric was by no means bad. I guess it comes down to user preferences. As for books, Dive Into Python 3 is one of the better books I've come across. http://eric-ide.python-projects.org/ -- best regards, Robert S. - My 2 cents on that (being also a beginner...). A very interesting and customizable IDE for Linux is the Spyder project. http://code.google.com/p/spyderlib/ It was previously known as Pydee and has lot's of features that I, as a beginner, find good, like the calltips, function browser, console, online help... and so on! Best regards! Joaquim Santos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Still the Python Challenge - Conclusion
Hi List! I just want to say thank you to all that helped me out! I've now seen the errors I was doing and how to correct them. Now it works as it should. I'll be sure to come back with more questions! And one day help out someone else! This is my script (I know that I only verify a small range but it works for what I want for now...) import string def decrypt(cypheredText, shiftedCypherNumber): ''' This function will take two arguments. The first is the cyphered text, the second is the number of characters we need to shift the text so we can decrypt it. This is a Caesar cypher. ''' textTranslated = list() for letter in cypheredText: asciiValue = ord(letter) if asciiValue in range(97, 123): asciiValue += shiftedCypherNumber if asciiValue 122: asciiValue -= 26 newLetter = chr(asciiValue) textTranslated.append(newLetter) joinedText = ''.join(textTranslated) return joinedText text = 'g fmnc wms bgblr rpylqjyrc gr zw fylb' a = decrypt(text, 2) print a and this is the end result: i hope you didnt translate it by hand -- Joaquim Santos http://js-vfx.com linkedin ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Still the Python Challenge - Conclusion
Hi Robert! Thanks for the heads up on the Style Guide. I'll read out the links you pointed out to me. About the script, result and Python Challenge, I apologize, however... in previous emails bigger pointers were given speaking about using 'maketrans' to solve the challenge. My way was a work around that I was trying to implement since day 1 and that can be (and maybe it will be) used as a base for a (non-serious) deciphering program. So, again, I'm sorry for presenting too much information, however more important parts where said already and if people are willing to find out by searching a list/web instead of trying out by themselves... they are going to find it! Cheers! 2012/1/5 Robert Sjoblom robert.sjob...@gmail.com: On 5 January 2012 19:41, Joaquim Santos jsantos.la...@gmail.com wrote: Hi List! [...] This is my script (I know that I only verify a small range but it works for what I want for now...) import string def decrypt(cypheredText, shiftedCypherNumber): ''' This function will take two arguments. The first is the cyphered text, the second is the number of characters we need to shift the text so we can decrypt it. This is a Caesar cypher. ''' textTranslated = list() for letter in cypheredText: asciiValue = ord(letter) if asciiValue in range(97, 123): asciiValue += shiftedCypherNumber if asciiValue 122: asciiValue -= 26 newLetter = chr(asciiValue) textTranslated.append(newLetter) joinedText = ''.join(textTranslated) return joinedText text = 'g fmnc wms bgblr rpylqjyrc gr zw fylb' a = decrypt(text, 2) print a and this is the end result: First of all, congratulations on solving it. Second, please don't include the answer to any python challenges to this list as future members or people searching for help with the same particular challenge might not want to know the answer. Thirdly, I think you should read PEP 8 - Style Guide for Python Code, but I'll quote the absolutely most relevant part: Use blank lines in functions, sparingly, to indicate logical sections. You don't need a blank line after every line of code; in fact, it makes it harder to read. Where does one block end and another begin? PEP 257 describes good docstring conventions. Note that most importantly, the that ends a multiline docstring should be on a line by itself, and preferably preceded by a blank line, def decrypt(cypheredText, shiftedCypherNumber): '''This function will take two arguments. The first is the cyphered text, the second is the number of characters we need to shift the text so we can decrypt it. This is a Caesar cypher. ''' textTranslated = list() for letter in cypheredText: asciiValue = ord(letter) if asciiValue in range(97, 123): asciiValue += shiftedCypherNumber #and so on PEP 8 is really worth reading through: http://www.python.org/dev/peps/pep-0008/ there's also a link to PEP 257 in it. If you follow most of the suggestions in PEP 8 it will be much easier to read your code, and because of that easier to help you. -- best regards, Robert S. -- Joaquim Santos http://js-vfx.com linkedin ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Still the Python Challenge
Hi list! After this past week of no PC and no work, I'm again at the Python Challenge Cypher problem. I decided to go with the flow and solve it with maketrans (6 lines of code against the 40 and going I had already...) and it solved it quickly and clean! However, and please be sure I don't want to re-invent any wheel, I still got some doubts unexplained... - How to correctly populate a list using, for instance, a for loop; - how to correctly use join to read the said list in a human friendly way... This was the code I was using. for letter in cypheredText: asciiValue = ord(letter) if asciiValue in range(97, 123): asciiValue += shiftedCypherNumber if asciiValue 122: asciiValue -= 26 newLetter = chr(asciiValue) text = list() text.append(newLetter) joinedText = ' '.join(text) return joinedText Thanks for all your time and patience. Sorry for before not using Plain text! Joaquim Santos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python challenge and decryption
Hi again list! I've been trying to implement the feedback I got. So far, I removed the print statements from the function, limited the range (just for the z at the moment) and tried to get all printing in one or two lines... but without success... I don't know if I'm doing the join as it should... The new list I ended up trying to populate it with 2 different ways, but without success when joined... This is the new (and a improved) code: import string def decrypt(cypheredText, shiftedCypherNumber): ''' This function will take two arguments. The first is the cyphered text, the second is the number of characters we need to shift the text so we can decrypt it. This is a Caesar cypher. ''' for letter in cypheredText: asciiValue = ord(letter) if asciiValue in range(97, 123): asciiValue += shiftedCypherNumber if asciiValue 122: asciiValue -= 26 newLetter = chr(asciiValue) text = list() text.append(newLetter) joinedText = ' '.join(text) return joinedText text = 'g fmnc wms bgblr rpylqjyrc gr zw fylb' a = decrypt(text, 2) print a For the new list (text), I initially tried to do it like this - text = list(newLetter) and only now resorted to the append... which way is more correct? Or which is not correct at all? And why is the return giving me just one letter? (the last one...) Thanks for all the tips so far. The maketrans like suggested probably would be faster but I didn't knew about it and now that I'm trying to grind this on my own I kind of prefer it... I'm learning more then if I used a function or something... The ASCII table was invaluable in making me rethink my approach! Merry Christmas to all in the list! In case someone doesn't believe in it, have a very nice weekend and all the best! Joaquim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python challenge and decryption
Hi List! Thanks for all the input you guys gave me! I'm trying to implement your ideas on the function and I've been getting some parts right (the correct translation, still vertical and without spaces) or the wrong translation but with spaces... My problem is my range check. I'm also getting a funny problem with return, but I'll ask about it later. What I would like to know now, because it would help me a lot to draw my solution(I like to make sketches/line numbers while I'm thinking) was where to get the ascii table for Python! I searched and got a lot of modules and stuff to install and print it out but no printed online version? You can find for other languages, so where is the one for Python? I know I could install the said modules/scripts but I just think this should also be somewhere... -- Joaquim Santos http://js-vfx.com http://js-vfx.com/ *linkedin* ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python challenge and decryption
Hi list! This is my first post here but I've been following the list for some time now! I know that recently there was a message about decryption and all. I think that was what made me go back into the Python challenge and try to solve some of them... For the second one, I first laid on paper my ideas, about user interaction (or input) and what would do what. I haven't implemented the user input yet but as I tested I ended up having some problems. Anticipated but still annoying... My Python version is 2.7.1 and my OS is Linux Mint 11. My code is this one: def decrypt(cypheredText, shiftedCypherNumber): ''' This function will take two arguments. The first is the cyphered text, the second is the number of characters we need to shift the text so we can decrypt it. This is a Caesar cypher. ''' crypticText = list(cypheredText) for letter in crypticText: asciiValue = ord(letter) asciiValue += shiftedCypherNumber newLetter = chr(asciiValue) print newLetter This solves the riddle, however some characters are not correctly decyphered (a is coming back as {...) and prints the solution like this: r e c o m m e n d e d 0 n o w { p p l y o n t h e u r l - How can I make this Human readable? ... Print the letters in just one (or more) lines and maybe replace the for spaces (This one I suppose it could/should be done with whitespaces() or just making a loop to check and change those for ' '.) Thanks for your time! -- Joaquim Santos http://js-vfx.com http://js-vfx.com/ *linkedin* ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor