[Tutor] Finding a nearest perfect cube

2013-11-07 Thread donsuni
Hi, I am new to python and i have to write a following code without using any
inbuilt function or a for loop. Only while and if loops are allowed.

If i input a number, i should get a perfect cube nearest to it.
For eg: if 
input=4, output=8
input=8, output=27
and so on
can some one help with the code?



--
View this message in context: 
http://python.6.x6.nabble.com/Finding-a-nearest-perfect-cube-tp5038336.html
Sent from the Python - tutor mailing list archive at Nabble.com.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] sequence of elements problem

2013-11-08 Thread donsuni
Hi, I have a problem in python which is kind of tricky.

if i give a sequence of numbers, i should get another sequence of numbers
such that the the elements exceeds previous element in the list. For eg

seq_num([3,2,5,7])=[3,5,7] since 5 is >3, and 7>5
seq_num([1,2,3,4])=[1,2,3,4]  since 2 is >1, and 3>2 and so on
seq_num([5,5,5])=[5]
seq_num([9,8,7])=[9]

and so on without using any inbuilt functions.

I tried the following code but it is not incrementing:

def seq_num(numlist):

n=len(numlist)
   
for i in range(0,n - 1):
   
if numlist[i]>numlist[i+1]:
i+=1
return numlist[i]



--
View this message in context: 
http://python.6.x6.nabble.com/sequence-of-elements-problem-tp5038402.html
Sent from the Python - tutor mailing list archive at Nabble.com.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor