I was set a task in my computing lesson to make a dice roll script in Python.
I made one, but then thought "How could I make it more efficient?".
In a few minutes I shortened my code down to 5 lines.
Which got me thinking, how short can you get it?
I challenge the Coders Lounge to create the shortest dice roll script you can in Python, it must follow the following:
"A game uses dice with 4, 6 and 12 sides to determine various outcomes.
Design, code and test a program that will simulate throwing dice with these numbers of sides.
The user should be able to input which dice is being thrown, eg 4, 6 or 12.
The program should output the dice chosen and the score,
for example ‘6 sided dice thrown, score 4’
The user should be able to repeat this process as many times as required."
As an example, this is my code:
Code:
import random
while True:
    dice = input("What dice do you want to roll? (4, 6 or 12): ")
    if dice == "4" or dice == "6" or dice == "12": print(dice, "sided dice thrown, score", random.randint(1, int(dice)), "\n")
    else: print("That is not a valid input, try again.\n")
Good luck!