[Tutor] Starting over with Python
After quite a while away from Python, I have decided to re-study Python. I am interested to learn Python to support my love for Cryptography. I have a first very easy question (did some search on Google but could not find anything helpful). I realise that this is very basic so be gentle with me. If i insert the following script: - odd =1 while odd =100: if (odd%2)==1: print odd odd = odd + 1 - I get a list of the odd numbers from 1 to 99. But now if I wanted to add those number together (i.e. 1 + 3 +5 + 7 etc.), what line of coding should I include? I have tried to add odd + odd but it did not work. In advance thanks. If anyone could direct me to some site where python is associated with Cryptography I would be very grateful. Many thanks JC _ Be the first to hear what's new at MSN - sign up to our free newsletters! http://www.msn.co.uk/newsletters ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject). Ord and Chr query
Hi Ben, you wrote --- John Carmona [EMAIL PROTECTED] wrote: Ben I could not get your script working indentation? You were right, it is working now, thanks JC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject). Ord and Chr query
To all that have answered, many thanks. I will check the tutorials that have been pointed out to me. I have also got the Dive into Python printed and I will start reading that one too pretty soon. I am off on holiday starting Tuesday so I won't have the time to study too much in the next couple of days (maybe at work if it is quiet...). Speak to you soon guys and thanks again JC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject). Ord and Chr query
Pujo, Alan, John and Ben, thanks for the input. Sorry I should have been clearer with the query perhaps. Alan I am just going through the book Learning Python written by Lutz and Ascher, and this is part of one exercise. I am still having problem in putting my head around in writting even very simple script. I can see the whole picture but have enormous problem in putting it down to paper (or screen). Once I see the solution I can really understand. I am actually archiving everything that I am learning. Problem is I am not a programmer, I don't use Python on a regular/daily basis so of course it seems that the learing curve is very steep but I am really enjoying it. Pujo you were spot on again, thanks. Ben I could not get your script working I am probably screwing up somewhere. John can you see now the reason why I was asking those questions, sorry for not being clearer (i have even forgoten to put a line on the subject... Regards JC See you soon ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] read() question
MyText = open('The_text.txt','r').read() In the above line could someone tell me what the 'r' stand for. Many thanks JC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] need a example of translate or maketrans
Terry, thanks very much that was very helpful right at this moment :) This is what beginners like me needs small example that explain very well how to use some of the functions. I found sometimes that the explanation on the book or the documentation going over my head because they don't show a concrete example. Thanks again JC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Challenge - Riddle 2
Hey Liam thanks again for the hint. I have finally managed to use the ???trans function. But now apply it to the URL, I am lost again. (I did apply it to the URL-twice) but nope, nothing is happening. One more hint if possible. Thanks JC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Challenge - Riddle 2
This is what I did. I have tried the whole field, part of the URL (after the .com), etc.. I Just get the old 404 not found message. JC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Challenge - Riddle 2
copied the URL, paste it in my script in Python and run it (once) did not get nowhere, then did it a second time, and again did not get nowhere. JC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Challenge - Riddle 2
To all thanks I have got it now!!! JC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python Challenge - Riddle 2
OK I am stuck on this one. I see what I need to do (correct me if I am wrong). But I need to write a script that will replace each letter by another one (In this case a -- c etc.). I look at String, List and Dictionary. I thought I could use the text.replace option but I am not sure. Anybody to put me in the right track. Also how can I add my work email address (but keeping this one) to have the mail forwarded to me, they have cut access to my hotmail at work and I am wasting too much time in waiting to go home to check my emails from Python.org. Many thanks JC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Challenge - Riddle 2
Thanks Liam, I will start checking this afternoon. Regards JC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python challenges
Hi to everybody reading this thread, can anybody point me to the URL where I can find these challenges. Many thanks JC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Re Help with this script
Hi Alan, I did not receive personally your last email but I have read it on the forum. OK i understand now what you were talking about, sorry it took such a long time for me to see the solution, the good thing about it is that I am learning tons. I will probably post soon again once I hit a wall on my next exercise. Thanks a million for your help (also Kent and John - I will try to rewrite your poem/exercise once I get a minute, thanks) Regards JC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Re Help with this script
OK Alan, I thing I have seen the light!!. Here is the script that Kent and you asked me to look at modified: - def print_options(): print -- print Options: print a. print options print f. quit the programme print -- print_options() choice = 0 while choice != 'f': print choice = raw_input(Choose an option: ) if choice == 'a': print Here we go again print_options() if choice == 'f': break print_options() - Is it that if you use while 1: you create a recursive function? Hope I am right. Thanks JC PREVIOUS EMAIL OK the situation is that I haven't still found out what the answer is, I have noticed in the other hand that if I select the option a let's say 4 times, I need to enter the option f 4 times. I am curious to know what the solution is. I have read your chapter on recursion but that did not clear anything. OK, basically the problem is that you have unintentionally created a recursive function. Every time you call it you create a new copy of the function. When you exit the function you wind up back in the previous copy. So as many times as you call the function you have to exit it the same number of times to get back to the top of your program. Have a think about it, and see if that makes sense. 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] Re Help with this script
Hi Alan, sorry for not replying sooner I am right in the middle of setting up a network at home. Thanks for your email. OK the situation is that I haven't still found out what the answer is, I have noticed in the other hand that if I select the option a let's say 4 times, I need to enter the option f 4 times. I am curious to know what the solution is. I have read your chapter on recursion but that did not clear anything. As soon as i get a minute I will look again. Thanks JC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Re Help with this script
Thanks Kent, as far as I can see I get the same problem that on my script, i need to enter f 3 to 4 times before I exit the programme. Hmmm, why, I can't see it really, i thought that the fact to have the break command would terminate the script straight away. If I enter f first then the programme ends. What am i missing? JC John Carmona wrote: Thanks for the help Kent, Noel and Alan. Here is my final script (it seems to be working ok but sometimes if I select quit the programme, I need to enter that option 2 or 3 times before it works, is this a bug Try this program. Choose option a a few times, then choose f enough times to exit. See if you can figure out what is going on. def print_options(): print -- print Options: print a. print options print f. quit the programme print -- while 1: choice = raw_input(Choose an option: ) if choice == 'a': print 'About to call print_options' print_options() print 'Finished calling print_options' if choice == 'f': break print_options() Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Re Help with this script
Thanks for the help Kent, Noel and Alan. Here is my final script (it seems to be working ok but sometimes if I select quit the programme, I need to enter that option 2 or 3 times before it works, is this a bug (I am running Win XP), please feel free to comment if you thing that something could be improved. Time to do the next exercise. JC #By J Carmona #Programme that compute volumes or surfaces ##First menu is for the calculation of area ##Second menu is for the calculation of volume ##First ask the user what he wants to do running = True def area_rect(): length = input(Length: ) width = input (Width: ) print The area is: ,length*width def area_circ(): radius = input(What is the radius?: ) print The area is approximately: , 3.14159*(radius**2) def area_squ(): side = input (What is the length of one side?: ) print The area is: , side*side def area_tgle(): base = input (What is the base of the triangle?: ) heigth = input (What is the heigth of the triangle?: ) print The area is: ,base*heigth/2 def vol_sph(): radius = input(What is the radius?: ) print The volume is: , (4*3.14159*radius**3)/3 def vol_cube(): side = input(Side: ) print The volume is: ,side**3 def vol_box(): width = input (What is the width of the box?: ) length = input (What is the length of the box?: ) depth = input (What is the depth of the box?: ) print The volume is: , width*length*depth def vol_cone(): radius = input (What is the radiux of the base of the cone?: ) heigth = input (What is the heigth of the cone?: ) print The volume is: , 0.*3.144159*(radius**2)*heigth def task_options(): print --- print Options: print a. Print options: print b. Do you want to calculate areas?: print c. Do you want to calculate volumes?: print d. Quit the programme print --- choice = raw_input(Choose an option: ) if choice == 'a': print task_options() elif choice == 'b': print print_options() elif choice == 'c': print print_options_2() elif choice == 'd': running = False def print_options(): print_options print -- print Options: print a. print options print b. calculate circle area print c. calculate square area print d. calculate rectangle area print e. calculate triangle area print f. quit the programme print -- while 1: choice = raw_input(Choose an option: ) if choice == 'a': print_options() elif choice == 'b': area_circ() elif choice == 'c': area_squ() elif choice == 'd': area_rect() elif choice == 'e': area_tgle() if choice == 'f': break def print_options_2(): print -- print Options: print a. print options print b. calculate the volume of a sphere print c. calculate the volume of a cube print d. calculate the volume of a box print e. calculate the volume of a cone print f. quit the programme print -- while 1: choice = raw_input(Choose an option: ) if choice == 'a': print_options() elif choice == 'b': vol_sph() elif choice == 'c': vol_cube() elif choice == 'd': vol_box() elif choice == 'e': vol_cone() elif choice == 'e': print_options() if choice == 'f': break #Call starting menu task_options() ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] How can I suspend...
I am off to sunny Spain for the next 2 weeks and I would like to suspend the emailing from Python.tutor for that period. Could someone put me in the right direction on how to do that, thanks. Regards JC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Re: Calendar question
Kristian you have said: - I can think of 2 ways to accomplish this. 1. Try to convert monthString to an int, use the lookup if that fails. This might be a good way to learn try/except processing. 2. Just double-up your dictionary to include a second set of keys: {'1':1, '2':2 ...} and just use your existing lookup method, unmodified. You wouldn't have to worry about string-int conversion after raw_input this way, so it's cleaner to implement. - When you say to double-up the dictionary do you mean using the following method: Dict = [{1:1,2:4,etc.}, {3:9,4:16, etc}] Thanks JC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Calendar question
I am back, thanks again all to help me sorting out the High_Low guessing game using time. Can somebody put me on the right track for the following script. I know how to use the calendar.prcal command to print the 12 months of choosen year. But how do you use the prmonth command, if you, for example, want to write something asking you: to enter a year (this I know) to enter a month of that year and print just the month I look and some of the previous posts, search the net but could not find anything specific. Thanks Also, I have been looking for some exercises to do using Python, obviously (and unfortunately) they need to be at a beginner level. Or better if anyone wants to send me one to do I would be very grateful Thanks JC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Calendar question
Thanks Kristian, it works a treat. Now you have set me up with finding out how to use the months entered by name. If I am stuck I will post again. Thanks very much JC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Calendar question
Kristian you wrote: - This assumes all input as integers; if you want months entered by name, you'll have to write a conversion routine (hint: use a dict). - I have been looking for a while about doing a conversion routine (using a dictionary??), are you saying that I should convert a string (January, February, etc.) into integers. Could you please give me some light (do not write the code please but just point me to the right direction if you can) Many thanks JC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What is the best book to start? - Many Thanks!
Dear Hoffmann, I am also a Newbie and I am currently going through A Byte of Python tutorial from Swaroop C H. http://www.byteofpython.info/download?PHPSESSID=c0d52343d90f69f25942f49df9ae7944 If you are completely new to programming like me, you will find that this tutorial is excellent. Good luck JC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] I am puzzled - help needed
Alan and John thanks for the help. I have now this bit of script but it is not running. -- from time import * n = time() s = str(n) numb = s[-2:] # last two characters of the string numb = int(numb) # convert back to a number guess = (raw_input('Enter a number: ')) if guess == numb: print (Bravo, you have just won the right to play again!) elif guess numb: print You are just a bit too low, try again else: print You are just a bit too high, try again print The End -- If i write the following line: n = time.time() I get the following error message: --- Traceback (most recent call last): File C:/Python24/Example/high_lowtest.py, line 3, in -toplevel- n = time.time() AttributeError: 'builtin_function_or_method' object has no attribute 'time' I feel like an idiot asking what is probably very basics questions but my desire to learn is quite high right now and I don't want to lose it, thanks again ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Calendar module
Hi guys, I have typed this programme from the Josh Cogliati manual - import calendar year = input(Type in the year number: ) calendar.prcal(year) I get this error message Traceback (most recent call last): File C:/Python24/Example/cal.py, line 1, in -toplevel- import calendar File C:\Python24\Example\calendar.py, line 4, in -toplevel- calendar.prcal(year) AttributeError: 'module' object has no attribute 'prcal' And for some reason it does not work. I saved it as cal.py and it is running from the same folder that hold Python 2.4 (I run XP) any reason why it is not working (I managed to make it work at my workplace by the way. JC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] I am puzzled - help needed
I am not sure that it is possible to ask that question please feel free to turn me down if it is going against the forum rules. I have going through Josh Cogliati tutorial, I am stuck on one of the exercise. I need to rewrite the high_low.py program (see below) to use the last two digits of time at that moment to be the random number. This is using the import time module. I just can't work out how to do that, I have been looking at it for the past 2,5 hours but can't break it. Has anyone done it in order for me to study it. Many thanks in advance for any help JC This is the original programme: number = 78 guess = 0 while guess != number guess = input (Guess a number: ) if guess number: print Too high elif guess number: print Too low print just right ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Defining functions
Hi there, I have written (well almost as I copied some lines from an existing example) this little programme - part of an exercise. #By J Carmona #Programme that compute area for #circle, square, rectangle def area_rect(): length = input(Length: ) width = input (Width: ) print The area is: ,length*width def area_circ(): radius = input(What is the radius?: ) print The area is approximately: , 3.14159*(radius**2) def area_squ(): side = input (What is the length of one side?: ) print The area is: , side*side def print_options(): print -- print Options: print 1. print options print 2. calculate circle area print 3. calculate square area print 4. calculate rectangle area print 5. quit the programme print -- choice = input(Choose an option: ) if choice == 1: print_options() elif choice == 2: area_circ() elif choice == 3: area_squ() elif choice == 4: area_rect() elif choice == 5: print_options() #Call starting menu print_options() If I try to change the 1, 2, 3, 4 or 5 by a letter i.e. a, b, c, d, e the programme stop functionning. I get an error message saying that Traceback (most recent call last): File C:/Python24/Example/area_cir_squ_regt.py, line 39, in -toplevel- print_options() File C:/Python24/Example/area_cir_squ_regt.py, line 27, in print_options choice = input(Choose an option: ) File string, line 0, in -toplevel- NameError: name 'c' is not defined What am I missing? Thanks JC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] I need some guidance
Hi to everyone first, this is my first posting and I hope that I won't make a mess. I am 100% newbie (and when I mean newbie it is with a big N). I decided to have a go at programming and after reading different articles I decided to have a go at Python (first because it is free, secondly because apparently it is easier than other languages). The reason for me to try to learn programming is that I have been involved with computer (graphic operator) but I have decided to modify my profesionnal path (risk of future redundancy) and want to equip myself better. I have started by reading the excellent Non-ProgrammersTutorial For Python by Josh Cogliati. I like it a lot. My first problem is as I don't have any experience in programming I sometimes get a bit lost in the explanation (i.e. I am just learning about Defining Functions. It fascinates me, but it is taking me a long to get around it. My first question is do i need to really understand everything first time I come across or does it get easier if you kind of move along and get back to it later? Second question: As i am not, unfortunately, involved professionaly in the field of programming is there a specific technique to learn other than just read everything I put my hand on? Third question: Does anybody know if it is possible to get involved in this field in a non-lucrative kind of way in order to learn faster and of course to apply this science in a real world. I guess it's enough question for now, sorry to bore you as you probably have seen this question over time. I apologise for my English as it is not my first language and thank in advance anybody that will help me with my queries. Thanks JC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor