Question

Python Question: Define the function high_score that consumes a list of integers (representing scores in a...

Python

Question: Define the function high_score that consumes a list of integers (representing scores in a game) and produces an integer representing the highest score in the list. Ignore scores less than 100, and stop processing values if you encounter -999. If the list is empty, return the value None instead. It is up to you to decompose this function (or not) however you want.

Here is my code so far:

from cisc108 import assert_equal

def high_score(scores: [int])->int:
max_num = None
mini = 100
empty_list = []
if scores == empty_list:
return None
  
for score in scores:
if score < mini:
continue
if score == -999:
break
if score > max_num:
max_num = score
return max_num
  
assert_equal(high_score([300, 40, 200, 150]), 300)
assert_equal(high_score([50, 100, 400, -999]), 400)
assert_equal(high_score([600, 800,]), 800)
assert_equal(high_score([300, 200, -999, 400]), 300)

all of my tests are passing except the last one. i need to stop going through the list once -999 is encountered.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

from cisc108 import assert_equal

def high_score(scores: [int])->int:

max_num = scores[0]

mini = 100

empty_list = []

if scores == empty_list:

return None

for score in scores:

#return max_num when we found -999

if score==-999:

return max_num

if score < mini:

continue

if score == -999:

break

if score > max_num:

max_num = score

return max_num

assert_equal(high_score([300, 40, 200, 150]), 300)

assert_equal(high_score([50, 100, 400, -999]), 400)

assert_equal(high_score([600, 800,]), 800)

assert_equal(high_score([300, 200, -999, 400]), 300)

main.py saved from cisc108 import assert_equal SUCCESS - [line 21] assert_equal (high score ([300, 40, 200, 150]), 300) SUCCE

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
Python Question: Define the function high_score that consumes a list of integers (representing scores in a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Need help writing these functions in Python: FUNCTION 1 get_course_ids: Consumes a list of Course dictionaries...

    Need help writing these functions in Python: FUNCTION 1 get_course_ids: Consumes a list of Course dictionaries and returns a list of integers representing course IDs. Here's what I have so far but I'm getting a Type Error - list indices must be integers or slices, not dict. def get_course_ids(courses): course_ids = [] for course in courses: course_ids.extend(courses[course])    return course_ids FUNCTION 2 choose_course: Consumes a list of integers representing course IDs and prompts the user to enter a valid ID,...

  • Python Language ! Use the Design Recipe to define a function save_history which consumes two parameters,...

    Python Language ! Use the Design Recipe to define a function save_history which consumes two parameters, a nested list and an int representing the current landing attempt. The function should open a new file named LandingNN.csv' where NN is two digits representing the current landing attempt. The first line should contain the number of sublists in the nested list. Each sublists should be written to the file on its own line with its values separated by commas. This function should...

  • Python Program Only: Write the function definition only of the "get(self, index)" function. Plug your method...

    Python Program Only: Write the function definition only of the "get(self, index)" function. Plug your method in the code file shared with you and test it in the main to get the element at index 3 of mylist2 . class Node: def __init__(self, e): self.element = e self.next = None class LinkedList: def __init__(self): self.head = None self.tail = None self.size = 0 def addFirst(self, e): newNode = Node(e) newNode.next = self.head self.head = newNode self.size = self.size + 1...

  • How can I modify my program to accept a list of integers (up to 20 entries)...

    How can I modify my program to accept a list of integers (up to 20 entries) from the user into a list and prints the numbers entered by the user in ascending order, their sum and their average. The program then stops when the user inputs -100 as a number to search. #function that returns largest number def max(numOne,numTwo,numThree): if(numOne > numTwo and numOne > numThree): return numOne elif(numTwo > numOne and numTwo > numThree): return numTwo elif(numThree > numOne...

  • Define the functions in Python 3.8 1. Write a function most frequent n that takes a...

    Define the functions in Python 3.8 1. Write a function most frequent n that takes a list of strings and an integer n, and that returns a dictionary where the keys are the top n most frequent unique words in the list, and the values are the frequency of each word: For example, most frequent n(text, 3) should return the dictionary {'is': 2, "the’: 3, 'of': 2}, and most frequent n(text, 2) could return either {'is': 2, 'the’: 3} or...

  • PYTHON 3 Object Oriented Programming ***a9q3.py file below*** class GradeItem(object): # A Grade Item is anything...

    PYTHON 3 Object Oriented Programming ***a9q3.py file below*** class GradeItem(object): # A Grade Item is anything a course uses in a grading scheme, # like a test or an assignment. It has a score, which is assessed by # an instructor, and a maximum value, set by the instructor, and a weight, # which defines how much the item counts towards a final grade. def __init__(self, weight, scored=None, out_of=None): """ Purpose: Initialize the GradeItem object. Preconditions: :param weight: the weight...

  • Question 1a - Increasing Numbers in List - First Occurence(3 points) Write a function numIncreasing1(L) that...

    Question 1a - Increasing Numbers in List - First Occurence(3 points) Write a function numIncreasing1(L) that takes as input a list of numbers and returns a list of the first sequence within that is increasing order, and has a length of at least 2. If no increasing sequential numbers are found, (ie. the input list is in descending order) then naturally a list of just the first value is returned. Increasing sequence means for a number to be valid it...

  • Professor Dolittle has asked some computer science students to write a program that will help him...

    Professor Dolittle has asked some computer science students to write a program that will help him calculate his final grades. Professor Dolittle gives two midterms and a final exam. Each of these is worth 100 points. In addition, he gives a number of homework assignments during the semester. Each homework assignment is worth 100 points. At the end of the semester, Professor Dolittle wants to calculate the median score on the homework assignments for the semester. He believes that the...

  • Question 1 An array is NOT: A - Made up of different data types. B - Subscripted by integers. C -...

    Question 1 An array is NOT: A - Made up of different data types. B - Subscripted by integers. C - A consecutive group of memory chunks. D - None of the choices. Question 2 How many times is the body of the loop executed? int i=1; while(true) { cout << i; if(++i==5) break; } A - Forever B - 4 C - 5 D - 6 E - 0 Question 3 What is wrong with the following piece of...

  • python question Question 1 Write a Python program to play two games. The program should be...

    python question Question 1 Write a Python program to play two games. The program should be menu driven and should use different functions to play each game. Call the file containing your program fun games.py. Your program should include the following functions: • function guess The Number which implements the number guessing game. This game is played against the computer and outputs the result of the game (win/lose) as well as number of guesses the user made to during the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT