RE: genNum function in Python was: Python question

  • From: "edward" <personal.edward@xxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Fri, 27 Nov 2009 10:53:55 -0500

Hello 

Here is the code I have.

I basicly want to print stars instead of numbers.
star='star'
n=5
for i in range(1,n+1):
        print range(1,i+1)*star 

-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Richard Dinger
Sent: Tuesday, November 24, 2009 2:37 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: Re: genNum function in Python was: Python question

You still have not described what your approach is and now you are showing
new requirements to display a series of stars.

Your code is:
> N=5
> For I in n:
the above line will not work it has an error n is not an iterable.  So you
should probably really want:
for i in range(1, n+1)
> print range(1,i)
the above should probably be:
print range(1, i+1)

> Output should be
> 1
> 12
...
> 12345
not true as the output of the range function is a list so the output would
be:
[1]
[1, 2]
...
[1, 2, 3, 4, 5]

And then you note in your previous message what you really want is:
*
**
...
*****

How do you plan to get from lists of numbers to strings of stars?

I think you should first sit back and think about your approach to the
problem.  Begin by describing what you want as output:
1 a list of something?
2. a series of printed outputs?
3. something else?

It is always best to know where you are going before you try to pack for the
trip.  After all, if you plan on going to Hawaii, you will want your
swimsuit not your winter coat.

Richard

----- Original Message -----
From: "edward" <personal.edward@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Tuesday, November 24, 2009 8:24 AM
Subject: RE: genNum function in Python was: Python question


> Hello
> Ok code:
> N=5
> For I in n:
> print range(1,i)
> Output should be
> 1
> 12
> 123
> 1234
> 12345
> Now I want to use the char "*" instead of numbers.
> Meaning I want to return
> *
> **
> ***
> ****
> *****
> Edward
>
>
> -----Original Message-----
> From: programmingblind-bounce@xxxxxxxxxxxxx
> [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Richard Dinger
> Sent: Tuesday, November 24, 2009 11:16 AM
> To: programmingblind@xxxxxxxxxxxxx
> Subject: genNum function in Python was: Python question
>
> Edward,
>
> You have some mistakes in your code.  This is a simple assignment and can 
> be
> solved several ways, but I am not certain what your approach is here.  Can
> you explain in simple terms what approach you are trying to take?
>
> If I know how you are trying to solve this problem, maybe I can help you
> figure it out.  I suggest that you first look closely at how the range
> function works.  Start by running:
>
>>>> help(range)
>
> in the interactive shell in order to see what options you have with range.
>
> Richard
> ----- Original Message -----
> From: "edward" <personal.edward@xxxxxxxxx>
> To: <programmingblind@xxxxxxxxxxxxx>
> Sent: Monday, November 23, 2009 7:21 PM
> Subject: RE: Python question
>
>
>> Hello
>> Thanks for your help. I have another question.
>> This code is supposed to take an integer, n and print it like the below.
>> Int is 5
>> 1
>> 12
>> 123
>> 1234
>> 12345
>> Here is my very wrong code.
>>
>> def genNum(n):
>> mat=[]
>> i=1
>> for i in range(n):
>> mat.append(range(i))
>> return mat
>>
>> -----O 

__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: