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...

  • urgent help with python. can somone code this please and show output QUESTION: There are a variety of games possi...

    urgent help with python. can somone code this please and show output QUESTION: There are a variety of games possible with a deck of cards. A deck of cards has four different suits, i.e. spades (*), clubs (*), diamonds (), hearts (), and thirteen values for each suit. Now write a function that uses list comprehension to create a deck of cards. Each element in the list will be a card, which is represented by a list containing the suit...

  • Encoding and Decoding PPM image 3 & 4 are parts of question 2 Code for a09q1:...

    Encoding and Decoding PPM image 3 & 4 are parts of question 2 Code for a09q1: We were unable to transcribe this image3 Encoding an Image in a09q2.py In the next four sections, you will no longer write class methods but rather functions. In each of the next four parts, you should be importing the PPM class from a09q1.py to use with the command from a09q1 import PPM Note that this is similar to how the check module was imported...

  • # Please use Python to do this question. # import turtle to do this question. Write...

    # Please use Python to do this question. # import turtle to do this question. Write a function, grade_histogram(t,mu,sigma,n), which uses the turtle module to make a histogram for quiz score data for n = 100 students.   First, create the data using gauss(mu,sigma), from the random module. mu is the average and sigma is the standard deviation of the scores and is a measure of the spread of the data scores. When the quiz data is generated, check to make...

  • 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...

  • Please answer this question using python programming only and provide a screen short for this code....

    Please answer this question using python programming only and provide a screen short for this code. Homework 3 - Multiples not less than a number Question 1 (out of 3) This homework is a SOLO assignment. While generally I encourage you to help one another to learn the material, you may only submit code that you have composed and that you understand. Use this template to write a Python 3 program that calculates the nearest multiple of a number that...

  • 12p I need help this is Python EXCEPTIONS: It's easier to ask forgiveness than permission. Try...

    12p I need help this is Python EXCEPTIONS: It's easier to ask forgiveness than permission. Try the code and catch the errors. The other paradigm is 'Look before you leap' which means test conditions to avoid errors. This can cause race conditions. 1.Write the output of the code here: class MyError(Exception): pass def notZero(num): if num == 0: raise MyError def run(f): try: exec(f) except TypeError: print("Wrong type, Programmer error") except ValueError: print("We value only integers.") except Zero Division Error:...

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
ADVERTISEMENT