Re: [Tutor] Python programming for the absolute beginner
On Fri, Sep 29, 2017 at 1:20 PM, Alan Gauld via Tutorwrote: > On 29/09/17 08:51, Peter Collidge wrote: >> I have borrowed the above book from my local library but I believe it was >> written in 2010 and as a result I am having difficulty in deciding which >> version of Python to download. >> Can anyone help? > > If you want to follow the book use the version the book > uses - probably 2.6 or something close? I no longer have a copy of this book, but I am fairly certain it uses an early version of Python 3. The main problem, though, is it uses a customized version of Pygame for its later gaming code called Livewires, so that would have to be Python-version-compatible. IIRC, the author had a download site where you could get the whole package together: correct Python version used in book, correct Livewires version, etc., and that this was addressed in the book (Maybe an appendix? Or the first get things setup chapter? Can't remember for sure.) If the OP goes on to use the sequel to this book, named "More Python Programming for the Absolute Beginner" (By a different author.), *that* book uses straight-up Pygame, again with an early version of Python 3. Again, I don't think there will be any problems with the exact version of Python 3 used as long as the version of Pygame is compatible with the chosen Python. -- boB ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python programming for the absolute beginner
On Fri, Sep 29, 2017 at 7:20 PM, Alan Gauld via Tutorwrote: > If you want to follow the book use the version the book > uses - probably 2.6 or something close? > I think the book uses either Python 3.0 or 3.1. It's been a while since I read it but it doesn't use Python 2. The 2nd edition written in 2010 used Python 3 but the 1st edition used Python 2. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python programming for the absolute beginner
Hi Peter My company primarily uses 2.7, but as I understand it 2.x flavors are compatible with each other. 2.x scripts are generally not compatible with 3.x versions and vice versa So, keep that in mind. Regards, -John -Original Message- From: Tutor [mailto:tutor-bounces+john.b.larocca=intel@python.org] On Behalf Of Peter Collidge Sent: Friday, September 29, 2017 12:51 AM To: tutor@python.org Subject: [Tutor] Python programming for the absolute beginner I have borrowed the above book from my local library but I believe it was written in 2010 and as a result I am having difficulty in deciding which version of Python to download. Can anyone help? Thanks Peter Collidge ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python programming for the absolute beginner
On 29/09/17 08:51, Peter Collidge wrote: > I have borrowed the above book from my local library but I believe it was > written in 2010 and as a result I am having difficulty in deciding which > version of Python to download. > Can anyone help? If you want to follow the book use the version the book uses - probably 2.6 or something close? When you finish the book move to Python 3.6 and go through the official tutorial that accompanbies it, that should bring you up to date with the latest version. There won't be a huge difference but there are significant changes in moving from 2 to 3, so use the version you are studying first then upgrade. All the older versions are available on the download page of python.org. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Python programming for the absolute beginner
I have borrowed the above book from my local library but I believe it was written in 2010 and as a result I am having difficulty in deciding which version of Python to download. Can anyone help? Thanks Peter Collidge ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Programming for the absolute beginner 3e Ch3 Challenge 1
On 27/07/16 02:39, kanishk srivastava wrote: > Hello, > > I am working through Michael Dawson's book - Python Programming for > absolute beginners 3e. > > Completed chapter 3, but unable to solve challenge 1. I don't know the book so don't know how much you know yet. So thee are some suggestions below that might not make sense to you because you haven't covered the material. Apologies in advance! > print("\t\tFortune Cookie") > print("\t\tWelcome user!") > > # fortune messages > message1 = "the earth is a school learn in it." > message2 = "be calm when confronting an emergency crisis." > message3 = "you never hesitate to tackle the most difficult problems." > message4 = "hard words break no bones, fine words butter no parsnips." > message5 = "Make all you can, save all you can, give all you can." Have you covered lists? Rather than a set of numbered messages you could put them in a list and access each message by index: messages = ["the earth is a school learn in it.", "be calm when confronting an emergency crisis.", "you never hesitate to tackle the most difficult problems.", "hard words break no bones, fine words butter no parsnips.", "Make all you can, save all you can, give all you can." ] And access them with messages[0], messages[1], ... messages[4] Although in this case you don't even need to do that, read on... > import random I don't know how many of the random module functions you cover but there are a lot of them. One of them, random.choice(aList), selects a random item from a list. So now that you have a list of messages it becomes trivial to select a random message from the list: > print("Your today's fortune ") use print(random.choice(messages)) here hth -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Python Programming for the absolute beginner 3e Ch3 Challenge 1
Hello, I am working through Michael Dawson's book - Python Programming for absolute beginners 3e. Completed chapter 3, but unable to solve challenge 1. Below code is what I have written but unsure on how to have the program generate the message at random. Any help will be appreciated. # Fortune Cookie # Demonstrates random message generation print("\t\tFortune Cookie") print("\t\tWelcome user!") # fortune messages message1 = "the earth is a school learn in it." message2 = "be calm when confronting an emergency crisis." message3 = "you never hesitate to tackle the most difficult problems." message4 = "hard words break no bones, fine words butter no parsnips." message5 = "Make all you can, save all you can, give all you can." import random print("Your today's fortune ") input("\n\nPress the enter key to exit") Thanks Kyo ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Python Programming for the Absolute Beginner - Chap 7 Q: 2
Hello, I am a python newbie. I am reading this book (Python Programming for the Absolute Beginner). I am on Chapter 7, Question 2. Improve the Trivia Challenge game so that it maintains a high-scores list in a file. The program should record the player's name and score. Store the high scores using a pickled object. I have the following code so far: def high_score(): Records a player's score high_scores = [] #add a score // Do current stuff for adding a new score... name = input(What is your name? ) player_score = int(input(What is your score? )) entry = (name, player_score) high_scores.append(entry) high_scores.sort(reverse=True) high_scores = high_scores[:5] # keep only top five # dump scores f = open(pickles1.dat, wb) pickle.dump(high_scores, f) f.close() f = open(pickles1.dat, rb) high_scores = pickle.load(f) print(high_scores) f.close() When I execute this program in the main() program I get only the existing single name, player_score list combination stored in the pickles1.dat file. Can someone walk me through how it can store all the values each time the program is ran? Thanks, Zack H. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Programming for the Absolute Beginner - Chap 7 Q: 2
On 12/08/13 01:52, Zack Hasanov wrote: I have the following code so far: def high_score(): high_scores = [] name = input(What is your name? ) player_score = int(input(What is your score? )) entry = (name, player_score) high_scores.append(entry) high_scores.sort(reverse=True) high_scores = high_scores[:5] # keep only top five Note that you never read the stored values from your pickle file you just add a single value. # dump scores f = open(pickles1.dat, wb) pickle.dump(high_scores, f) f.close() This then dumps that single value to the file overwriting anything that might have already been there. f = open(pickles1.dat, rb) high_scores = pickle.load(f) print(high_scores) You then load the new value and print it. When I execute this program in the main() program I get only the existing single name, player_score list combination stored in the pickles1.dat file. I have no idea how you call this. Presumably from within a loop? But because you never read in the stored values before writing the new you only ever get the last value stored. You need to insert code like your last block above at the top of the function to pre-populate high_scores before adding the new entry. Once you get that working we can look at tidying up some of the unnecessary code that will be left over, but lets get it working first! HTH -- Alan G 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 Programming for the absolute beginner 3e, Ch3 Challenge 4
Thanks for getting back to me... I am using Python 3.3.2. The challenge is as follows: # Chapter 3 Challenge 4 # # Write the psudocode for a program where the player and the computer # trade places in the number guessing game. That is, the player picks a # random number between 1 and 100 that the computer has to guess. # Before you start, think about how you guess. If all goes well, try # coding the game. It builds on the previous challenge, where the user guesses the number - I coded that OK, as below. import random print(\tWelcome to 'Guess My Number'!) print(\nI'm thinking of a number between 1 and 100.) print(Try to guess it in as few attempts as possible.\n) # set the initial values the_number = random.randint(1, 100) guess = int(input(Take a guess: )) tries = 1 # guessing loop while guess != the_number and tries 10: if guess the_number: print(Lower...) else: print(Higher...) guess = int(input(Take a guess: )) tries += 1 if guess == the_number: print(You guessed it! The number was, the_number) print(And it only took you, tries, tries!\n) else: print(Huh - you took , tries, tries and still never got it.) print(It was , the_number, - but why tell you, you'll forget it, won't you.) input(\n\nPress the enter key to exit.) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Programming for the absolute beginner 3e, Ch3 Challenge 4
Also don't know how to do a binary chop, but the book hasn't covered anything like that - it has just taught if, else and while, A binary chop is an algorithm. All you need is if/else and while. The algorithm looks a bit like this: while not found determine the middle value between min and max if value target set max to value if value target set min to value else found = True the_number = int(input(Type in a number - I swear down I no look!^^ ))You don't need to store the number since the human user can just remember it print(But I asked the computer, and it reckons your number is...) guess = (random.randint(1, 100))You don't want to use random guesses - that could take a very long time! while guess != the_number: hilo = input(\nWas I too high or too low? Write 'h' or 'l'.\n) if hilo == h: print(\nToo high, well, in that case what about...\n) lower_guess = (random.randint(lowest, temp))This is almost right except you will be faster using the mid value rather than a random one. And what happened in the shell: Hello Welcome to 'Modified Guess My Number'! Think of a number between 1 and 100 the computer has to guess it. Type in a number - I swear down I no look!^^ 30 OK you wrote 30 but I no show the computer. But I asked the computer, and it reckons your number is... 57 Was I too high or too low? Write 'h' or 'l'. h Too high, well, in that case what about... 10 Was I too high or too low? Write 'h' or 'l'. l Too low, well, in that case what about... 53 Was I too high or too low? Write 'h' or 'l'. h Too high, well, in that case what about... 51 Was I too high or too low? Write 'h' or 'l'. hAs you can see its working, but just taking a lot of guesses. You will speed it up dramatically if you calculate the mid point rather than use random. HTH Alan G.___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Programming for the absolute beginner 3e, Ch3 Challenge 4
# Write the psudocode for a program where the player and the computer # trade places in the number guessing game. That is, the player picks a # random number between 1 and 100 that the computer has to guess. # Before you start, think about how you guess. If all goes well, try # coding the game. It builds on the previous challenge, where the user guesses the number - I coded that OK, as below.OK, So which bits of this challenge puzzle you? Can you write down the process you used when guessing the numbers? Can you turn that description into pseudo-Python code? Hint: You need to get the computer to generate numbers in an ever narrowing range, Maybe the midpoint number? (You could also google binary chop to get more ideas) Then you need to tell the computer which direction it should go next. Have a stab at it, get back to us with what you've come up with. HTH Alan G. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python Programming for the absolute beginner 3e Ch3 Challenge 4
Hello, I am working through Michael Dawson's book, Python Programming for the absolute beginner 3rd edition. Have just completed Chapter 3, but cannot solve Challenge 4. Has anyone solved this yet - and be willing to share this code? I would much appreciate.. John. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Programming for the absolute beginner 3e Ch3 Challenge 4
On 08/08/13 18:05, John Feleppa wrote: I am working through Michael Dawson's book, Python Programming for the absolute beginner 3rd edition. Have just completed Chapter 3, but cannot solve Challenge 4. Has anyone solved this yet - and be willing to share this code? If you give us a clue what it is then more of us might be able to give you a hint... Especially if you tell us what you've tried so far. Also what python version you are using... -- Alan G 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 Programming for the Absolute Beginner
Hello~ I'm working through the Book Python Programming for the Absolute Beginner and am wondering if you could help me out with the coding to certain Challenges at the end of the book, specifically chapter 7 challenges 1 and 2 and chapter 8 challenges 1 and 3. Could you help? I need something to compare my coding to. Thank you! ~Grace Sent from my iPad___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Programming for the Absolute Beginner
Hi Grace, On Thu, May 2, 2013 at 8:04 AM, Grace Kathryn grace_k_por...@earthlink.netwrote: Hello~ I'm working through the Book Python Programming for the Absolute Beginner and am wondering if you could help me out with the coding to certain Challenges at the end of the book, specifically chapter 7 challenges 1 and 2 and chapter 8 challenges 1 and 3. Could you help? I need something to compare my coding to. Welcome. I am sure somebody will be able to help you out. However, you would need to tell what exactly the challenges are and if possible, any specific problem you are facing for someone to help you. Not all of the members in this list may have access to the book. Best, Amit. Thank you! ~Grace Sent from my iPad ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- http://echorand.me ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Programming for the Absolute Beginner
I'm working through the Book Python Programming for the Absolute Beginner and am wondering if you could help me out with the coding to certain Challenges at the end of the book, specifically chapter 7 challenges 1 and 2 and chapter 8 challenges 1 and 3. Since I personally don't have that particular book, and I imagine many others on this mailing list don't either, it'll be hard for us to comment on the challenges, given that we don't know what they are. -- best regards, Robert S. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Programming for the Absolute Beginner
i completed this book and i did every exercise. are you asking for help with the challenges, or have you completed them and want code to compare yours too? im relunctant to share challenge code, incase you havent done them. They are really good exercises to try doing. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python Programming for the Absolute Beginner-OT
A bit OT, but still within the realm of beginning Python... My co-worker whom has just started learning Python, bought this book in used condition. http://www.courseptr.com/ptr_detail.cfm?group=Programmingsubcat=Otherisbn=978%2D1%2D59863%2D112%2D8 Unfortunately it came without the CD, and the publisher does not have a link for downloading the sources. If you have this book AND the CD, please reply to me OFF-LIST. I would like to get a copy of the files on the CD for my co-worker. Thanks ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor