Re: [Tutor] Another question, dictionaries
On 02/03/18 21:05, Roger Lea Scherer wrote: > ability to exchange point between the pool and each of the, what I call, > attributes of Strength, Health, Wisdom, and Dexterity. I got only to the > first option and I'm stuck on how to get the points to change > "permanently". The program will run well for option 1 (I haven't got to the > rest of the options), but the next time I run the program it goes back to > the original configuration. Did I do everything right, but I just need to > write to a file, and that's what the problem is? or what? You are correct on all counts. Every time you run the program it is reinitialised to the hard coded values. To make the changes stick you would need to store them somewhere and then read them at startup. There are many ways to do that, some work better than others with dictionaries: the shelve module or the CSV module or the JSON module are all fairly easy to use. However, I suspect the book's author is only looking for you to play the game once and then forget the values (or start afresh) She/he will likely cover files later. To that end you need to look at wrapping your menu selection in a loop (probably a while) and keep on applying the changes until you are done. -- 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
Re: [Tutor] shooting method in python code
On 02/03/18 20:42, Alessandro Parisi wrote: > Hi, My name is Alessandro Parisi, Hi. > I would need to download this code to understand how it works What code? Do you have a URL? Or a link of some kind? We are not mind readers. -- 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] Another question, dictionaries
I'm trying to finish chapter 5 in my book and it has to do with dictionaries and creating simple games. We need a pool of points and the ability to exchange point between the pool and each of the, what I call, attributes of Strength, Health, Wisdom, and Dexterity. I got only to the first option and I'm stuck on how to get the points to change "permanently". The program will run well for option 1 (I haven't got to the rest of the options), but the next time I run the program it goes back to the original configuration. Did I do everything right, but I just need to write to a file, and that's what the problem is? or what? I've reread the chapter, I've gone on stackoverflow and thegeekstuff.com, I've thought about it for at least a day and I just can't figure out what the problem is. Please help? # Character creator program for role playing pool = 30 attributes = {"Strength": 0, "Health": 0, "Wisdom": 0, "Dexterity": 0} print("You have", pool, "points") print(""" You can apply them to your Strength, Health, Wisdom, or Dexterity. Press: 0 to Quit 1 to apply points to Strength 2 to apply points to Health 3 to apply points to Wisdom 4 to apply points to Dexterity 5 to apply points from Strength to your pool 6 to apply points from Health to your pool 7 to apply points from Wisdom to your pool 8 to apply points from Dexterity to your pool """) choice = input("Choice: ") print(attributes.get("Strength")) if choice == "0": print("Good-bye.") input("\n\nPress enter to exit.") elif choice == "1": strengthChoice = input("How many points would you like to transfer from pool to Strength?: ") print(strengthChoice) attributes["Strength"] += int(strengthChoice) print(attributes.get("Strength")) pool -= int(strengthChoice) print(pool) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] shooting method in python code
Hi, My name is Alessandro Parisi, I would need to download this code to understand how it works ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python distribution file error
On 02/03/18 02:40, Nirmal Bhatt wrote: > Hi, > I am trying to deploy the distribution file What do you mean by "the distribution file"? How are you creating this file? How are you "deploying" it? > and getting the attached error. The server strips out attachments so we cannot see it, please just paste the (full) text into the mail message. > Requesting the help to resolve the error. You need to provide us with more specific information about what you are doing and how. -- 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 distribution file error
Hi, I am trying to deploy the distribution file and getting the attached error. Requesting the help to resolve the error. Thanks in advance. regards Nirmal ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor