Write a program to monitor the price of shares in your latest technology start up.
Your program should read in a sequence of floats all on one line, and if the share price decreases without ever increasing in the sequence, your program should output Crashed!, like this:
Prices: 5.0 4.8 3.2 2.0
Crashed!
or this:
Prices: 1.0 0.7 0.7 0.7 0.1
Crashed!
If the share price remains constant, or if it goes up and down, your program should output Everything is OK.:
Prices: 3.0 4.5 2.0 1.0
Everything is OK.
and for this case too:
Prices: 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
Everything is OK.
This is what i have gotten so far what is wrong with it?
price=raw_input("Prices:")
list=price.split()
i=0
test=1
a=1
octopus=5
while i <(len(list)-1):
if float(list[i]) > float(list[i+1]):
a=0
elif float(list[i]) == float(list[i + 1]):
octopus=1
else:
c = 1
break
i = i + 1
if a ==0:
print "Crashed!"
else:
print "Everything is OK."
The error i received was the following by a automatic tester:
Test cases:
testing the first example in the question: passed
testing the second example in the question: passed
testing the third example in the question: passed
testing the fourth example in the question: passed
testing a case with a strictly decreasing sequence: passed
testing a case with a strictly increasing sequence: passed
testing a case where the share price remains constant (and is over 9000!): passed
testing a case where the share price decreases and then increases: failed
Your submission output
Prices:10.0 8.5 8.6
Crashed!
when it was meant to output
Prices: 10.0 8.5 8.6
Everything is OK.


Sign In
Create Account

Back to top









