def learn_to_program(): return """ CS149 - Introduction to Programming Department of Computer Science James Madison University Spring 2022 """
The goal of this assignment is to gain experience working with:
For this homework, and all of the remaining homeworks, all of your modules and functions must exhibit correct documentation. Submissions that don’t pass docstring checks will receive no credit.
You should read the Docstring Requirements carefully to see how it should be done.
Back in HW 6 you created a program that determined if numbers were positive or negative, and another that sorted numbers into even and odd. Now you will create a function that sorts numbers input by the user into separate lists of positive and negative numbers. Your program will read numbers from the keyboard until the user inputs a ‘q’.
Name your program while_signs.py
. Write a function get_positive_negative()
that:
Input?
(notice the trailing space).For instance:
Computers aren’t born knowing how to perform integer division; they must be programmed to do it. One such method is the division algorithm, described below.
Say you want to divide an integer n ≥ 0 by an integer d > 0. To find the quotient and remainder, follow these steps:
You can test you’ve done it right by checking that n = qd + r.
In a file named division.py
, write a function divide
that takes two parameters, number and divisor, in that order, that performs the division algorithm to find number/divisor and returns the two values q and r in that order.
Back in Exercise 3.3 you created a program for JMU Basketball that printed the scoring for a single player, and in Exercise 5.4 a function that returned all the statistics for a single player. They would now like you to create a function that will print the statistics for a large number of players all at once.
Name your program even_more_stats.py
. Write a function called print_stats
that does two things:
The function will take a single parameter, a list that contains all the statistics for the players. A sample list is as follows:
'Jefferson', 706, 88, 57), ('Hazell', 615, 62, 62), ('Tucker', 551, 137, 17)] [(
(Statistics from 2020-2021 JMU Women’s Basketball Team)
The list consists of tuples, each of which lists a player’s name, their total points, total rebounds, and total assists for the season. Your code should print a line for each player (as demonstrated below), and then print the total points, total rebounds, and total assists, calculated for the entire list.
The output should be as follows:
Note: Iterating through a list of elements like this would normally be accomplished using a for-loop, not a while-loop. We’ll see how to use for-loops for problems like this next week. For now, your solution must use a while-loop.