Re: [Tutor] Python Help
On Tue, 28 Sep 2010 02:15:52 pm masawudu bature wrote: I'm having a hard time finding the count of divisors that are even. Help anybody? Here's my code. The output is suppose to count the number of even divisors the range has. I don't understand the question. What do you mean by divisors the range has? Perhaps you should show an example, and give the answer you expect. This function is troublesome: def evenCount(b) : for n in range(x, y+1) : count = 0 if n % 2 == 0 : count += n/3 count % n == 1 return n What's b? It is never used. Every time through the loop, you start the count at zero again. This function will always return y, the stopping value. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python Help
I'm having a hard time finding the count of divisors that are even. Help anybody? Here's my code. The output is suppose to count the number of even divisors the range has. def evenCount(b) : for n in range(x, y+1) : count = 0 if n % 2 == 0 : count += n/3 count % n == 1 return n ### main x = input(Enter a starting value: ) y = input(Enter a stopping value: ) count = evenCount(x) for n in range(x, y+1) : count = 0 if n % 2 == 0 : count += n/3 print %2d: %n, has%2d %count, even divisors, else : print %2d: %n, has 0 even divisors, print ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Help
On Tue, Sep 28, 2010 at 12:15 AM, masawudu bature mass0...@yahoo.ca wrote: I'm having a hard time finding the count of divisors that are even. Help anybody? Here's my code. The output is suppose to count the number of even divisors the range has. def evenCount(b) : for n in range(x, y+1) : count = 0 if n % 2 == 0 : count += n/3 count % n == 1 return n ### main x = input(Enter a starting value: ) y = input(Enter a stopping value: ) count = evenCount(x) for n in range(x, y+1) : count = 0 if n % 2 == 0 : count += n/3 print %2d: %n, has%2d %count, even divisors, else : print %2d: %n, has 0 even divisors, print ___ Tutor maillist - tu...@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor #You start with your range variables x = input(Enter a starting value: ) y = input(Enter a stopping value: ) #You set a for loop for range for num in range(x, y): #If that number divided by 2 has a remainder of 0, it's of course even. if num % 2 == 0: #print the number print num And various other ways as well. David ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Help - How to end program
Jason MacFiggen jmacfig...@gmail.com wrote Python keeps looping when it gets past the int 0, how do I end the program when it the int 0 or 0. while True: if mo_hp 0: print The Lich King has been slain! elif my_hp 0: /etc... When using a while True loop you need ttto have an explicit break statement somewhere to get out. Personally I like to keep that statement near the top of the loop if possible - just so that I can find it easily! So in your case I'd add a test like if mo_hp = 0: break right at the top of the loop. If there were other statements after the loop these would then get executed but since you don't your program will naturally terminate. Note that if you had an else clause in your while loop(quite unusual) it does not get executed after a break - the only useful feature I've found for a loop else condition! ie while True: break else: print 'never executed' print 'exited' HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python Help - How to end program
Python keeps looping when it gets past the int 0, how do I end the program when it the int 0 or 0. my_hp = 50 mo_hp = 50 my_dmg = random.randrange(1, 20) mo_dmg = random.randrange(1, 20) endProgram = end() while True: if mo_hp 0: print The Lich King has been slain! elif my_hp 0: print You have been slain by the Lich King! if mo_hp = 0: endProgram else my_hp = 0: endProgram else: print Menu Selections: print 1 - Attack print 2 - Defend print choice = input (Enter your selection. ) choice = float(choice) print if choice == 1: mo_hp = mo_hp - my_dmg print The Lich King is at , mo_hp, Hit Points print You did , my_dmg, damage! print my_hp = my_hp - mo_dmg print I was attacked by the lk for , mo_dmg, damage! print My Hit Points are , my_hp print elif choice == 2: mo_hp = mo_hp - my_dmg / 2 print The Lich King is at, mo_hp, Hit Points print you did , my_dmg / 2, damage! print my_hp = my_hp - mo_dmg print I was attacked by the lk for , mo_dmg, damage! print My Hit Points are , my_hp print -Thank you ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Help - How to end program
Jason Are you trying to prevent negative numbers? Ben --- On Wed, 7/28/10, Jason MacFiggen jmacfig...@gmail.com wrote: From: Jason MacFiggen jmacfig...@gmail.com Subject: [Tutor] Python Help - How to end program To: tutor@python.org Date: Wednesday, July 28, 2010, 9:01 PM Python keeps looping when it gets past the int 0, how do I end the program when it the int 0 or 0. my_hp = 50 mo_hp = 50 my_dmg = random.randrange(1, 20) mo_dmg = random.randrange(1, 20) endProgram = end() while True: if mo_hp 0: print The Lich King has been slain! elif my_hp 0: print You have been slain by the Lich King! if mo_hp = 0: endProgram else my_hp = 0: endProgram else: print Menu Selections: print 1 - Attack print 2 - Defend print choice = input (Enter your selection. ) choice = float(choice) print if choice == 1: mo_hp = mo_hp - my_dmg print The Lich King is at , mo_hp, Hit Points print You did , my_dmg, damage! print my_hp = my_hp - mo_dmg print I was attacked by the lk for , mo_dmg, damage! print My Hit Points are , my_hp print elif choice == 2: mo_hp = mo_hp - my_dmg / 2 print The Lich King is at, mo_hp, Hit Points print you did , my_dmg / 2, damage! print my_hp = my_hp - mo_dmg print I was attacked by the lk for , mo_dmg, damage! print My Hit Points are , my_hp print -Thank you -Inline Attachment Follows- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Help - How to end program
Jason MacFiggen jmacfig...@gmail.com wrote in message news:aanlktinevw8zje7fxktomks+tbrp=trmb7sb7pbkt...@mail.gmail.com... Python keeps looping when it gets past the int 0, how do I end the program when it the int 0 or 0. my_hp = 50 mo_hp = 50 my_dmg = random.randrange(1, 20) mo_dmg = random.randrange(1, 20) endProgram = end() while True: if mo_hp 0: print The Lich King has been slain! elif my_hp 0: print You have been slain by the Lich King! if mo_hp = 0: endProgram else my_hp = 0: endProgram else: print Menu Selections: print 1 - Attack print 2 - Defend print choice = input (Enter your selection. ) choice = float(choice) print if choice == 1: mo_hp = mo_hp - my_dmg print The Lich King is at , mo_hp, Hit Points print You did , my_dmg, damage! print my_hp = my_hp - mo_dmg print I was attacked by the lk for , mo_dmg, damage! print My Hit Points are , my_hp print elif choice == 2: mo_hp = mo_hp - my_dmg / 2 print The Lich King is at, mo_hp, Hit Points print you did , my_dmg / 2, damage! print my_hp = my_hp - mo_dmg print I was attacked by the lk for , mo_dmg, damage! print My Hit Points are , my_hp print The keyword 'break' will exit a while loop. Since you have no commands after the while loop, that will end your program. -Mark ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python help please
On Mon, 22 Mar 2010 22:31:58 + laura castañeda laura_cast...@hotmail.com wrote: Hi my name is Laura and im currently trying to solve one of the challenges in the book: Python Programming, second edition by Michael Dawson... I'm stuck in the 5 chapter because of this challenge, im the kinda person who dont give up so i have to solve this challenge or else i cant move on its just getting really frustrating and i was wondering if u can help me with it. Right now im trying to teach my self programming and i found the book really useful but this challenge is messing with me haha well is the second challenge at the end of the 5 chapter i hope its not to much problem for u and i'd really appreciated if u help me. The challenge: Write a character creator program for a role-playing game. the player should be given a pool of 30 point to spend on four attributes: Strength, wisdom, health and Dexterity. The player should be able to spend points from the pool on any attribute and should also be able to take points from an attribute and put them back into the pool. Thank you so much and please please help me.. this is what im thinking to do so far maybe we can work with it in the interface i want to print Welcome to C.C. so print character, be able to change the name, change the strength (something like Strength:___ would you like to add/sub [+/-]), change health, change wisdom, change dex, and points remaining.. and in the code i was thinking to start with a while loop .this is what i have so far and honestly im stuck i dont now how to start please help me thank you. Laura I would just have a dict with entries for each trait. And a func changePointDispatch(trait, number, sign) Sign is here a flag saying more/less. If more, check there is enough in pool, else send error message, remove it and add to the trait. If less,... The loop, as you say, just repetitively asks for a command and calls the func, until a code saying bastà! Maybe you have better ideas. Object-orientation would be nice but seems a bit overkill here (just an opinion). The design side of the problem is to get a practicle friendly interface to the user. Denis vit esse estrany ☣ spir.wikidot.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python help please
Hi my name is Laura and im currently trying to solve one of the challenges in the book: Python Programming, second edition by Michael Dawson... I'm stuck in the 5 chapter because of this challenge, im the kinda person who dont give up so i have to solve this challenge or else i cant move on its just getting really frustrating and i was wondering if u can help me with it. Right now im trying to teach my self programming and i found the book really useful but this challenge is messing with me haha well is the second challenge at the end of the 5 chapter i hope its not to much problem for u and i'd really appreciated if u help me. The challenge: Write a character creator program for a role-playing game. the player should be given a pool of 30 point to spend on four attributes: Strength, wisdom, health and Dexterity. The player should be able to spend points from the pool on any attribute and should also be able to take points from an attribute and put them back into the pool. Thank you so much and please please help me.. this is what im thinking to do so far maybe we can work with it in the interface i want to print Welcome to C.C. so print character, be able to change the name, change the strength (something like Strength:___ would you like to add/sub [+/-]), change health, change wisdom, change dex, and points remaining.. and in the code i was thinking to start with a while loop .this is what i have so far and honestly im stuck i dont now how to start please help me thank you. Laura _ Connect to the next generation of MSN Messenger http://imagine-msn.com/messenger/launch80/default.aspx?locale=en-ussource=wlmailtagline___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python help please
laura castañeda laura_cast...@hotmail.com wrote Hi my name is Laura and im currently trying to solve one of the challenges in the book: Python Programming, ... if u can help me with it. Right now im trying to teach my self programming and i found the book really useful Hi feel free to sitgn up to the tutor list, that way your posts will go through a lot quicker - and the answers will therefore come back quicker too :-) ...in the code i was thinking to start with a while loop Your ideas are all good. Get the data structures/variable set up, then iterate in a while loop adding and subtracting points from the pool to the character. Its a little like double entry book-keeping - for every addition there must be a corresponding subtraction and vice versa If you have a list of characters you will need a corresponding list of pools - or associate the pools with the characters - a dictionary maybe? Start with one character and try getting the most basic version running. If you get stuck show us the code plus any error messages and ask... -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] python help needed
i wana make ToC/headings for any PDF documents ,PDFminer solves the my problem if ToC are given.i came across many files where there is no Toc. Does any one know ,how to extract ToC/headings from such files. thanx _ Windows Live Hotmail: Your friends can get your Facebook updates, right from Hotmail®. http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_4:092009___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python help needed
On Mon, Oct 12, 2009 at 2:15 AM, mazher ahmad mazher_an...@hotmail.com wrote: i wana make ToC/headings for any PDF documents ,PDFminer solves the my problem if ToC are given.i came across many files where there is no Toc. Does any one know ,how to extract ToC/headings from such files. I guess you will have to construct the ToC from the headings. Does dumppdf (from PDFminer) show the information you want to collect? If so, it should give you a starting point for collecting the data. Kent ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python help
IT_ForMe snice14...@aol.com wrote cart = {apple:2.00, orange:2.50, banana:1.75} You set this up but then don't use it. Also your problem statement said *some* items were taxable, implying some were not. You might want to record whether an item is taxable in the dictionary too. print cart apple = 2 orange = 2.5 banana = 1.75 You don't need these lines since they are replicating your dictionary above totalprice = 0 You don't need this since you will set totalprice in the next line. totalprice = apple + orange + banana You should use the dictionary here, and you could apply the tax to the taxable items before generating the total. Also you might like to use a loop to get the total since the cart might change the number of items in a real world scenario. print your subtotal is 'totalprice' taxedprice = (totalprice *.07) + totalprice It might be easier to just multiple by 1.07 Also it would be good to store the tax as a variable in case the rate changes. print your final price is 'taxedprice' prompt = raw_input(are you a student?) if yes ('taxedprice' / 10) + taxed price = student you must assign a value to a variable you cannot assign a variable to an expression. Also, I thought the students got a discount? This provides a surcharge! print your student price is 'student' else print have a nice day You also have some faulty syntax in the last if/else section which Python will tell you about. HTH, -- 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] Python help
Anyone know how to program this using Python Add up the prices for items in a shopping cart. Some items are taxable and some items are not. You may assume a 7% tax rate for all taxable items. Apply a 10% discount if the customer is a student. (hint, instead of asking the user to input items, set them up as an associative array in the code) -- View this message in context: http://www.nabble.com/Python-help-tp23175541p23175541.html Sent from the Python - tutor mailing list archive at Nabble.com. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python help
Yes. Show us your solution and perhaps we can help you make it a tad more efficient. Robert Berman IT_ForMe wrote: Anyone know how to program this using Python Add up the prices for items in a shopping cart. Some items are taxable and some items are not. You may assume a 7% tax rate for all taxable items. Apply a 10% discount if the customer is a student. (hint, instead of asking the user to input items, set them up as an associative array in the code) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python help
On Wed, Apr 22, 2009 at 11:08 AM, IT_ForMe snice14...@aol.com wrote: Anyone know how to program this using Python Add up the prices for items in a shopping cart. Some items are taxable and some items are not. You may assume a 7% tax rate for all taxable items. Apply a 10% discount if the customer is a student. (hint, instead of asking the user to input items, set them up as an associative array in the code) My guess is most of us could do it, and this is homework. We have a policy against that sort of thing, but if you'd like to give it a try and then ask for help if you get stuck, we're more than willing to help. -Wayne ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python HELP
hey there, if anyone can help me with an assignment im stuck in for a fee i will be grateful *** Regards. A K. Hachem EMAILING FOR THE GREATER GOOD Join me ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python HELP
On Fri, Oct 24, 2008 at 1:18 PM, A .K Hachem [EMAIL PROTECTED] wrote: hey there, if anyone can help me with an assignment im stuck in for a fee i will be grateful We will help for free if you show us what you have done and ask specific questions. We won't do your homework for you. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [Python-Help] [EMAIL PROTECTED]
Artur Sousa wrote: What's the difference between: code for a in range(2, 10): for n in range(2, a): if a % n == 0: print a, 'equals', n, '*', a/n break else: print a, 'is a prime number' /code and code for a in range(2, 10): for n in range(2, a): if a % n ==0: print a, 'equals', n, '*', a/n break else: print a, 'is a prime number' /code Most of us monitor tutor and help - so initially pleas just post to one. Tutor is probably the best in this case. The obvious difference is the placement of the else statement. In the first else pairs with for and is invoked when no break happens. In the second else pairs with if and is invoked each time the divisor test fails. If that does not help you decide which is correct (it should) then run the 2 programs examine the results and that should reveal which gives you what you want. -- Bob Gailer 919-636-4239 Chapel Hill, NC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] python help
I have tried to find out the solution my self, and have failed to do so. So here is my problem: I want to submit text into an edit box on a web page. ie the equivalent of me typing text into the edit box and clicking the submit button. __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] python help
http://developer.yahoo.com/python/python-rest.html#post On 10/21/07, SwartMumba snake [EMAIL PROTECTED] wrote: I have tried to find out the solution my self, and have failed to do so. So here is my problem: I want to submit text into an edit box on a web page. ie the equivalent of me typing text into the edit box and clicking the submit button. __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -- Michael Langford Phone: 404-386-0495 Consulting: http://www.TierOneDesign.com/ -- Michael Langford Phone: 404-386-0495 Consulting: http://www.TierOneDesign.com/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python help
hi,i need help on a terrible homework assignment. do ul offer hw help?natasha Yahoo! Messenger with Voice. PC-to-Phone calls for ridiculously low rates.___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python help
On Tue, 28 Mar 2006, Natasha Menon wrote: i need help on a terrible homework assignment. do ul offer hw help? Not directly. Your homework is really your own to do. Please try to avoid the temptation of just posting a homework question here and hoping that someone will do the work for you. See: http://www.catb.org/~esr/faqs/smart-questions.html#homework But if you are asking for documentation or tutorial resources, or if you'd like to talk about general concepts or examples to help make things less confusing, we'll be happy to help in that way. Good luck to you. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python help
Why not post where you are stuck or what you are trying to understand? and we'll give you help and direction. What we cannot do is solve your homework for you. Hugo Natasha Menon wrote: hi, i need help on a terrible homework assignment. do ul offer hw help? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python help
Ben, Write a function that that uses X and Y techniques. I realise teachers have to test mastery of certain techniques, but they seem to lack the imagination. To be fair to teachers, its often the students who lack imagination. If you pose the problem as write an application to count the numbers of each letter in a paragraph of text or whatever many students will not make the connection to the technique that they are supposed to be using. Or they get so involved in the sub problem of creating/reading the paragraph of text that they don't spend time on the counting problem. A an example I have seen a solution to the above problem that used multiple loops to create a list of unique words. It then iterated over that list counting the occurences of each unique word. This solution required 2 loops overv the text for every unique word. Iyt worked but was horribly slow and the student made no use of the dictionaries that we had just spent a lecture learning about (this was in an awk class not Python...). Especially with modern languagues like Python, where you can write a whole program that actually does something usefull using only a few lines of code it OTOH I do agree that the tasks could be at least a bit more interesting. Even if the technique to be used was prescribed or mandated. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python help
has no human context whatsoever, so of course it's a useless homework problem. Why would someone want to take a useless histogram of a bunch of letters? Erm me! Communications analysts and cryptographers do that all the time! :-) The problem is fine, it's the context that would give it a purpose that is missing. If the problem were introduced with a little background rationale it might seem more relevant. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] python help
Hi,I have a few doubts in python programming. C if any of u can help me out. 1. In a file called string_stuff.py i have to write a function called frequencies that takes a string as a parameter and returns a dictionary where the keys are the characters from the string and each value is an integer indicating the number of times the key appeared in the string. 2. Similary in the same file string_stuff.py, have to write a function called locations that takes a string as a parameter and returns a dictionary where the keys are the characters from the string and each value is a list indicating the indices in the string at which the key appears, sorted in increasing order.3. In the same file string_stuff.py, write a function called concordance that takes an open file as a parameter and returns a dictionary where the keys are the strings from the file and each value is a list of line numbers of the lines in which the key appeared, sorted in increasing order. Start counting at 0. Each line number should appear at most once in a list, even if a word appears twice on a line. You may assume that the input consists only of alphabetic letters (a-z, A-Z) and whitespace. Id really appreciate if you could help me on these small question. I am tryin to learn to program in python.Thanks, Natasha Brings words and photos together (easily) with PhotoMail - it's free and works with Yahoo! Mail.___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python help
These sound like homework questions, in which case it would not be right for us to just give you the answer (and it would not be right for you to ask for it). If you can show us what you have tried so far, maybe we can give you some hints ... From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Natasha Menon Sent: 08 February 2006 17:19 To: tutor@python.org Subject: [Tutor] python help Hi, I have a few doubts in python programming. C if any of u can help me out. 1. In a file called string_stuff.py i have to write a function called frequencies that takes a string as a parameter and returns a dictionary where the keys are the characters from the string and each value is an integer indicating the number of times the key appeared in the string. 2. Similary in the same file string_stuff.py, have to write a function called locations that takes a string as a parameter and returns a dictionary where the keys are the characters from the string and each value is a list indicating the indices in the string at which the key appears, sorted in increasing order. 3. In the same file string_stuff.py, write a function called concordance that takes an open file as a parameter and returns a dictionary where the keys are the strings from the file and each value is a list of line numbers of the lines in which the key appeared, sorted in increasing order. Start counting at 0. Each line number should appear at most once in a list, even if a word appears twice on a line. You may assume that the input consists only of alphabetic letters (a-z, A-Z) and whitespace. Id really appreciate if you could help me on these small question. I am tryin to learn to program in python. Thanks, Natasha ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python help
These sound like homework questions, in which case it would not be right for us to just give you the answer (and it would not be right for you to ask for it). Agreed; these are not small questions at all. Natasha, if you're having trouble, please be more specific about what you're getting stuck on. Don't just give us homework questions to work on, because that gives us very little information on what in particular you're having problems with. As it is, it looks like each question assumes that you're familiar with loops, dictionaries, strings, and File I/O. That's a tall order; we can't just explain all of that, because we'd end up just regurgitating whatever book or tutorial you're already using, and that's no good to you! So try to show us more of what you've tried; that'll help us see where you need help, and we can be more targetted in what we try to explain. By the way, you may find the tutorials at: http://wiki.python.org/moin/BeginnersGuide/NonProgrammers helpful in learning Python. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python help
I have a few doubts in python programming. C if any of u can help me out. Have no doubts - Python can do all of this. In a file called string_stuff.py i have to write a function called frequencies that takes a string as a parameter and returns a dictionary where the keys are the characters from the string and each value is an integer indicating the number of times the key appeared in the string. What is your doubt here? Can you create a function called frequencies that has a string parameter and returns a dictionary? Can you read a string character by character into said dictionary? Can you increment the count for each character as you do so? Where is the problem that you need help with? Similary in the same file string_stuff.py, have to write a function called locations that takes a string as a parameter and returns a dictionary where the keys are the characters from the string and each value is a list indicating the indices in the string at which the key appears, sorted in increasing order. Similarly this is a pretty clear description of how to solve the problem What bit are you having trouble with? Show us your code and we might be able to help. In the same file string_stuff.py, write a function called concordance that takes an open file as a parameter and returns a dictionary where the keys are the strings from the file and each value is a list of line numbers of the lines in which the key appeared, sorted in increasing order. Start counting at 0. Each line number should appear at most once in a list, even if a word appears twice on a line. You may assume that the input consists only of alphabetic letters (a-z, A-Z) and whitespace. Slightly trickier but not much if you've already done the first two problems. Hint: Remember that you can store lists in dictionaries too. 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] python help
Why are these homework programming challenges so recognisable? It boils down to: Write a function that that uses X and Y techniques. The function may be hard and challenging to write but doesn't ever do anything interesting or anything that is useful and complete on its own. I realise teachers have to test mastery of certain techniques, but they seem to lack the imagination. Especially with modern languagues like Python, where you can write a whole program that actually does something usefull using only a few lines of code it should not be necessary to ask these kinds of dull questions. Just stick at it Natasha, it is far more interesting when you the programming challenge has to accomplish a real result. Ben --- Natasha Menon [EMAIL PROTECTED] wrote: Hi, I have a few doubts in python programming. C if any of u can help me out. 1. In a file called string_stuff.py i have to write a function called frequencies that takes a string as a parameter and returns a dictionary where the keys are the characters from the string and each value is an integer indicating the number of times the key appeared in the string. 2. Similary in the same file string_stuff.py, have to write a function called locations that takes a string as a parameter and returns a dictionary where the keys are the characters from the string and each value is a list indicating the indices in the string at which the key appears, sorted in increasing order. 3. In the same file string_stuff.py, write a function called concordance that takes an open file as a parameter and returns a dictionary where the keys are the strings from the file and each value is a list of line numbers of the lines in which the key appeared, sorted in increasing order. Start counting at 0. Each line number should appear at most once in a list, even if a word appears twice on a line. You may assume that the input consists only of alphabetic letters (a-z, A-Z) and whitespace. Id really appreciate if you could help me on these small question. I am tryin to learn to program in python. Thanks, Natasha - Brings words and photos together (easily) with PhotoMail - it's free and works with Yahoo! Mail. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ 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] python help
I realise teachers have to test mastery of certain techniques, but they seem to lack the imagination. I agree; the problem here, I think, is that these homework questions often focus WAY too much on Python-specific features, rather than on fundamental issues, and so the questions end up feeling very artificial. So the first question that says: In a file called string_stuff.py i have to write a function called frequencies that takes a string as a parameter and returns a dictionary where the keys are the characters from the string and each value is an integer indicating the number of times the key appeared in the string. has no human context whatsoever, so of course it's a useless homework problem. Why would someone want to take a useless histogram of a bunch of letters? What would be more interesting is putting it in context, say like: We're writing a book report, but we notice that we use certain words a lot more than other words. It would be useful to get an idea of what words are being overused so we can get out our thesaurus out on those particular words. We need to know which words we're using, and how frequently we're using them... The context has to be there for the problem to make sense: otherwise what often ends up happening is disattachment and disillusionment. And the result should be relevant and feel like a real thing to them, even if it is a simplification. And it doesn't have to be immediately useful for the student, just as long as that student sees that it might be useful to someone. And in this case, if we don't mention dictionaries initially, that's fine, because we can solve the problem with or without dictionaries. If we did want to force the use of dictionaries: 1. We can motivate it later by mentioning that we want to use the program on a term paper, and it's taking forever. 2. Or we can talk about how our friends have some other program that can plot histograms, but it expects to see a dictionary mapping items and their occurrence. Either way, there needs to be a reason, a why to these things. Unfortunately, it takes effort on a teacher's end to do this, but that's what they should be paid for! *grin* ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [Python-Help] Variable question
[Note: try to avoid crossposting. The Mailing List Ettiquette FAQ: http://www.gweep.ca/~edmonds/usenet/ml-etiquette.html explains why crossposting isn't such a good idea usually. I'm taking [EMAIL PROTECTED] out of CC now.] I am trying to pass a variable into this ESRI function and it won't let me is there a way to do this?? Thanks for your help! Can you show us what you've tried so far? Also, can you show us how Python responds? Do you get an error message of any sort? These are things we'll want to know, because otherwise, we can't say anything concrete and know that we're actually addressing your question. *grin* You mentioned ESRI, so I'm assuming you're using ArcGIS. http://hobu.biz/software/python_guide_esri/ If you think that your question seems less about Python and more about the integration with ArcGIS, then you may want to try the ESRI forums here: http://forums.esri.com/forums.asp?c=93s=1729#1729 where they appear to have a fairly active community of ArcGIS/Python users. Good luck to you! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor