Question: Using Python without print At the beginning of a game of snooker, the red balls are placed in a triangular pattern, with 1 ball in

Using Python without print

At the beginning of a game of snooker, the red balls are placed in a triangular pattern, with 1 ball in the first row and 1 more ball in each subsequent row (see the snooker setup here). This is also the setup at the beginning of a game of eight-ball pool (image here). For example, the first 3 rows contain 6 balls (1+2+3) and the first 5 rows contain 15 balls (1+2+3+4+5).

This is related to a concept in computer science and mathematics called triangular numbers, which you should research here. Look for a formula for computing a triangular number 1 + + n directly (that is, without adding them explicitly using n 1 additions, which is slower and would require iteration with a for loop, a future topic).

Write the function nSnookerBall(nRow) that takes a nonnegative integer nRow, representing the number of rows of balls, and returns an integer, the number of balls in the associated rack. Notice that we are generalizing from a rack of 5 rows to a rack with any number of rows.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!