Question

Question 4a (2 points): Finding Edge Cases I This program is a partially correct solution to the winning streak problem from a previous lab. Given a string, list, or tuple as input, find the longest winning streak. This solution contains an error. Find a test case that returns an incorrect value, or raises an error Do not modify or try to correct the code for this question, simply find a problematic input for the function # Modify the value of this variable so that winningstreakBad produces incorrect PROBLEM_INPUT1 # Do not modify the code below this line def winningStreakBad(s): if type(s) not in (tuple, list, str): return 0 if len(s)0: returne wins 1 maxwins = 1 for i in range(1en(s)): if s[i] s[14]: == wins 1 else: wins 1 if wins maxwins: maxwins wins return maxwins ## This is what the autograder will see winningStreakBad(PROBLEM INPUT1) Question 4b (2 points): Finding Edge Cases ll The code below tries to solve the linear system Find an input (A, B, C, D) that produces incorrect results. For the purposes of this question, False is considered a correst result for non-numeric inputs (strings, lists, etc.) # Modify these values so that solveLinearBad does not produce correct results # Do not modify the code below this line def solvelinearBad(a, b, c, d): for i in [a, b, c, d]: if type(i) not in (int, float): return False x(b d) / (c - a) return x ## This is what the autograder will see : solveLinearBad(A, B, C, D) # Hidden test cell for 4b

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

(4a)

The below code produces the output 2, whereas the expected output is 1. Hence, when PROBLEM_INPUT is set to the string "W", the code produces incorrect output.

Code Screenshots:

#Modify the value of this variable so that winningStreakBad incorrect output. у PROBLEM INPUT1 - #Do not modi fy the code b

Sample Output:

>>winningStreakBad (PROBLEM INPUTi) 2

Code To Copy:

#Modify the value of this variable so that winningStreakBad incorrect output.

PROBLEM_INPUT1 = "W"

#Do not modify the code below this line.

def winningStreakBad(s):

    if type(s) not in (tuple, list, str):

        return 0

    if len(s) == 0:

        return 0

    wins = 1

    maxwins = 1

    for i in range(len(s)):

        if s[i] == s[i-1]:

            wins += 1

       

        else:

            wins = 1

        if wins > maxwins:

            maxwins = wins

    return maxwins

(4b)

The below code generates an error as the Division By Zero isn't being handled in the code.

Code Screenshots:

# Modify these values so that solveLinearBad does not produce correct results A = 5 1 B = C = 5 D = 3 #Do not modify the code

Sample Output:

>>solveLinearBad (A, B, C, D) Traceback (most recent call last) : File <pyshell#10>, line 1, in <module> solveLinearBad (A,

Code To Copy:

# Modify these values so that solveLinearBad does not produce correct results.

A = 5

B = 1

C = 5

D = 3

#Do not modify the code below this line.

def solveLinearBad(a, b, c, d):

    for i in [a, b, c, d]:

        if type(i) not in (int, float):

            return False

   

    x = (b - d) / (c - a)

    return x

Add a comment
Know the answer?
Add Answer to:
Question 4a (2 points): Finding Edge Cases I This program is a partially correct solution to...
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
  • 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...

  • In python, write the following program, high school question, please keep simple. When I submitted the...

    In python, write the following program, high school question, please keep simple. When I submitted the solution, I get an error as 'wrong answer'. Please note below the question and then the solution with compiler errors. 7.2 Code Practice: Question 2 Instructions Write a program to generate passwords. The program should ask the user for a phrase and number, and then create the password based on our special algorithm. The algorithm to create the password is as follows: If the...

  • Help! i can't get the correct output for this question: Write a program that will read...

    Help! i can't get the correct output for this question: Write a program that will read in an integer from the user and test to see whether or not it is prime. You are to determine if each integer read is prime or not, and output the result to the screen as shown below. If a number is prime, your output should read: 101 = 1 x 101 101: PRIME Number For a number that turns out not to be...

  • // READ BEFORE YOU START: // You are given a partially completed program that creates a...

    // READ BEFORE YOU START: // You are given a partially completed program that creates a list of students for a school. // Each student has the corresponding information: name, gender, class, standard, and roll_number. // To begin, you should trace through the given code and understand how it works. // Please read the instructions above each required function and follow the directions carefully. // If you modify any of the given code, the return types, or the parameters, you...

  • Question 2: Levenshtein Take the recursive Java program Levenshtein.java and convert it to the equivalent C...

    Question 2: Levenshtein Take the recursive Java program Levenshtein.java and convert it to the equivalent C program. Tip: You have explicit permission to copy/paste the main method for this question, replacing instances of System.out.println with printf, where appropriate. Notes You can get the assert function from assert.h. Try running the Java program on the CS macOS machines. You can compile and run the program following the instructions provided in assignment 0. Assertions are disabled by default. You can enable assertions...

  • Hello! I'm posting this program that is partially completed if someone can help me out, I...

    Hello! I'm posting this program that is partially completed if someone can help me out, I will give you a good rating! Thanks, // You are given a partially completed program that creates a list of employees, like employees' record. // Each record has this information: employee's name, supervisors's name, department of the employee, room number. // The struct 'employeeRecord' holds information of one employee. Department is enum type. // An array of structs called 'list' is made to hold...

  • What is the role of polymorphism? Question options: Polymorphism allows a programmer to manipulate objects that...

    What is the role of polymorphism? Question options: Polymorphism allows a programmer to manipulate objects that share a set of tasks, even though the tasks are executed in different ways. Polymorphism allows a programmer to use a subclass object in place of a superclass object. Polymorphism allows a subclass to override a superclass method by providing a completely new implementation. Polymorphism allows a subclass to extend a superclass method by performing the superclass task plus some additional work. Assume that...

  • So I am creating a 10 question quiz in Microsoft Visual Studio 2017 (C#) and I...

    So I am creating a 10 question quiz in Microsoft Visual Studio 2017 (C#) and I need help editing my code. I want my quiz to clear the screen after each question. It should do one question at a time and then give a retry of each question that was wrong. The right answer should appear if the retry is wrong. After the 1 retry of each question, a grade should appear. Please note and explain the changes you make...

  • PYTHON 3 node Node ADT Question. Question 3 (18 points): Purpose: To practice working with node chains created using...

    PYTHON 3 node Node ADT Question. Question 3 (18 points): Purpose: To practice working with node chains created using the Node ADT to implement slightly harder functionality Degree of Difficulty: Moderate to Tricky In this question you'll implement merge sort for node chains! Recall, merge sort is a divide-and-conquer technique that uses recursion to sort a given sequence (in this case a node chain). A overview of the algorithm is given below. Algorithm mergeSort (NC) Borts node chain NC using...

  • **TStack.py below** # CMPT 145: Linear ADTs # Defines the Stack ADT # # A stack (also called a pushdown or LIFO stack)...

    **TStack.py below** # CMPT 145: Linear ADTs # Defines the Stack ADT # # A stack (also called a pushdown or LIFO stack) is a compound # data structure in which the data values are ordered according # to the LIFO (last-in first-out) protocol. # # Implementation: # This implementation was designed to point out when ADT operations are # used incorrectly. def create(): """ Purpose creates an empty stack Return an empty stack """ return '__Stack__',list() def is_empty(stack): """...

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