Re: [Tutor] While learning Py: To IDE or not to IDE?
In my humble opinion, I think what is important is to get familiar with python for now. The free version of Komodo is what I have been using and its been cool. When you're comfortable with the language and you want to start writing some apps and all of that, you would be matured and independent enough to make a choice as to which editor to go with. Trust me, when you bury your head into writing amazing codes, the choice of editor would come almost naturally. All the best. Sent from my BlackBerry wireless device from MTN -Original Message- From: Brian van den Broek Sender: tutor-bounces+delegbede=dudupay@python.org Date: Mon, 21 May 2012 18:17:01 To: boB Stepp Cc: Subject: Re: [Tutor] While learning Py: To IDE or not to IDE? ___ 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] extracting lines between patterns.
Give an example. Let's see what you've tried and then it becomes clear what help is needed. Regards. Sent from my BlackBerry wireless device from MTN -Original Message- From: Bala subramanian Sender: tutor-bounces+delegbede=dudupay@python.org Date: Mon, 14 May 2012 09:31:41 To: Subject: [Tutor] extracting lines between patterns. ___ 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 arthematics
What have you tried? What so u intend to achieve? There are math functions in python already; so, are you planning to use the functions in the math class for your program or you want to write yours separately? The later would be a little disturbing in my candid opinion. Regards. Sent from my BlackBerry wireless device from MTN -Original Message- From: Sukhpreet Sdhu Sender: tutor-bounces+delegbede=dudupay@python.org Date: Fri, 23 Mar 2012 06:14:41 To: tutor@python.org Reply-To: Sukhpreet Sdhu Subject: [Tutor] python arthematics ___ 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] finding a polymer of letters in a string
Hi, The explanation you have given isn't good enough to get us anywhere. What are the possible patterns? Do you have a fixed number of As you're looking out for? What defines a polymer region? The different DNA samples, how are they separated? With commas, new lines etc? You can do a line by line explanation and we could get some people in here to help you get python codes to achieve what you just explained. Regards. Sent from my BlackBerry wireless device from MTN -Original Message- From: Hs Hs Sender: tutor-bounces+delegbede=dudupay@python.org Date: Thu, 19 Jan 2012 10:09:27 To: tutor@python.org Reply-To: Hs Hs Subject: [Tutor] finding a polymer of letters in a string ___ 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] Making a function run every second.
In my opinion, you probably have to think of how many times it has to run. If you want to run forever, you can just make an infinite loop. Here's my try. import time def myloop(): while True: print 'Hi' time.sleep(1) This would run forever and print Hi after every 1 second when you run the program. What exactly are you trying to achieve. Sent from my BlackBerry wireless device from MTN -Original Message- From: "Mic" Sender: tutor-bounces+delegbede=dudupay@python.org Date: Tue, 29 Nov 2011 15:54:59 To: Subject: [Tutor] Making a function run every second. Hi I want a function to run every second , how do I do that? Say that the function look like this: def hi(): print("hi") Thanks! Mic ___ 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] Variables (with lists??)
Hi Chris, Straight to the point, this is how to populate a python dictionary. customer = {} This statement makes a new dictionary, which is empty though, called customer. A python dictionary has a pair of key and value linked with semicolon and seperated from other pairs by a comma. print “Add a new customer to the database\n” custNum = raw_input(‘Enter a customer number: ‘) This expects an input from the user and then sets that to the variable custName. Here is a thing to note here, whatever the user enters is treated as a string because of raw_input. That's another lesson as a whole. What's in the parenthesis would be shown at the prompt when the program is run. It tells the user what to do. customer['firstName'] = raw_input(‘Customer First Name: ‘) This creates a pair of key value in a dictionary. Initially, the dictionary customer was empty. This statement now creates a key 'firstname' that has the value of whatever is entered by the user as the Customer First Name. customer['lastName'] = raw_input(‘Customer Last Name: ‘) The same explanation for the above explains this and the rest all through the customer['zip'] = raw_input(‘Customer Zip Code: ‘) You can also look at what others would say. While searching google, search, creating python dictionary. HTH. Regards. Sent from my BlackBerry wireless device from MTN -Original Message- From: Chris Kavanagh Sender: tutor-bounces+delegbede=dudupay@python.org Date: Tue, 22 Nov 2011 23:15:49 To: Subject: [Tutor] Variables (with lists??) I was going over one of Derek Banas' tutorials on youtube, and came across something I hadn't seen before. A variable with a list beside it (see code below). He sets the variable, customer , equal to a dict. Then uses the variable with ['firstname'],['lastname'], ect. I've never seen this in my short programming life. What is this called? And is there any documentation on it?? I tried to google it, but had no idea what to google, lol. The code below is just partial code. . . Thanks for the help, and I hope everyone has a happy Thanksgiving! customer = {} print “Add a new customer to the database\n” custNum = raw_input(‘Enter a customer number: ‘) customer['firstName'] = raw_input(‘Customer First Name: ‘) customer['lastName'] = raw_input(‘Customer Last Name: ‘) customer['streetAdd'] = raw_input(‘Customer Street Address: ‘) customer['city'] = raw_input(‘Customer City: ‘) customer['state'] = raw_input(‘Customer State: ‘) customer['zip'] = raw_input(‘Customer Zip Code: ‘) ___ 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] Guess my number game
Hi Myles, Pseudocodes are what anyone would write but they only lay an idea of what you intend to achieve. To get quick help, you need to write the actual code and tell us where the trouble spot is. This way we can help you get along. Cheers. Sent from my BlackBerry wireless device from MTN -Original Message- From: myles broomes Sender: tutor-bounces+delegbede=dudupay@python.org Date: Sat, 19 Nov 2011 12:53:40 To: Subject: [Tutor] Guess my number game I am currently learning Python from the 'Python Programming for the Absolute Beginner' book. At the end of each chapter, you are given challenges and one of the challenges is to make a 'Guess My Number' game where the player thinks of a number between 1 and 100 and the computer has to guess the number. I'm having real trouble designing the 'guessing loop' where the computer guesses the players number. Here is the pseudocode I have written up: Welcome the user to the game Explain the rules of the game Wait for the user to think of a number Once the user has thought of their number, take a guess While the number has not been guessed correctly Increase the number of 'tries' by 1 Ask the user if the guess was too high or too low If the guess was too high guess lower If the guess was too low guess higher Once the number has been guessed correctly, tell the user the number of tries it took Exit the game Any help would be very much appreciated. ___ 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] please help - stuck for hours
Where do you intend the variable cash_in to come from? The system doesn't know what cash_in is beyond that you mentioned it and that makes it impossible to multiply it with dollar which is a float type. If cash_in is supposed to be an input from the user, you probably should make it an int type right away before doing the multiplication. Hope this helps. Cheers. Sent from my BlackBerry wireless device from MTN -Original Message- From: ADRIAN KELLY Sender: tutor-bounces+delegbede=dudupay@python.org Date: Thu, 17 Nov 2011 21:19:45 To: Subject: [Tutor] please help - stuck for hours ___ 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] local variable referenced before assignment
Post the error stack. Sent from my BlackBerry wireless device from MTN -Original Message- From: ADRIAN KELLY Sender: tutor-bounces+delegbede=dudupay@python.org Date: Thu, 17 Nov 2011 18:47:07 To: Subject: [Tutor] local variable referenced before assignment ___ 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] Hello again. Still the same problem, different question.
Can you kindly mail the author? That might be a better way to have this resolved. Its interesting you are sticking with python v3. Cheers. Sent from my BlackBerry wireless device from MTN -Original Message- From: Nathaniel Trujillo Sender: tutor-bounces+delegbede=dudupay@python.org Date: Fri, 11 Nov 2011 21:16:30 To: Subject: [Tutor] Hello again. Still the same problem, different question. ___ 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] Okay, this time I tried doing a little research but no luck in solving this one.
If you didn't get any error and you were returned to the prompt as you mentioned, it means pygame has been successfully imported. Try running a pygame command to confirm. If you type pygame at the prompt, it should tell you the location of pygame on your system. Regards. Sent from my BlackBerry wireless device from MTN -Original Message- From: Nathaniel Trujillo Sender: tutor-bounces+delegbede=dudupay@python.org Date: Thu, 10 Nov 2011 19:41:54 To: Subject: [Tutor] Okay, this time I tried doing a little research but no luck in solving this one. ___ 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] how to remove the coming duplication
You have the error because the square brackets are missing. You should have done this: b=[b.append(a[i]) for i in range(len(a)) if a[i] != b[-1]] This would however give you an index out of range error. That said, may I ask what it is exactly you are trying to achieve? Cheers. Sent from my BlackBerry wireless device from MTN -Original Message- From: lina Sender: tutor-bounces+delegbede=dudupay@python.org Date: Thu, 10 Nov 2011 15:20:49 To: tutor Subject: Re: [Tutor] how to remove the coming duplication b = [] b=b.append(a[i]) for i in range(len(a)) if a[i] != b[-1] showed me: SyntaxError: invalid syntax ___ 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] how to remove the coming duplication
Try this >>> a=['2', '5', '7', '5', '5'] >>> d=list(set(a)) >>> d ['2','5','7'] Is there any reason why your numbers are in quotes??? Hope this helps. Sent from my BlackBerry wireless device from MTN -Original Message- From: lina Sender: tutor-bounces+delegbede=dudupay@python.org Date: Thu, 10 Nov 2011 15:10:57 To: tutor Subject: [Tutor] how to remove the coming duplication Hi, How to remove the coming duplication, Here I wrote one (not working): >>> a=['2', '5', '7', '5', '5'] >>> for i in range(len(a)-1): if a[i+1]==a[i]: a.remove(a[i+1]) if i not in range(len(a)): break >>> a ['2', '7', '5', '5'] I wish to get a is [2,5,7,5] just remove the coming duplication, not unique the list. Thanks for any advice, Best regards, ___ 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] problem with using set
+1 Ramit. Sent from my BlackBerry wireless device from MTN -Original Message- From: "Prasad, Ramit" Sender: tutor-bounces+delegbede=dudupay@python.org Date: Thu, 13 Oct 2011 11:09:24 To: tutor@python.org Subject: Re: [Tutor] problem with using set Approach:- >>> a='hello' >>> set(a) set(['h', 'e', 'l', 'o']), so i am thinking somehow if i remove 'l' and i join the string, i will get the desired output. 2. >>> a='microsoft' >>> set(a) set(['c', 'f', 'i', 'm', 'o', 's', 'r', 't']) >>> print ''.join(set(a)) cfimosrt When i print "Hello", i get the output as "helo"(in same sequence) but when i write "microsoft" i get this-"cfimosrt". So, it means i can't predict the outcome of set(a)?? = Are you required to use set? If you are not, I think the following will be easier. >>> 'hello'.replace( 'l', '' ) 'heo' >>> 'microsoft'.replace( 'o', '' ) 'micrsft' If you require set, you can do: >>> s = set("microsoft") >>> s set(['c', 'f', 'i', 'm', 'o', 's', 'r', 't']) >>> s.remove('o') >>> string = [] >>> for letter in 'microsoft': ... if letter in s: ... string.append( letter ) ... >>> ''.join( string ) 'micrsft' Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. ___ 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] problem with using set
What exactly do you intend to get as an output? Sent from my BlackBerry wireless device from MTN -Original Message- From: Praveen Singh Sender: tutor-bounces+delegbede=dudupay@python.org Date: Thu, 13 Oct 2011 10:44:53 To: Subject: [Tutor] problem with using set ___ 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 coding help
Try a byte of a python or alan gauld site on learning python. Welcome to python. Sent from my BlackBerry wireless device from MTN -Original Message- From: Aisha Ali Sender: tutor-bounces+delegbede=dudupay@python.org Date: Sat, 8 Oct 2011 17:40:38 To: tutor@python.org Reply-To: Aisha Ali Subject: [Tutor] Python coding help ___ 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
[Tutor] START-UP PROJECT
Hi all, I have been coding python for a while but I just can't get to rate myself. I have been part of few projects that are python based and did a pretty good job with other team mates. I however want to step up my game and make python my core competence; the challenge I have is what project to embark on. I really can't figure out what project to take on but would be prepared to take on anything and get my hand dirtier than before. Kindly put forth suggestions. I wouldn't mind being pushed to the extreme. I just want something to work on. Thanks as I look forward to your thoughts. Cheers. Sent from my BlackBerry wireless device from MTN ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] quick data structures question
As a follow up Fred, you have to install the xlrd package to use it. It helps you interact with an excel file even if you don't have excel installed on your pc. Sent from my BlackBerry wireless device from MTN -Original Message- From: Fred G Sender: tutor-bounces+delegbede=dudupay@python.org Date: Tue, 20 Sep 2011 23:28:43 To: Subject: [Tutor] quick data structures question ___ 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] quick data structures question
Hi Fred, Here is my attempt to solve your task. import xlrd def extract(file_name): choice_file = xlrd.open_workbook(file_name) choice_sheet = choice_file.sheet_by_index(0) gene_dict = {} for row_num in range(1,choice_sheet.nrows): row_vals = choice_sheet.row_values(row_num) if int(row_vals[0] * 100) > 20: gene_dict[row_vals[1]] = row_vals[0] * 100 return gene_dict Here are few assumptions I made. 1. The your excel file has just two column with headers. Column 1 is High gain written in % format and column 2 is the gene. 2. that excel returns % format as decimals which is float in python; hence my conversion to int. Try this out and let me know how it goes. Watch the indents carefully. I typed from my blackberry. HTH. Sent from my BlackBerry wireless device from MTN -Original Message- From: Fred G Sender: tutor-bounces+delegbede=dudupay@python.org Date: Tue, 20 Sep 2011 23:28:43 To: Subject: [Tutor] quick data structures question ___ 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] Coin Flipping Program
Hi Joel, Someone has asked this question before and I think it was dealt with. That said, in my opinion, starting out with python 3 reduces the number of assist you can get on the fly. I for one have dealt with this issue before but can't help with the python 3 areas. Have you checked Alan Gauld's website? He dealt with python 3. Sorry Mate. Sent from my BlackBerry wireless device from MTN -Original Message- From: Joel Preston Sender: tutor-bounces+delegbede=dudupay@python.org Date: Sun, 21 Aug 2011 12:14:37 To: Subject: [Tutor] Coin Flipping Program ___ 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] Beginner troubleshooting py2exe
Just curious. Going by the last line of the error generated, it says something you tried to import is not a valid windows application. Can you confirm you installed the right py2exe for python 2.7 on Win32? You may want to check that to be sure. The last line of your error stack should point you in the direction to go. Regards. Sent from my BlackBerry wireless device from MTN -Original Message- From: Esther Showalter Sender: tutor-bounces+delegbede=dudupay@python.org Date: Mon, 27 Jun 2011 18:27:10 To: Subject: [Tutor] Beginner troubleshooting py2exe ___ 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] nitinchandra rubbish on list
The problem with boxbe is a nightmare for everybody. It is a mail application by a company that gets into the ways of people ones the receiver of your mail has boxbe running on his system. Sadly my yahoomail has boxbe but that's not my mail on this list. The most annoying part is that you can't even unsubscribe. While I understand how annoying that is, may I appeal you don't withdraw your contributions to this list as a result of that. Thank you. Sent from my BlackBerry wireless device from MTN -Original Message- From: Válas Péter Sender: tutor-bounces+delegbede=dudupay@python.org Date: Sun, 19 Jun 2011 18:55:46 To: Python Tutors Subject: Re: [Tutor] nitinchandra rubbish on list ___ 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] Creating a dictionary
Nice observation Spawgi. Sent from my BlackBerry wireless device from MTN -Original Message- From: spa...@gmail.com Sender: tutor-bounces+delegbede=dudupay@python.org Date: Fri, 27 May 2011 20:01:24 To: Válas Péter Cc: Subject: Re: [Tutor] Creating a dictionary ___ 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] Creating a dictionary
The first instance is more keystrokes while the second saves u that. Sent from my BlackBerry wireless device from MTN -Original Message- From: Válas Péter Sender: tutor-bounces+delegbede=dudupay@python.org Date: Fri, 27 May 2011 16:19:08 To: Cc: Subject: Re: [Tutor] Creating a dictionary ___ 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] PI
Do import math first I.e type import math You could also do from math import pi Provided pi is the only function u need in the math module. from math import * This imports every function of the math module. HTH Sent from my BlackBerry wireless device from MTN -Original Message- From: David Merrick Sender: tutor-bounces+delegbede=dudupay@python.org Date: Thu, 26 May 2011 16:21:01 To: Subject: [Tutor] PI ___ 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] textbook question
Nice job, Michael. The way it is, you have done the best anyone here would do to answer that question. Justin, in addition to what Michael said, note too that functions don't have to span hundreds of lines. def Useless(): pass That's a function correctly defined but does nothing. Having this in mind and what Michael has sent earlier, give it a shot. All the best. Sent from my BlackBerry wireless device from MTN -Original Message- From: michael scott Sender: tutor-bounces+delegbede=dudupay@python.org Date: Sun, 27 Feb 2011 22:34:38 To: Subject: Re: [Tutor] textbook question ___ 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] Having Troubles with For Loops
To start with, you don't need to do so much for loop. You have already set the chosen word, word to correct. Every randomly selected word becomes the value of correct so, you need to only check for word in correct. So, after initiating the random selector, you print the number of letters in the word using the syntax like this: The player has 5 tries, depending on the approach you intend to adopt, you may not have to use max_tries. Say you go for the while loop. Set tries to 1 correct=word[random.randrange(len(word)-1)] word = a list of words you want the player to choose from print 'The word has %d letters' % len(correct) while tries <= 5: guess=raw_input('Guess a letter: ') if guess in correct: print 'yes' else: print 'no' tries += 1 What you would achieve with the above is that, immediately the player does 5 guesses, the game exits. How do you expect a player to guess a 7 letter word with just 5 tries. Second, the player should after 5 tries, if you insist on that, have a chance to guess the word itself assuming he has he has made two or three guesses, atleast give him a chance to make a wild guess. You can then tell him if he is right or wrong and go ahead to tell him the word. This is just a game logic from my own perspective. Do the necessary tweak to the cold. If there are other problems, please let's know. I hope this helps. Regards. Sent from my BlackBerry wireless device from MTN -Original Message- From: Corey Richardson Sender: tutor-bounces+delegbede=dudupay@python.org Date: Sat, 19 Feb 2011 13:22:25 To: Subject: Re: [Tutor] Having Troubles with For Loops On 02/19/2011 01:06 PM, jyatesster wrote: > I am refreshing my memory of Python programming after taking a class this > past fall. I am using the book, *Python Programming for the absolute > beginner*. I am at chapter 4, challenge 4 which instructs me to create a > program that picks a random word and the player has to guess the word. The > computer tells the player how mnay letters are in the word. Then the player > gets five chances to ask if a letter is in the word. The computer can only > respond with "yes" or "no." Then, the player must guess the word. > > Here is what I have so far. I think I am doing something wrong with the for > loops as the program is not reading whether the letter is in the constant > and giving the appropriate response. > [snip] You're going about it wrong. You should look into the len() function. For example: print("This word has %d letters" % (len(word)) ) for i in range(5): letter = input("Guess a letter: ") if letter.lower() in word.lower(): print("Yes") else: print("No") Your for loops in the end don't do what you think they do. for letter in XYLOPHONES: # Loops through XYLOPHONES if letter.lower() not in XYLOPHONES: # Always will return false, print("No")# because you are looping through the word itself # etc. You are also mixing Python 3's print() with Python 2's raw_input(), so it's hard to tell which you are using. I'm assuming Python 2 because you didn't report the raw_input() failing. If that's the case, you don't need the ()'s around the text you are printing. I also suggest you look into lists and list indexing. You should go through the Python Tutorial [0] if you haven't before. [0] - http://docs.python.org/tutorial/ -- Corey Richardson I've never known any trouble which an hour's reading didn't assuage. -Charles De Secondat ___ 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 and Tuples
Thanks Karim. That's a way to go. Cheers. Sent from my BlackBerry wireless device from MTN -Original Message- From: Karim Sender: tutor-bounces+delegbede=dudupay@python.org Date: Sun, 30 Jan 2011 10:50:31 To: Becky Mcquilling; python mail list Subject: Re: [Tutor] Python and Tuples ___ 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 and Tuples
Nice Steve, No one does it better. Weldone. Sent from my BlackBerry wireless device from MTN -Original Message- From: Steven D'Aprano Sender: tutor-bounces+delegbede=dudupay@python.org Date: Sun, 30 Jan 2011 20:47:08 To: Subject: Re: [Tutor] Python and Tuples Becky Mcquilling wrote: > I'm fairly new to python and I am trying to do some math with tuples. > > If I have a tuple: > > t =( (1000, 2000), (2, 4), (25, 2)) > I want to loop through and print out the results of the multiplying the two Start with a basic loop through the objects in the tuple: >>> t = ( (1000, 2000), (2, 4), (25, 2) ) >>> for pair in t: ... print(pair) ... (1000, 2000) (2, 4) (25, 2) This walks through the outer tuple, grabbing each inner tuple (a pair of numbers) in turn. So we *could* (but won't -- keep reading!) write this: for pair in t: x = pair[0] # grab the first number in the pair y = pair[1] # and the second number print(x*y) and that would work, but we can do better than that. Python has "tuple unpacking" that works like this: >>> pair = (23, 42) >>> x, y = pair >>> print(x) 23 >>> print(y) 42 We can combine tuple unpacking with the for-loop to get this: >>> for x,y in t: ... print(x*y) ... 200 8 50 -- Steven ___ 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
[Tutor] Print Help
I want to loop over a list and then print out a one statement that carries all the items in the list e.g def checking(responses): ''' Converts strings that look like A2C3D89AA90 into {'A':'2', 'C':'3', 'D':'89', 'AA':'90'}''' responses=dict(re.findall(r'([A-Z]{1,2})([0-9]+)', responses.upper())) if responses else {} for key in responses.keys(): count = [] if key in ['A'] and int(responses[key]) not in range(1,3): count += key elif key in ['B', 'G', 'T', 'U', 'V', 'W', 'X'] and int(responses[key]) not in range(1, 3): count += key elif key in ['H', 'J', 'K', 'M', 'N', 'P', 'Q','R','S'] and int(responses[key]) not in range(1, 6): count += key elif key in ['D', 'E'] and int(responses[key]) == 4: print 'accepted' for err in count: count = ", ".join(count) print "Invalid Message: You specified out of range values for %s" % (", ".join(count)) What I am expecting is: Invalid Message: You specified out of range values for a,s,d,r,t,u Assuming those were the values that are incorrect. Ple help. Sent from my BlackBerry wireless device from MTN ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] REGEX EXPLANATION
I have been reading regex in order to work around an assignment. Could anyone explain to me in plain english what the following regex expression translate to. (r'PSC(?P\d{6})(DC|VR)(\d{2})(RC|GA)(\d{3})(!?([A-Z\d]{1,})@?(.*))?', re.I) (r'PSC(?P\d{6})VR(?P\d{2})RC(?P\d{3})(?P[ABCDEFGHJKMNPQRSTUVWXYZ\d]{2,})?', re.I) (r'PSC(?P\d{6})VR(?P\d{2})(?P(RC|GA))(?P\d{3})!(?P[ABCDEFGHJKMNPQ]{1,})@?(?P.*)', re.I) (r'PSC(?P\d{6})DC(?P\d{2})RC(?P\d{3})(?P[ABCDEFGHJKMNPQRSTUVWX\d]{2,})?', re.I) (r'PSC(?P\d{6})DC(?P\d{2})(?P(RC|GA))(?P\d{3})!(?P[ABCDEFGHJK]{1,})@?(?P.*)', re.I) Like reading it out in plain english. This should further help me understand how these signs work and then I can get along. Thanks. Sent from my BlackBerry wireless device from MTN ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 81, Issue 90
I am beginning to feel the name Wangolo Joel is not human. It probably could be the name of a virus. It has been said over and over how to unsubscribe to an extent that someone actually sent a link and yet, we are still getting this mail. Can anyone write a simple program to deactivate this virus. Regards. Sent from my BlackBerry wireless device from MTN -Original Message- From: Wangolo Joel Sender: tutor-bounces+delegbede=dudupay@python.org Date: Sat, 27 Nov 2010 08:55:10 To: Subject: Re: [Tutor] Tutor Digest, Vol 81, Issue 90 ___ 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] JOB AD PROJECT
Hi People, I am afraid only Alan has said something to me. Is it that solution would never come or u guys are waiting to gimme the best? Please help. Sent from my BlackBerry wireless device from MTN -Original Message- From: "Alan Gauld" Sender: tutor-bounces+delegbede=dudupay@python.org Date: Sat, 20 Nov 2010 09:00:52 To: Subject: Re: [Tutor] JOB AD PROJECT wrote > I have done some extensive reading on python. > i want to design a classifieds site for jobs. Have you done any extensive programming yet? Reading alone will be of limited benefit and jumping into a faurly complex web project before you have the basics mastered will be a painful experience. I'm assuming you have at least some experience of web programming in other languages for you to take such a bold step? > I am taking this as my first project and would appreciate any help. > I am looking in the direction of python, maybe django. The choice of tools is fine, but its a big task for a first ever Python project! 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 maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] JOB AD PROJECT
Hi, I have done some extensive reading on python. i want to design a classifieds site for jobs. The service is meant to send people who register an sms with available jobs that fit their criteria/cv. But the main idea is that people come and register for quick jobs(like www.freelancer.com) and put up their criteria,age,location,qualificationsand when a company or employer posts a job,the people that fall into the category that was specified get sms and email alerts as to the availability of the job. I am taking this as my first project and would appreciate any help. I am looking in the direction of python, maybe django. Kindly help. Thanks. Sent from my BlackBerry wireless device from MTN ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 81, Issue 35
Hi Joel, To start with, I sincerely appreciate your concern and I am deeply sorry your computer is so infected. Having said that, I think it is unfair to pile all the blames and as a matter of fact, any at all, on this group. That is very unfair to say the least. I don't have an idea of how long you have been on this mailing list but I am quite sure you are not the first to subscribe and you can't be the last. It therefore bothers me that you are the onlt person I have heard say such a terrible thing about this group despite all measures in place to avoid sending malicious elements. I hope you are aware this group doesn't allow attachments except you are suggesting the viruses you are talking about are the letters and numerals in the mails. That then underscores your knowledge as an IT person. Second, you had an option to stick with your PDF and google stuff before coming on this mailing list. If you are all of a sudden attached to your PDF again, it ia matured enough to unsubscribe and be thankful for the things you have learnt in here. While I hope you would have a change of mind and apologise for your very harsh and false accusations, I hope you would also understand that everybody here despite our different backgrounds have gone thus far because we play by the rules and we are interested in not only learning python but teaching too and making everyone smile. Have a great day. Regards Sent from my BlackBerry wireless device from MTN -Original Message- From: Wangolo Joel Sender: tutor-bounces+delegbede=dudupay@python.org Date: Fri, 12 Nov 2010 14:45:21 To: Subject: Re: [Tutor] Tutor Digest, Vol 81, Issue 35 ___ 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] if statement
It is not always enough to send just the error. What construct do you have after the if line? Make your sample detailed to get useful responses. Regards. Sent from my BlackBerry wireless device from MTN -Original Message- From: Glen Clark Sender: tutor-bounces+delegbede=dudupay@python.org Date: Tue, 02 Nov 2010 19:02:15 To: python mail list Subject: [Tutor] if statement File "/home/glen/workspace/test.py", line 19 if confirmed == "y": ^ SyntaxError: invalid syntax Why does this not work??? PyDev says "Expected:else" ___ 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] Zip Command
I have the Winzip so I can actually view zip folders. What I want is for my backups to be wrapped in such folder. Thanks Walter Sent from my BlackBerry wireless device from MTN -Original Message- From: Walter Prins Date: Thu, 14 Oct 2010 09:29:30 To: Cc: tutor Subject: Re: [Tutor] Zip Command On 14 October 2010 07:12, wrote: > Does window os have a zip command for python like linux and unix. > If yes, please what is it. > If no, please what does it use to create a zip folder. > I am working on an example in byte of python but the zip command is from > linux but I use windows. > Thank you. > Windows does not have a command line wrapper for it's zipped folders functionality (which as you probably know should more properly be called zip files as that's what they are, notwithstanding the fact that Windows Explorer makes them look like folders in the UI.) Several third party command line versions exist however, including proprietary ones like Winzip and open source ones. (Google yielded for example this: http://www.pcreview.co.uk/forums/thread-103518.php ) However, you should perhaps have a look at Python's "zipfile" module which should be able to create zip files as well. See e.g. http://docs.python.org/release/2.5.2/lib/module-zipfile.html Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Zip Command
Thanks to start with. A byte f python is a book by Swaroop C.H. It is also a book for beginners. Back to the module for zip, do I have to import it into my code for use? It actually works on two lists as you rightly said. I am supposed to create a back up files from 2 directories into another seperate directory on my PC and I want the backup wrapped in a zip folder. Thanks. Sent from my BlackBerry wireless device from MTN -Original Message- From: "Alan Gauld" Sender: tutor-bounces+delegbede=dudupay@python.org Date: Thu, 14 Oct 2010 08:14:40 To: Subject: Re: [Tutor] Zip Command wrote > Does window os have a zip command for python like linux and unix. > If yes, please what is it. Yes, zip > If no, please what does it use to create a zip folder. But the zip command does nmot create a "zip folder" - in fact I'm not even sure what you mean by a zip folder. I know about zip files but not zip folders... To create zip files you need to use the zipfile module. > I am working on an example in byte of python but the > zip command is from linux but I use windows. The zip commansd is a standard command and is used for joining two lists. The zipfile module is a standard module that should work across platforms. But I have no idea which you are referring to from Byte of Python, sorry. 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 maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Zip Command
Hi all, Does window os have a zip command for python like linux and unix. If yes, please what is it. If no, please what does it use to create a zip folder. I am working on an example in byte of python but the zip command is from linux but I use windows. Thank you. Sent from my BlackBerry wireless device from MTN ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] cgi help
Got it fixed. Thanks y'all. Regards, --Original Message-- From: Dave Angel To: Dipo Elegbede Cc: tutor Subject: Re: [Tutor] cgi help Sent: Oct 6, 2010 12:30 On 2:59 PM, Dipo Elegbede wrote: > here is the code: > > http://pastebin.com/K2Fxq6ac > > kindly help me figure out my mistake. > > It is supposed to return a table of environmental variables but it returns > only the header and a blank page. > > thanks > Care to define "return" ? How are you running this code? How are you trapping and displaying the exception it gets when run? Can you show us the traceback? Are you looking at the output in a web browser? Which one? And are you doing a view-Source, or whatever your browser offers? A CGI program is intended to run on a web server, and debugging it can be very difficult. Are you sure you want this as a beginner project? If so, then I'd start by saying you should run it locally, till you get rid of all the errors you'll see that way. By inspection, I can see that you should get more than the header, you should also get the element, then it'll crash on the bogus assignment of the uninitialized variable rowNumber. When I run it locally, I get: Content-type: text/html http://www.w3.org/1999/xhtml";> Environmental Variables Traceback (most recent call last): File "M:\cgitest.py", line 27, in rowNumber += 1 NameError: name 'rowNumber' is not defined You don't initialize the global variable rowNumber to anything, but just increment it. You do initialize a local variable in your function with the same name, but nothing is ever done with that, and of course it goes away when the function ends. Same with the backgroundColor local. To fix this problem you'll need to initialize rowNumber before the for statement. DaveA Sent from my BlackBerry wireless device from MTN ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] CGI HELP
Yes, so I did a pastebin and resent to the group. Thanks. Sent from my BlackBerry wireless device from MTN -Original Message- From: Joel Goldstick Sender: tutor-bounces+delegbede=dudupay@python.org Date: Wed, 6 Oct 2010 05:54:03 To: tutor Subject: Re: [Tutor] CGI HELP ___ 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] Coin Toss Problems
This is also a learner's advice, so just give it a shot. In the first function, set HEADS to 0 and TAILS to 0. Then if flip==0, heads=heads+1 Return Heads. Do same for Tails and see if it makes any sense. Regards. Sent from my BlackBerry wireless device from MTN -Original Message- From: Colleen Glaeser Sender: tutor-bounces+delegbede=dudupay@python.org Date: Fri, 1 Oct 2010 02:49:33 To: Subject: [Tutor] Coin Toss Problems ___ 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] Printing prime numbers
Ok. I will do that as soon As I get back to my workstation. Sent from my BlackBerry wireless device from MTN -Original Message- From: Shashwat Anand Date: Thu, 30 Sep 2010 19:11:33 To: Cc: Subject: Re: [Tutor] Printing prime numbers On Thu, Sep 30, 2010 at 5:27 PM, wrote: > Hi all, > I am trying to write a function that prints out which number is prime in > range (1,500) > The function would check thru and the print out something like > 1 is prime > 2 is prime > 3 is prime > 4 is not > 5 is prime > > Please help me. > Thank you. > Can you show us your attempts. We may try to help where you did wrong. > Sent from my BlackBerry wireless device from MTN > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > -- ~l0nwlf ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Printing prime numbers
Hi all, I am trying to write a function that prints out which number is prime in range (1,500) The function would check thru and the print out something like 1 is prime 2 is prime 3 is prime 4 is not 5 is prime Please help me. Thank you. Sent from my BlackBerry wireless device from MTN ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor