In Very Basic Python:
Kyle Lowry is trying to calculate his career statistics thus far in his illustrious career.
Write a program that prompts the user for Lowry’s average points per game (ppg) in EACH of his 14 seasons in the NBA.
The program will display the number of seasons in which he averaged 15 ppg or more, his career average, and his best season (SEASON # in which he had his highest ppg). [
CODE:
#DECLARE A LIST TO STORE AVERAGE POINTS PER GAME(PPG) OF 14 SEASONS
average_ppg=[]
#ITERATE FOR LOOP 14 TIMES TO INPUT THE AVERAGE PPG FOR EVERY SEASON
for i in range(14):
#INPUT AVERAGE PPG IN EACH SEASON
#INPUT STATEMENT TO PROMPT USER
str1="Enter the average points per game(ppg) in season ",(i+1),": "
avg_ppg=int(input(str1))
#ADD THE INPUT TO THE LIST TO FIND THE CAREER STATISTICS LATER
average_ppg.append(avg_ppg)
#INITIALIZE A VARIABLE TO COUNT THE NUMBER OF SEASONS IN WHICH LOWRY AVERAGED 15 PPG OR MORE
count_average=0
#INITAILIZE A VARIABLE TO FIND AVERAGE PPG OF ALL 14 SEASONS
career_average=0
#FIND THE BEST SEASON OF ALL THE SEASONS
best_season=0
#CALCULATE BEST SEASON USING THE HIGHEST PPG OF ALL THE 14 SEASONS
highest_ppg=0
for i in range(14):
#CHECK IF AVERAGE PPG OF ANY SEASON IS GREATER THAN OR EQUAL TO 15 THAN INCREMENT COUNT
if average_ppg[i]>=15:
count_average+=1
#SUM AVERAGE PPG OF ALL 14 SEASONS
career_average+=average_ppg[i]
#FIND THE BEST SEASON HAVING HIGHEST PPG OF ALL THE SEASONS
if highest_ppg<average_ppg[i]:
highest_ppg=average_ppg[i]
best_season=i+1
#CALCULATE CAREER AVERAGE OF 14 SEASONS
career_average/=14
#PRINT ALL THESE CALCULATED STATISTICS
print("The number of seasons in which Kyle Lowry averaged 15 ppg or more: ",count_average)
print("The career average of Kyle Lowry: ",career_average)
print("The Best Season of Kyle Lowry is Season: ",best_season," with highest ppg of: ",highest_ppg)
CODE SNIPPET:
#DECLARE A LIST TO STORE AVERAGE POINTS PER GAME(PPG) OF 14 SEASONS
average_ppg=[]
#ITERATE FOR LOOP 14 TIMES TO INPUT THE AVERAGE PPG FOR EVERY SEASON
for i in range(14):
#INPUT AVERAGE PPG IN EACH SEASON
#INPUT STATEMENT TO PROMPT USER
str1="Enter the average points per game(ppg) in season ",(i+1),": "
avg_ppg=int(input(str1))
#ADD THE INPUT TO THE LIST TO FIND THE CAREER STATISTICS LATER
average_ppg.append(avg_ppg)
#INITIALIZE A VARIABLE TO COUNT THE NUMBER OF SEASONS IN WHICH LOWRY AVERAGED 15 PPG OR MORE
count_average=0
#INITAILIZE A VARIABLE TO FIND AVERAGE PPG OF ALL 14 SEASONS
career_average=0
#FIND THE BEST SEASON OF ALL THE SEASONS
best_season=0
#CALCULATE BEST SEASON USING THE HIGHEST PPG OF ALL THE 14 SEASONS
highest_ppg=0
for i in range(14):
#CHECK IF AVERAGE PPG OF ANY SEASON IS GREATER THAN OR EQUAL TO 15 THAN INCREMENT COUNT
if average_ppg[i]>=15:
count_average+=1
#SUM AVERAGE PPG OF ALL 14 SEASONS
career_average+=average_ppg[i]
#FIND THE BEST SEASON HAVING HIGHEST PPG OF ALL THE SEASONS
if highest_ppg<average_ppg[i]:
highest_ppg=average_ppg[i]
best_season=i+1
#CALCULATE CAREER AVERAGE OF 14 SEASONS
career_average/=14
#PRINT ALL THESE CALCULATED STATISTICS
print("The number of seasons in which Kyle Lowry averaged 15 ppg or more: ",count_average)
print("The career average of Kyle Lowry: ",career_average)
print("The Best Season of Kyle Lowry is Season: ",best_season," with highest ppg of: ",highest_ppg)
OUTPUT:
Enter the average points per game(ppg) in season ,1,: 15
Enter the average points per game(ppg) in season ,2,: 5
Enter the average points per game(ppg) in season ,3,: 15
Enter the average points per game(ppg) in season ,4,: 5
Enter the average points per game(ppg) in season ,5,: 5
Enter the average points per game(ppg) in season ,6,: 5
Enter the average points per game(ppg) in season ,7,: 3
Enter the average points per game(ppg) in season ,8,: 15
Enter the average points per game(ppg) in season ,9,: 20
Enter the average points per game(ppg) in season ,10,: 21
Enter the average points per game(ppg) in season ,11,: 8
Enter the average points per game(ppg) in season ,12,: 6
Enter the average points per game(ppg) in season ,13,: 9
Enter the average points per game(ppg) in season ,14,: 14
The number of seasons in which Kyle Lowry averaged 15 ppg or more: 5
The career average of Kyle Lowry: 10.428571428571429
The Best Season of Kyle Lowry is Season: 10 with highest ppg of: 21
SUMMARY:
The above python code is written in a very basic manner and all the functionalities are explained in the comments of the program. The code is implemented using list to store all the average ppg of 14 seasons and for loop to process these and get all the required statistics. You can run this code online on google colab or any online compiler or softwares.
Get Answers For Free
Most questions answered within 1 hours.