Python: Solutions to coding challenges Issue 12
Issue 12 Solutions: Using Python modules effortlessly!
Challenge 1: Dice Roller
import random
def roll_dice():
"""Simulates rolling two six-sided dice and returns the total."""
die1 = random.randint(1, 6)
die2 = random.randint(1, 6)
total = die1 + die2
print(f"You rolled a {die1} and a {die2} for a total of {total}")
return total
# Example usage
roll_dice()
Explanation:
Import the
ran…
Keep reading with a 7-day free trial
Subscribe to Young Pythoneers to keep reading this post and get 7 days of free access to the full post archives.