Today I made Pig from a Youtube tutorial
import random
def roll():
min_value = 1
max_value = 6
roll = random.randint(min_value, max_value)
return roll
This shows the max and minimum numbers that the program can choose by using the random function.
while True:
players = input("Enter the number of players (2 - 4): ")
if players.isdigit():
players = int(players)
if 2 <= players <= 4:
break
else:
print("Must be between 2 - 4 players.")
else:
print("Invalid, try again.")
This one is the Input for the player for the amount of players and if a player puts anything other than 2, 3 or 4 it denies it.
max_score = 50
player_scores = [0 for _ in range(players)]
while max(player_scores) < max_score:
for player_idx in range(players):
print("\nPlayer number", player_idx + 1, "turn has just started!")
print("Your total score is:", player_scores[player_idx], "\n")
current_score = 0
while True:
should_roll = input("Would you like to roll (y)? ")
if should_roll.lower() != "y":
break
value = roll()
if value == 1:
print("You rolled a 1! Turn done!")
current_score = 0
break
else:
current_score += value
print("You rolled a:", value)
print("Your score is:", current_score)
player_scores[player_idx] += current_score
print("Your total score is:", player_scores[player_idx])
This one adds the score together and if a players get a one it resets the players score back to zero.
max_score = max(player_scores)
winning_idx = player_scores.index(max_score)
print("Player number", winning_idx + 1,
"is the winner with a score of:", max_score)
This one prints the winners score and announces the winner.

Awesome! This is a great example of what I am looking for in a blog post.