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 November 28th, 2012, 10:34 AM
PandaGeist1989 PandaGeist1989 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 1 PandaGeist1989 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 m 19 sec
Reputation Power: 0
My dice program

hey guys im fairly new to python and ive been studying it for 3 days now.. this is my 4th draft of my dice program and im calling it a beta release

I just wanted to know what you guys think and if there is any features that it should have

to use the program just type something like 1d6 than if you want to roll more than one dice at a time then press enter and type another set

when your done just type done and press enter

you can also type something like 2d12+4 ^^
------------------------------------------
Code:
#Dice-Roller v4
#Copyright-DreamForged.inc
#You are free to use and redistribute this product as long as credit is giving
#to the above mentioned.
#Thank you for using Dice-Roller.


import random
import time

dice_selection = []

count = 0

print "Welcome to Dice-Roller v3. To use the program read the following instructions."
print "Type in the dice you want to roll(up to a d100) then press enter."
print "For example: If you want multiple dice just hit enter and type in another set."
print "4d6"
print "1d20"
print "When your finished make sure your type prompt is on the line beneith your last"
print "dice entry. Then type done and press enter."
print "Dont type anything other than dice sets or done, the program will error out."
print "-------------------------------------------------------------------------------"
print "\n"

while True:

    if count < 0:
        count = 0
    
    selection_ = raw_input("Set your dice: ")
    
    if selection_ == "done":
        print "\n"
        while count > 0:

            if "d" not in dice_selection[0]:
                print dice_selection[0],": You forgot a d. Or you didnt type in a dice set\n"
                dice_selection[:] = []
                time.sleep(1)
                count = 0
                break;
             
            if dice_selection[0] == "done":
                for i in dice_selection:
                    if "done" not in dice_selection:
                        break;
                    dice_selection.remove("done")
                    
            while " " in dice_selection[0]:
                if " " not in dice_selection[0]:
                    break;
                dice_selection.remove(" ")
            
            dice = dice_selection[0]
            
            if "+" in dice:
                indexMath_ = dice.index("+")
                getMath_ = dice[indexMath_:]
                Math_ = getMath_[0]
                addMath_ = int(dice[indexMath_+1:])
            else:
                indexMath_ = dice.index("d")+4
                         
            d_position = dice.index("d")
            diceCount = int(dice[0:d_position])
            diceType = int(dice[d_position+1:indexMath_])
            rollNum = 0
            rolledList = []
            rolledList[:] = []
            
            while diceCount > 0:
                roll = random.randint(1, diceType)
                rollNum +=1
                print rollNum,":",dice,":",roll
                rolledList.append(roll)
                diceCount -= 1
                    
                if diceCount == 0 and "+" in dice:
                    print "-----Total:",sum(rolledList) ,getMath_,":" ,sum(rolledList)+addMath_
                else:
                    if diceCount == 0:
                        print "-----Total:" ,sum(rolledList)
            
            del dice_selection[0]
            count -= 1
            print "\n"
            if dice_selection == []:
                break;
    
    dice_selection.append(selection_)
    if selection_ == "done":
        count = count
    else:
        count += 1
    

Reply With Quote
  #2  
Old November 28th, 2012, 12:25 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,380 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 13 h 7 m 19 sec
Reputation Power: 383
Code:
           while " " in dice_selection[0]:
                if " " not in dice_selection[0]:
                    break; #### ; separates statements, does not terminate them.

If a space is in dice_selection[0] how could space not be in dice selection[0]? I think you can safely remove the if condition: break statements.

Terminating a program by way of error isn't best practice. Study try: except: statements soon.
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > My dice program

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