Search code examples
pythondice

How do you determine the number of inputs from an integer in a prior input? Dice game


Question: Antonia and David are playing a game. Each player starts with 100 points. The game uses standard six-sided dice and is played in rounds. During one round, each player rolls one die. The player with the lower roll loses the number of points shown on the higher die. If both players roll the same number, no points are lost by either player. Write a program to determine the final scores.

Input Specification The first line of input contains the integer n (1 ≤ n ≤ 15), which is the number of rounds that will be played. On each of the next n lines, will be two integers: the roll of Antonia for that round, followed by a space, followed by the roll of David for that round. Each roll will be an integer between 1 and 6 (inclusive). Output Specification The output will consist of two lines. On the first line, output the number of points that Antonia has after all rounds have been played. On the second line, output the number of points that David has after all rounds have been played.

One of my many problems is making the program list the correct number of inputs the first input specifies.

Here is what I have so far:

rounds = input()
score1 = input()[0:3]
score2 = input()[0:3]
score3 = input()[0:3]
score4 = input()[0:3]

game = [score1, score2, score3, score4]

antonia = 100
david = 100


for scores in game:
    roll = game
    a = game[0]
    d = game[2]
    if a > d:
        antonia -= int(d[0])
    elif d < a:
        david -= int(a[2])
    elif a == d:
        break
print(antonia)
print(david)

I know I only asked for one thing specifically, but can anyone complete this challenge and explain the best way to do it?


Solution

  • I obviously won't solve this homework-like task for you, but to perform n rounds (in your case
    n = rounds) you should use a for loop like you have in your program with range:

    rounds = input()
    for i in range(rounds):
        ...
    

    This will be executed rounds times (0...rounds-1). And i will be the index.