A function is a named sequence of statements that performs a computation. A function is like a group of statements within a program that perform a specific task of a large program. When you define a function, you specify the name and the sequence of statements. Functions can be executed in order to perform overall program task. The functions allowed me to break my program into smaller, manageable parts. The functions I used in my program were,
title_msg(): Displays the program title
get_choice(): Asks the user to select an option.
check_choice(): Validates user input.
option1(), option2(), option3(), option4(): Each function calculates and displays the highest value for a different statistic.
main(): Controls the program’s flow by calling other functions.
Calling a function
Later, you need to call the function by name. Calling a function means executing it. In my program for example, option1() is called if the user selects option 1. This would trigger the function to run and display the highest scoring position.
Passing Arguments
Passing arguments is when you provide input values to a function. For example in my program check_choice (min_val, max_val) would take min_val and max_val as arguments to set the valid input range.
Returning Values
A function returns a value when it sends data back to the part of the prograsm tha called it. Check_choice() returns the users choice so that the get_choice() function can use it. Most of my functions just print results directly.
The Python program I made is an NBA position comparison program that analyzes and compares key statistical averages such as points, rebound seals, blocks and assists for different basketball positions. Parentheses center power forward point guard small forward and shooting guard parentheses the user is prompted with a set of options to explore these statistics, including which position excels in each category bullet point The program calculates, and displays which NBA position has the highest average points per game, rebounds per game, steals + blocks per game, and assists per game. The user can select from these options to view the best performing positions in each category. The program provides a summary of the relevant statistics for each position and helps users gain insights into the strengths and different roles of different positions in basketball.
This program is highly relevant to the topic of NBA positions because it provides a deeper understanding of how different positions contribute to the overall success of a basketball team by focusing on individual stats. The program allows users to see the distinctions between positions and allows users to appreciate the specialized roles that players perform and what statistics come from playing these roles Whether it’s a point guards play making ability or a centers dominance in blocks and rebounds. This program can overall help users visualize how each position impacts the game in different ways. This insight is crucial for those trying to learn about basketball analytics, player performance, and team dynamics.
My NBA position guessing game defines key statistics such as (PTS, TRBS, AST, STL, and BLK) for all positions in the NBA. My program allows users to compare them through a menu-driven system. The program continues to run until user requests to quit. Input validation ensures only valid options are accepted, otherwise error message will be shown. Conditional statements determine the position with the highest value for each category. (if, elif, else) My program uses the max function to find the highest average for that category inside the list. The arithmetic operations being used is the max function. My program uses the + as a string operation. It is used to combine strings.