Re: 3 random numbers

2019-01-15 Thread Alister via Python-list
On Tue, 15 Jan 2019 06:13:00 -0800, Gengyang Cai wrote:

> I managed to solve the problem and also another problem with different 3
> random numbers. But it wasn't a very good question in the first place, i
> admit 
> 
>
Indeed it is a poorly write exercise & I suspect it has been 
misinterpreted.

unless i am very much mistaken the tutor expects the program to pick the 
3 random numbers each time it is run, not the programmer  

-- 
We've picked COBOL as the language of choice.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 3 random numbers

2019-01-15 Thread Gengyang Cai
I managed to solve the problem and also another problem with different 3 random 
numbers. But it wasn't a very good question in the first place, i admit 



On Tuesday, January 15, 2019 at 9:55:00 PM UTC+8, Rick Johnson wrote:
> Gengyang Cai wrote:
> > Can anyone understand it and explain it to me please ? 
> 
> Instead of attempting to read source code that you obviously have no 
> qualification to read, why don't you try _thinking_ like a programmer? 
> 
> "But Rick! How will i think like a programmer if i cannot even read source 
> code?!"
> 
> Forget about reading source code, kid! Reading source code is only a small 
> part of being a programmer. Are you any less intelligent because you can't 
> speak every language on the freakin' planet including Klingon, Elvish and the 
> black tongue of the Mordor Orc? No. Of course not! You can still tie you 
> tennis shoes, yes? Okay... Thus, programming languages are like natural 
> language, in that they are merely a means to communicate. Tools. That's all. 
> So, if you can become competent with a rake, then you can probably do the 
> same with a shovel, and a hoe. All of these tools will help you build a 
> garden. Or bury a skeleton in the backyard -- after dark, when the nosy 
> neighbors are sleeping!
> 
> <_<
> 
> >_>
> 
> "Okay Rick... i sorta understand your point here, but... i'm not having that 
> ah-hah! moment. How do i think like a programmer?"
> 
> Simple! You look at a problem, and then you ask yourself: "What are the 
> fundamental steps required to solve this problem?" And sometimes scratching 
> the head helps...
> 
> ASSIGNMENT: "Pick any 3 random ascending numbers and write out a loop 
> function that prints out all 3 numbers"""
> 
> Looking at this sentence, i see two specific problems:
> 
> 
> 
> So, in the case of your assignment, the first step would be to pick three 
> numbers. 
> 
> STEP_1. Pick three numbers. 
> 
>numbers = [400, 467, 851]

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 3 random numbers

2019-01-14 Thread Cameron Simpson

On 14Jan2019 21:29, caig...@gmail.com  wrote:

So I was given this question to be solved in Python 3 : Pick any
3 random ascending numbers and write out a loop function that prints
out all 3 numbers. This was the code and solution presented to me.
Can anyone understand it and explain it to me please ? I have looked
at it but cannot see how it was derived and why the correct solution
was printed. Thanks alot !


Indentation is vital in Python; it is used to delineate the start and 
end of loops and control structures etc (where other languages might use 
curly braces). So because your pasted code has no indentation we must 
guess. I'm going to reindent to express what I'm guessing:


   # any 3 ascending numbers , counter must start at 0.
   # 400 467 851
   i = 0
   x = 400
   while x < 852:
 print(x)
 if i > 0:
   x = x + ((i + 4) * 67) + (i * 49)
 else:
   x = x + 67
 i = i + 1

The other thing is that I do not think you have described the problem 
correctly, or if that _is_ how it was expressed to you then it is a 
terrible terrible problem description.


All the code above does is (a) start "x" at 400, which is your first 
arbitrary value and (b) stop the loop when "x" >= 852, which _prevents_ 
it printing any numbers above your last arbitrary value (851).


The bit in the middle is just contrived.

The important things about the code seem to be:

"x" is always increased. This ensures that the loop will finish, because 
"x" starts below the limit (852) and always gets closer to it, and 
eventually exceeds it ==> loop exits.


The first pass through the loop when "x" == 0 just adds 67 to it, 
getting from 400 to 467, your second arbitrary number.


So this isn't some clever bit of code that does something to generate 3 
values, it is a loop that runs three times to get exactly the 3 values 
in your comment.


I suspect we're missing the larger picture here.

Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: 3 random numbers

2019-01-14 Thread Spencer Graves



On 2019-01-14 23:29, caig...@gmail.com wrote:

So I was given this question to be solved in Python 3 : Pick any 3 random 
ascending numbers and write out a loop function that prints out all 3 numbers. 
This was the code and solution presented to me. Can anyone understand it and 
explain it to me please ? I have looked at it but cannot see how it was derived 
and why the correct solution was printed. Thanks alot !

# any 3 ascending numbers , counter must start at 0.
# 400 467 851
i = 0
x = 400
while x < 852:
print(x)
if i > 0:
x = x + ((i + 4) * 67) + (i * 49)
else:
x = x + 67
i = i + 1



  This sounds like a homework problem for a class.  I don't know 
how this list treats such questions, but I suspect answering such 
questions may be discouraged.



  Hint:  Read the documentation on "while" and then trace the 
iterations.



      Spencer



--
https://mail.python.org/mailman/listinfo/python-list