Rugby Scores

Write a program that allows a rugby team to calculate their points from tries and conversions.

  • Each try that is scored is worth 5 points.
  • After each try, a successful conversion awards an additional 2 points.

The program should ask the user how many tries were scored. For each try, ask if the conversion was successful. If it was successful, 2 additional points should be added to the score. At the end of the program, the team’s score should be displayed.

How many tries were scored? 3
Was the conversion successful? (y/n): y
Was the conversion successful? (y/n): n
Was the conversion successful? (y/n): y
The team's final score is 19 points
SET score TO 0

RECEIVE tries FROM KEYBOARD

FOR i FROM 1 TO tries DO
    SET score TO score + 5
    OUTPUT "Was the conversion successful? (y/n)"
    RECEIVE conversion FROM KEYBOARD
    IF conversion = "y" THEN
        SET score TO score + 2
    END IF
END FOR

OUTPUT "The team's final score is", score, "points"

score = 0

tries = int(input("How many tries were scored? "))

for i in range(tries):
    score = score + 5   # add points for the try
    conversion = str(input("Was the conversion successful? (y/n): "))
    if conversion == "y":
        score = score + 2

print("The team's final score is", score, "points")

# Set score to 0
score = 0

# Get the number of tries from the user
tries = int(input("How many tries were scored? "))

# Repeat for the number of tries
for i in range(tries):
    # Add 5 to the score for each try
    score = score + 5   # add points for the try
    # Ask the user if the conversion was successful
    conversion = str(input("Was the conversion successful? (y/n): "))
    # If the user answered yes, increase score by 2
    if conversion == "y":
        score = score + 2

# Display the team's final score
print("The team's final score is", score, "points")

Extension

Extend the program to calculate the score for two teams. Then display which team won or if it was a draw.

How many tries did team 1 score? 3
Was the conversion successful? (y/n): y
Was the conversion successful? (y/n): y
Was the conversion successful? (y/n): n
How many tries did team 2 score? 3
Was the conversion successful? (y/n): n
Was the conversion successful? (y/n): n
Was the conversion successful? (y/n): n
The final score was 19 to 15
Team 1 won!
How many tries did team 1 score? 3
Was the conversion successful? (y/n): n
Was the conversion successful? (y/n): n
Was the conversion successful? (y/n): n
How many tries did team 2 score? 3
Was the conversion successful? (y/n): y
Was the conversion successful? (y/n): y
Was the conversion successful? (y/n): y
The final score was 15 to 21
Team 2 won!
How many tries did team 1 score? 2
Was the conversion successful? (y/n): y
Was the conversion successful? (y/n): y
How many tries did team 2 score? 2
Was the conversion successful? (y/n): y
Was the conversion successful? (y/n): y
The final score was 14 to 14
It was a draw!

Target

You should be able to use For Loops to solve a problem.