Python Forum
Array to get profit (school assignment)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Array to get profit (school assignment)
#1
I've got an assignment to do, can someone help me out? I don't have a clue what to do.

The bitcoin is a digital currency whose value can go up and down considerably.
From an acquaintance with predictive gifts you get the value of the bitcoin in euros for the next N days.
You can now try to make as much profit as possible in that period.

The following applies:
  •  At the beginning you do not have a bitcoin. At the end of the period you do not have a bitcoin.
     You may never have more than one bitcoin at a time.
     Every day of the period you can buy a bitcoin if you do not own one, or sell the bitcoin that you own.

The aim is to make as much profit as possible at the end of the period.
Your program reads the number N from a standard input first. Then your program reads N lines, each with a number W, which indicates the value of the bitcoin on the relevant day.
Your program writes to standard output one line with the maximum profit you can
pick up in these N days. That could possibly be 0; you do not have to make a purchase.

Example
Input:
10
5
11
4
2
8
10
7
4
3
6
Output:
17


A time limit of 2 seconds applies to the program.

Preconditions: In eight out of ten test cases, 1 <N <100 applies. In one test case, N = 2000 and in one test case N = 100000 applies. For every number W 0 <W <100 applies.

this is what i have now:
length = int(raw_input())
list = []
for x in range(0, length):
	list.append(raw_input())
minm = []
maxm = []
i=0

while i < length-1:
    if i < length - 1:
        while i < length-1 and y[i+1] >= y[i]:
            i+=1

        if i != 0 and i < length-1:
            maxm = np.append(maxm,i)

        i+=1

    if i < length - 1:
        while i < length-1 and y[i+1] <= y[i]:
            i+=1

        if i < length-1:
            minm = np.append(minm,i)
        i+=1


print minm
print maxm

print(lijst)
Reply
#2
A better way to enter a list is:
mylist = [ ]

while True:
    item = raw_input("Enter a value, or type 'quit' to end: ")
    if item == 'quit':
        break
    mylist.append(item)
don't use pythoh types as variable names, naming your list 'list' is a no no!
Reply
#3
Do not send PM asking for help.
That is what the forum is for.
Any questions you have can be answered here!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Lab Assignment with Array's & Loops jonstryder 14 6,059 Aug-08-2019, 07:38 PM
Last Post: jonstryder
  Need help with a tough school assignment datson79 5 3,389 Feb-18-2019, 06:01 PM
Last Post: ichabod801
  School Work Assignment: Snake Game DarksideMoses 6 5,133 Apr-29-2018, 10:56 PM
Last Post: DarksideMoses
  School assignment Ronaldo 5 9,078 Jan-08-2017, 11:57 AM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020