Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+5 votes

So I have a loop creating all of the low temps in question 1 in Routine Practice 7 but when I print the max(str(variable)) it only takes the last number. Does anyone know how to keep all of the temps for the max() input?

asked in CSC201 Spring 2021 by (1 point)

2 Answers

+2 votes

If you use the max() syntax for question 1 RP7,
I think that you should including all numbers of input temp into a list so that Python can filter the greatest
Ex:

temp = [-1, -10, -23, -5, -15]
print(max(temp))

Also, there is another way to do 1st question by using the loop and if functions, which is similar to this example during class. You can check it here:
https://moodle.augustana.edu/mod/resource/view.php?id=163141

Hope this helps!

answered by (1 point)
edited by
+2 votes

Instead of attempting to use the max() function, which we haven't talked about in class, I expect students to use an accumulator loop where you:
1) before the loop, assign a "maxSoFar" variable to be an extremely low value to start with (that is lower than any possible value the user might enter)
2) in the loop, keep checking whether the number just entered by the user is greater than the maxSoFar variable, and if it is, then update the maxSoFar variable.

See the pinball wizard example from class, which is posted on Moodle. It looks like Nhi was kind enough to post a direct link to it. It might also be helpful to review the slides from Friday, which are also posted on Moodle.

answered by (508 points)
...