Question

In Python. #1. please write a function called "stocksell", #2. the input parameters are the price...

In Python.

#1. please write a function called "stocksell",
#2. the input parameters are the price list (l) and the ith day,i from [0, 7],
#3. the return value is the jth day you should sell to make the most profit,
#4. print the profit

#for example a = stocksell(l, 2) then a = 6
#(2nd day price is 32, selling day is 6th day, price is 35)


l = [34,47,32, 28, 29, 31, 35,34]

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def stocksell(prices, day):
    max_index = day + 1
    for i in range(day + 1, len(prices)):
        if prices[i] > prices[max_index]:
            max_index = i
    return max_index


# Testing the function here. ignore/remove the code below if not required
l = [34, 47, 32, 28, 29, 31, 35, 34]
print(stocksell(l, 2))

Add a comment
Know the answer?
Add Answer to:
In Python. #1. please write a function called "stocksell", #2. the input parameters are the price...
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
  • Write a python function called "get_sma", that takes two input arguments, similar to the example provided....

    Write a python function called "get_sma", that takes two input arguments, similar to the example provided. First argument is the original prices of type list, and the 2nd input argument being the number of days we want to calculate SMA, like a 8 day sma or 35 day sma. This function should return a new list of sma price, based on the input day range, and should be able to handle any SMA calculation, like: sma200 for 200 days moving...

  • l Question 2 -JS and Python a) Write JavaScript code to create a function called "sortstingsDesc"...

    l Question 2 -JS and Python a) Write JavaScript code to create a function called "sortstingsDesc" that will sort an array of string suppiied as a parameter in descending order. (4) Write Python code to create a function called "addToFront" that will accept two parameters the list of information and the value to be added and place the value to the beginning of the list. [4) b)

  • Python 3 code Write a function named coinflip that accepts an input called flips. The function...

    Python 3 code Write a function named coinflip that accepts an input called flips. The function should sim-ulate flipping a coin flips times. The function should return True if the coin was the same result for every flip. You can assume the function receives a positive integer as input. Write a second function named simulation that runs trials of the coin flip experiment. simulation should accept two parameters: the number of trials, and the number of coin flips to do...

  • Python: Using chr() and ord() write a function called en_crypt() that takes into input a string...

    Python: Using chr() and ord() write a function called en_crypt() that takes into input a string and returns a new encrypted version of the input string. Example: "atwOta@0202" should return "fy|TyfE5757", then write a function de_crypt() so that "fy|TyfE5757" returns "atwOta@0202"

  • python Days of the Week Function Name: days_of_the_week() Parameters: list of birthdays ( list ), year...

    python Days of the Week Function Name: days_of_the_week() Parameters: list of birthdays ( list ), year (int ) Returns: list of names ( list ) Description: You and your friends all want to celebrate your birthdays together, but you don't want to stay up late on a school night. Write a function that takes in a list of tuples formatted as (day ( int ), month ( int ), name (string)), and a year ( int ). Use Python's calendar...

  • Python Question? Write a function called reverse(user_list, num = -1) that takes a list and a...

    Python Question? Write a function called reverse(user_list, num = -1) that takes a list and a number as parameters. The function returns a copy of the list with the first number of items reversed. Conditions: The number parameter must be a default argument. -      If the default argument for number is given in the function call, only the first number of items are reversed. -      If the default argument for number is not provided in the function call, then the...

  • USING C++ and PYTHON Please Help me: 1. Write a function that takes in an array...

    USING C++ and PYTHON Please Help me: 1. Write a function that takes in an array of integers (and the size of the array in the C/C++ version). The function will reverse the array of integers and return the reversed array. Print the array that is returned from the function. How you "return" the array is up to you, but do not overwrite the original array. Note: in Python, the term list is more appropriate, see https://docs.python.org/3.5/tutorial/datastructures.html a) Example input:...

  • 1. use python List to Dictionary Write a function that has three parameters: a list of...

    1. use python List to Dictionary Write a function that has three parameters: a list of unsorted numbers with no duplicates, a start number, and an end number. This function should return a dictionary with all integers between the start and end number (inclusive) as the keys and their respective indices in the list as the value. If the integer is not in the list, the corresponding value would be None. Example unsorted list: [2,1,10,0,4,3] two numbers: 3, 10 returned...

  • pYTHON Exercise: create01 Description Write a function that receives no parameters and returns a Pencil object...

    pYTHON Exercise: create01 Description Write a function that receives no parameters and returns a Pencil object constructed with 3 leads. Function Name create01 Parameters • None Return Value A Pencil object with 3 leads. Example р create01() print(p.get_num_leads()) # -> 3 print(p.get_current_lead_length()) # > 10 Hints • Don't forget to import Pencil.

  • Lab 1 Q1. Write a Python program with the following function building block. •All input values...

    Lab 1 Q1. Write a Python program with the following function building block. •All input values are to be taken fro m the user. •Ensure to check for possible error cases like mismatch of data type and input out of range, for every function.       Function 1: countVowels(sentence) – Function that returns the count of vowels in a sentence. Function 2: Sum of all even numbers between two numbers, identify number of parameters   Q2. Write a Python program that reads a...

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