Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 3rd, 2013, 01:53 PM
jomiscli jomiscli is offline
Registered User
Click here for more information
 
Join Date: Dec 2012
Posts: 29 jomiscli User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 39 sec
Reputation Power: 0
Code critique?!

Hey! I just wrote a rudimentary character creator program and the code ended up being extremely long, like 350 lines.

Anyhow I was just curious if I could get some critique on it but I don't want to post it because its so long, but I can't figure out how to attach it as a zip. Do I need to host it myself or does this forum have an attachment option?

Reply With Quote
  #2  
Old January 3rd, 2013, 03:34 PM
StevenJM StevenJM is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 12 StevenJM User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 51 m 27 sec
Reputation Power: 0
You could try using Pastebin and adjust the privacy settings as you wish.

Reply With Quote
  #3  
Old January 3rd, 2013, 04:35 PM
jomiscli jomiscli is offline
Registered User
Click here for more information
 
Join Date: Dec 2012
Posts: 29 jomiscli User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 39 sec
Reputation Power: 0
Hey thanks StevenJM. I'll do is ASAP!!

Reply With Quote
  #4  
Old January 3rd, 2013, 05:52 PM
jomiscli jomiscli is offline
Registered User
Click here for more information
 
Join Date: Dec 2012
Posts: 29 jomiscli User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 39 sec
Reputation Power: 0
Character Creator!

The only issue I couldn't resolve here is with this bit of code:

Code:
            while allo_strength > stat_pool_length or allo_strength < 1:
                print("\nInvalid choice.")
                print("You have",stat_pool_length,"stat points in your Stat Pool.")
                allo_strength = int(input("\n(SUB)Please choose a valid amount to allocate: "))
                if allo_strength > stat_pool_length or allo_strength < 1:
                    continue
                else:
                    break


Basically I can't figure out how to check the input for letters or an accidental enter hit. Right now it's only protected from integer inputs. If there is an accidental letter or the enter key is hit an error happens and it exits the program.

I am sure there is a lot wrong with this program and I have a feeling something like this could be done with WAY less lines of code.

Is my first significant program from scratch so I am proud of it!! But if your generous enough to take the time to look at it please be as critcal as you feel necessary! I must learn how to code, I love it!!

Any feedback is greatly appreciated!!!

P.S. Also thanks b49P23TIvg for showing me the .join() function.

EDIT: Thanks StevenJM for leading me to Pastebin, awesome website.

Last edited by jomiscli : January 3rd, 2013 at 05:57 PM. Reason: forgot to thank StevenJM for leading me to Pastebin, what an awesome website!

Reply With Quote
  #5  
Old January 3rd, 2013, 07:25 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is online now
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,365 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 10 h 49 m 13 sec
Reputation Power: 383
We abhor duplicate code. This must have been a nightmare to write. "Gotta make the change in 4 places. OH NO!"

You have 4 cases all the same except for the attribute name and which lists are used. Encapsulate that into a function.

You have many prompts with validity tests. Again, encapsulate into a function.

I started rewriting as
Code:
stat_pool = ['|']*30
strength = []
health = []
wisdom = []
dexterity = []

choice = None

def prompt(message,validSet,tries,failureChoice):
    M = message
    result = failureChoice
    for i in range(tries):
        result = input(M)
        if result in validSet:
            return result
        M = 'Please choose from %s'%str(validSet)
    return failureChoice

while choice != "6":
    attribute = prompt('(MAIN)Please choose an option: ',set('123456'),2,'6')

    if attribute in set('1234'):
        attribute_name = {
            '1':'Strength','2':'Health','3':'Wisdom','4':'Dexterity'
            }[attribute]

You may need a somewhat more clever prompt function with a validation function and exception handling when you get to the numbers representing amounts of stat points to transfer.
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #6  
Old January 4th, 2013, 05:09 AM
jomiscli jomiscli is offline
Registered User
Click here for more information
 
Join Date: Dec 2012
Posts: 29 jomiscli User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 39 sec
Reputation Power: 0
Thank you for the response. Going to learn a ton from this again!!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Code critique?!

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap