Re: [Tutor] Can someone please help me with this?
On 7 November 2013 02:56, Alex Kleider wrote: > On 2013-11-06 01:52, Oscar Benjamin wrote: > >> >> I'll give one suggestion which is that to concatenate one list onto >> the end of another you would use the .extend() method rather than the >> .append() method. > > > What would be the advantage/disadvantage of what you suggest vs using the > plus (+) operand as in > l = l1 + l2 > ?? As Dave says l1 + l2 creates a new list. However l1 += l2 does the same as the extend method and mutates l1 in place. Oscar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Can someone please help me with this?
On 7 November 2013 13:28, Anton Gilb wrote: > > I don't know how to reach all of you that helped me out, but I just want to > extend a huge thank you! You guys are a big help and your time and input is > well appreciated! Hi Anton, you can reach everyone by sending your reply email to tutor@python.org (or just using reply-all) as I have for this email. I'm glad you appreciate the help. Oscar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Finding a nearest perfect cube
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
Re: [Tutor] Finding a nearest perfect cube
On Thu, Nov 7, 2013 at 2:25 PM, donsuni wrote: > 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? > You're about to get a deluge of responses just like this, but: We don't do people's homework for them. If you've made some effort and you're stuck, show us what you've done and a LOT of people will be happy to help. But doing it for you? Not so much. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Finding a nearest perfect cube
On 07/11/13 22:25, donsuni wrote: 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? We will help YOU write the code but we won't do it for you. So what have you got so far? If you don't have code do you know how to solve it in your mind? Can you write down the algorithm you would use to solve it? As for the restrictions, don't worry about them too much. Anything you can do with a for loop you can do with a while loop, just with a little more effort. The restriction on not using inbuilt functions is a bit more severe because you can't do a lot without using inbuilt functions, but I assume they mean that using things like +, -,*,etc is OK. As would be printing. BTW it also helps to know which Python version you are using (v2 or v3) and sometimes what OS you are running. Finally, some questions about the problem: The examples you give you always take the next cube up the scale, but inputting 8 should surely give 8 as an answer since 8 is a cube? And what if I input 9? Can I count back down to 8 or must I go upwards to the next cube? In which case it may not really be the "nearest" cube but the "next" cube. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Finding a nearest perfect cube
> > > 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 > Let's consider those examples. Pretend you were given: input = 4 and the description of the problem. Forget computers for a brief moment. What would YOU do do solve this problem? Why should I believe that "8" is an acceptable answer to this? This is one of the first steps to understanding the problem, to understand the sample inputs and outputs. If you find that those outputs make no sense, then you've got to stop right now: no amount of coding will help if you don't understand what you're trying to code. Same question to 'input = 8'. Why would "27" be an acceptable answer? In fact, I would argue that the expected answer here is wrong if we pay attention to the problem statement. 8 is a perfect cube, and 8 is closest to 8, as math.abs(8 - 8) == 0! So you must define what you mean by "closest". ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor