I am trying to make a simple game for class but I am getting hung up on one of the parts. There are two dice that roll and then you can input either the full sum or multiple numbers that equal the sum (ex. dice = 10 you could pick 10 or 3,2,5). From there each of the numbers picked will be removed from a list.

It should run a little like this,

Dice = 9
Numbers picked = 3, 5, 1
(list after the numbers were removed) [2,4,6,7,8,9]

How would I go about doing this?

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by pyTony

Split on the comma and test for length. If the length is one, then a total was entered, otherwise it is a series of numbers. One alternative is to use easygui, with one box for the total and a second entry box for individual numbers, so which ever box has an entry (length) is the function you choose.

Edited by woooee: n/a

``````>>> dice_num = 9
>>> available = set(range(1, 1+dice_num))
>>> remove = raw_input('Give comma separated values: ')
Give comma separated values: 3,5,1
>>> left_over = available - set(int(r) for r in  remove.strip().split(','))
>>> left_over
set([2, 4, 6, 7, 8, 9])
>>> remove = raw_input('Give comma separated values: ')
Give comma separated values: 4
>>> left_over = available - set(int(r) for r in  remove.strip().split(','))
>>> left_over
set([1, 2, 3, 5, 6, 7, 8, 9])
>>>``````

Edited by pyTony: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.