Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dice Roller
#4
Only problem I see with your code. Is those nasty recursive calls.
Using loops is a better solution.
import random

def dice():
    while True:
        roll_dice = input('roll ? >> ')
        if roll_dice in ['y', '']:
            print(random.choice(range(1, 7)))
        elif roll_dice == 'n':
            break
        else:
            print('invalid entry')

dice()
99 percent of computer problems exists between chair and keyboard.
Reply


Messages In This Thread
Dice Roller - by mcmxl22 - Feb-03-2018, 09:19 PM
RE: Dice Roller - by Windspar - Feb-04-2018, 02:15 PM
RE: Dice Roller - by mcmxl22 - Feb-04-2018, 08:11 PM
RE: Dice Roller - by Windspar - Feb-05-2018, 02:09 AM
RE: Dice Roller - by buran - Feb-05-2018, 09:45 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  A CLI based Dice Roller. Ablazesphere 10 6,824 Oct-26-2018, 11:41 AM
Last Post: snippsat
  Dice roller with Tkinter GUI Yojul 1 6,328 Oct-24-2018, 01:40 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020