Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #78653 > unrolled thread

Python Basics

Started bydiarmuid.higgins@mycit.ie
First post2014-10-03 10:35 -0700
Last post2014-10-03 19:13 -0400
Articles 16 — 8 participants

Back to article view | Back to comp.lang.python


Contents

  Python Basics diarmuid.higgins@mycit.ie - 2014-10-03 10:35 -0700
    Re: Python Basics Chris Angelico <rosuav@gmail.com> - 2014-10-04 03:42 +1000
      Re: Python Basics diarmuid.higgins@mycit.ie - 2014-10-03 10:44 -0700
        Re: Python Basics Chris Angelico <rosuav@gmail.com> - 2014-10-04 03:47 +1000
          Re: Python Basics diarmuid.higgins@mycit.ie - 2014-10-03 10:54 -0700
            Re: Python Basics Chris Angelico <rosuav@gmail.com> - 2014-10-04 04:04 +1000
            Re: Python Basics Tobiah <toby@tobiah.org> - 2014-10-03 11:34 -0700
    Re: Python Basics Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-03 18:54 -0400
      Re: Python Basics Chris Angelico <rosuav@gmail.com> - 2014-10-04 09:05 +1000
        Re: Python Basics Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-04 11:09 +1000
          Re: Python Basics Chris Angelico <rosuav@gmail.com> - 2014-10-04 12:24 +1000
          Re: Python Basics alister <alister.nospam.ware@ntlworld.com> - 2014-10-04 09:10 +0000
          Re: Python Basics Peter Pearson <pkpearson@nowhere.invalid> - 2014-10-04 17:42 +0000
        Re: Python Basics Tobiah <toby@tobiah.org> - 2014-10-09 11:26 -0700
          Re: Python Basics Chris Angelico <rosuav@gmail.com> - 2014-10-10 08:38 +1100
    Re:Python Basics Dave Angel <davea@davea.name> - 2014-10-03 19:13 -0400

#78653 — Python Basics

Fromdiarmuid.higgins@mycit.ie
Date2014-10-03 10:35 -0700
SubjectPython Basics
Message-ID<3c9504c9-6906-4358-b14c-5764bba70a65@googlegroups.com>
Hi

I have just started an introductory course on Python. I have never even seen a programming language before so I am struggling a bit. Our lecturer has given us a number of excercises to complete and I am stuck on the one I have listed below. Please help 

Q2. Implement a function called printNumTriangle. The function should ask the user to enter a single integer. It should then print a triangle of that size specified by the integer so that each row in the triangle is made up of the integer displayed. 

The following is a sample output

Please enter an integer for triangle size:
1
22
333
4444
55555

[toc] | [next] | [standalone]


#78654

FromChris Angelico <rosuav@gmail.com>
Date2014-10-04 03:42 +1000
Message-ID<mailman.14577.1412358154.18130.python-list@python.org>
In reply to#78653
On Sat, Oct 4, 2014 at 3:35 AM,  <diarmuid.higgins@mycit.ie> wrote:
> Our lecturer has given us a number of excercises to complete and I am stuck on the one I have listed below. Please help

Sure! Show us the code you have so far, and explain what it is you're
stuck on. Then we can help you. But we're not going to write the code
for you.

ChrisA

[toc] | [prev] | [next] | [standalone]


#78655

Fromdiarmuid.higgins@mycit.ie
Date2014-10-03 10:44 -0700
Message-ID<2c198e3c-ddee-47a9-b744-a35c726cdfd2@googlegroups.com>
In reply to#78654
def printNumTriangle():
   num = input("Please enter an integer for triangle size:")
   for i in range(1,num+1):
      for j in range (i):
         print i

Cheers!!!!


On Friday, October 3, 2014 6:42:46 PM UTC+1, Chris Angelico wrote:
> On Sat, Oct 4, 2014 at 3:35 AM,  <diarmuid.higgins@mycit.ie> wrote:
> 
> > Our lecturer has given us a number of excercises to complete and I am stuck on the one I have listed below. Please help
> 
> 
> 
> Sure! Show us the code you have so far, and explain what it is you're
> 
> stuck on. Then we can help you. But we're not going to write the code
> 
> for you.
> 
> 
> 
> ChrisA

[toc] | [prev] | [next] | [standalone]


#78656

FromChris Angelico <rosuav@gmail.com>
Date2014-10-04 03:47 +1000
Message-ID<mailman.14578.1412358462.18130.python-list@python.org>
In reply to#78655
On Sat, Oct 4, 2014 at 3:44 AM,  <diarmuid.higgins@mycit.ie> wrote:
> def printNumTriangle():
>    num = input("Please enter an integer for triangle size:")
>    for i in range(1,num+1):
>       for j in range (i):
>          print i
>
> Cheers!!!!

Okay! You're very close, and I can see what's going on there. But I'd
like you to learn how to ask questions, as well as how to write Python
code, because both skills are important to your future. :) So I'm
going to get you to take another step in asking the question: What is
it that your code isn't doing right?

ChrisA

[toc] | [prev] | [next] | [standalone]


#78657

Fromdiarmuid.higgins@mycit.ie
Date2014-10-03 10:54 -0700
Message-ID<f6b134d6-892f-4672-92cc-69298b3fabda@googlegroups.com>
In reply to#78656
On Friday, October 3, 2014 6:47:54 PM UTC+1, Chris Angelico wrote:
> On Sat, Oct 4, 2014 at 3:44 AM,  <diarmuid.higgins@mycit.ie> wrote:
> 
> > def printNumTriangle():
> 
> >    num = input("Please enter an integer for triangle size:")
> 
> >    for i in range(1,num+1):
> 
> >       for j in range (i):
> 
> >          print i
> 
> >
> 
> > Cheers!!!!
> 
> 
> 
> Okay! You're very close, and I can see what's going on there. But I'd
> 
> like you to learn how to ask questions, as well as how to write Python
> 
> code, because both skills are important to your future. :) So I'm
> 
> going to get you to take another step in asking the question: What is
> 
> it that your code isn't doing right?
> 
> 
> 
> ChrisA

Hi Chris
I can't get the code to display the output as it should.
I can get it to display like this:
122333444455555 or I can get it to display like this:
1
2
2
3
3
3
4
4
4
4
5
5
5
5
5
but not as has been asked in the question.
Cheers
Diarmuid

[toc] | [prev] | [next] | [standalone]


#78658

FromChris Angelico <rosuav@gmail.com>
Date2014-10-04 04:04 +1000
Message-ID<mailman.14579.1412359482.18130.python-list@python.org>
In reply to#78657
On Sat, Oct 4, 2014 at 3:54 AM,  <diarmuid.higgins@mycit.ie> wrote:
> Hi Chris
> I can't get the code to display the output as it should.
> I can get it to display like this:
> 122333444455555 or I can get it to display like this:
> 1
> 2
> 2
> 3
> 3
> 3
> 4
> 4
> 4
> 4
> 5
> 5
> 5
> 5
> 5
> but not as has been asked in the question.

Good! (It would help if you explained how you had the two different
versions, incidentally.) What you need is like the first version, only
you want to break the lines every time the digit changes. That can be
done pretty easily. All you need to do is print out nothing, followed
by end-of-line; and you need to do this in such a way that it happens
after all of one digit has been displayed, but before the next one is.
Can you do that?

Side point: Google Groups makes a horrible mess of your posts. Please
consider switching to the mailing list, or to a better newsreader. You
can join the mailing list here:

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

Thanks!

ChrisA

[toc] | [prev] | [next] | [standalone]


#78659

FromTobiah <toby@tobiah.org>
Date2014-10-03 11:34 -0700
Message-ID<542EEC28.1010702@tobiah.org>
In reply to#78657
> Hi Chris
> I can't get the code to display the output as it should.
> I can get it to display like this:
> 122333444455555 or I can get it to display like this:
> 1
> 2
> 2
> 3
> 3
> 3
> 4
> 4
> 4
> 4
> 5
> 5
> 5
> 5
> 5
> but not as has been asked in the question.
> Cheers
> Diarmuid
>


Hint:

>>> 'a' * 4
'aaaa'

[toc] | [prev] | [next] | [standalone]


#78670

FromSeymore4Head <Seymore4Head@Hotmail.invalid>
Date2014-10-03 18:54 -0400
Message-ID<78au2a12nlq6nipske1a327p14dvgvakug@4ax.com>
In reply to#78653
On Fri, 3 Oct 2014 10:35:38 -0700 (PDT), diarmuid.higgins@mycit.ie
wrote:

>Hi
>
>I have just started an introductory course on Python. I have never even seen a programming language before so I am struggling a bit. Our lecturer has given us a number of excercises to complete and I am stuck on the one I have listed below. Please help 
>
>Q2. Implement a function called printNumTriangle. The function should ask the user to enter a single integer. It should then print a triangle of that size specified by the integer so that each row in the triangle is made up of the integer displayed. 
>
>The following is a sample output
>
>Please enter an integer for triangle size:
>1
>22
>333
>4444
>55555
for i in range(1,10):
    print (str(i)*i)

[toc] | [prev] | [next] | [standalone]


#78671

FromChris Angelico <rosuav@gmail.com>
Date2014-10-04 09:05 +1000
Message-ID<mailman.14588.1412377559.18130.python-list@python.org>
In reply to#78670
On Sat, Oct 4, 2014 at 8:54 AM, Seymore4Head
<Seymore4Head@hotmail.invalid> wrote:
>>Q2. Implement a function called printNumTriangle. The function should ask the user to enter a single integer. It should then print a triangle of that size specified by the integer so that each row in the triangle is made up of the integer displayed.
>>
>>The following is a sample output
>>
>>Please enter an integer for triangle size:
>>1
>>22
>>333
>>4444
>>55555
> for i in range(1,10):
>     print (str(i)*i)

Seymour, please don't do this. When you "help" someone by just giving
him the answer to a homework problem, you get him past his immediate
issue of "I need to submit my homework for this problem". That lets
him get through his course without understanding the code he's
creating (because he's not the one creating it). He'll either run into
more trouble before graduating the course, or (far worse) he'll
graduate successfully, without having the competence that the course
is supposed to teach - and the world will be given a qualified
programmer who doesn't know his stuff. That damages the world, damages
the reputation of the course, and gives python-list a reputation as a
homework assignment solver... none of which I want. I'm pretty sure
you don't want it either.

So don't do people's homework for them. PLEASE!!

ChrisA

[toc] | [prev] | [next] | [standalone]


#78675

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2014-10-04 11:09 +1000
Message-ID<542f48e7$0$13014$c3e8da3$5496439d@news.astraweb.com>
In reply to#78671
Chris Angelico wrote:

> On Sat, Oct 4, 2014 at 8:54 AM, Seymore4Head
> <Seymore4Head@hotmail.invalid> wrote:

>> for i in range(1,10):
>>     print (str(i)*i)
> 
> Seymour, please don't do this. When you "help" someone by just giving
> him the answer to a homework problem, you get him past his immediate
> issue of "I need to submit my homework for this problem". That lets
> him get through his course without understanding the code he's
> creating
[...]

In fairness to Seymour, at this extremely basic level, it's really hard to
explain to somebody how to solve a problem without giving them the answer.

While I don't condone mindless parroting of work that others have done,
remember that for tens of thousands of years, being shown how to do
something, then imitating that, has been the most effective way for people
to learn. Dropping hints is typically the least effective learning method.



-- 
Steven

[toc] | [prev] | [next] | [standalone]


#78678

FromChris Angelico <rosuav@gmail.com>
Date2014-10-04 12:24 +1000
Message-ID<mailman.14592.1412389462.18130.python-list@python.org>
In reply to#78675
On Sat, Oct 4, 2014 at 11:09 AM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> In fairness to Seymour, at this extremely basic level, it's really hard to
> explain to somebody how to solve a problem without giving them the answer.
>
> While I don't condone mindless parroting of work that others have done,
> remember that for tens of thousands of years, being shown how to do
> something, then imitating that, has been the most effective way for people
> to learn. Dropping hints is typically the least effective learning method.

Maybe. I'd still like to see the student's existing code before just
giving the answer. Providing code in response to the copy/pasted
problem definition invites the answer to be copy/pasted, which creates
the situation I described.

ChrisA

[toc] | [prev] | [next] | [standalone]


#78684

Fromalister <alister.nospam.ware@ntlworld.com>
Date2014-10-04 09:10 +0000
Message-ID<aQOXv.537891$AB3.189587@fx07.am4>
In reply to#78675
On Sat, 04 Oct 2014 11:09:58 +1000, Steven D'Aprano wrote:

> Chris Angelico wrote:
> 
>> On Sat, Oct 4, 2014 at 8:54 AM, Seymore4Head
>> <Seymore4Head@hotmail.invalid> wrote:
> 
>>> for i in range(1,10):
>>>     print (str(i)*i)
>> 
>> Seymour, please don't do this. When you "help" someone by just giving
>> him the answer to a homework problem, you get him past his immediate
>> issue of "I need to submit my homework for this problem". That lets him
>> get through his course without understanding the code he's creating
> [...]
> 
> In fairness to Seymour, at this extremely basic level, it's really hard
> to explain to somebody how to solve a problem without giving them the
> answer.
> 
> While I don't condone mindless parroting of work that others have done,
> remember that for tens of thousands of years, being shown how to do
> something, then imitating that, has been the most effective way for
> people to learn. Dropping hints is typically the least effective
> learning method.

I think Chris as demonstrated that you even at this basic level you can 
help without giving the answer, by asking a series of leading questions 
that result in the student providing the answer.




-- 
One possible reason that things aren't going according to plan
is that there never was a plan in the first place.

[toc] | [prev] | [next] | [standalone]


#78700

FromPeter Pearson <pkpearson@nowhere.invalid>
Date2014-10-04 17:42 +0000
Message-ID<c9apsgFp0ikU1@mid.individual.net>
In reply to#78675
On Sat, 04 Oct 2014 11:09:58 +1000, Steven D'Aprano wrote:
> Chris Angelico wrote:
>
>> On Sat, Oct 4, 2014 at 8:54 AM, Seymore4Head
>> <Seymore4Head@hotmail.invalid> wrote:
>
>>> for i in range(1,10):
>>>     print (str(i)*i)
>> 
>> Seymour, please don't do this. When you "help" someone by just giving
>> him the answer to a homework problem, you get him past his immediate
>> issue of "I need to submit my homework for this problem". That lets
>> him get through his course without understanding the code he's
>> creating
> [...]
>
> In fairness to Seymour, at this extremely basic level, it's really hard to
> explain to somebody how to solve a problem without giving them the answer.
>
> While I don't condone mindless parroting of work that others have done,
> remember that for tens of thousands of years, being shown how to do
> something, then imitating that, has been the most effective way for people
> to learn. Dropping hints is typically the least effective learning method.

This has gotta be the most civilised newsgroup on the Net.  Kudos to
you stalwarts who keep it that way.

Personally, I thought Tobiah's hint, printing 'a'*4, would be just
what the OP needed.

-- 
To email me, substitute nowhere->runbox, invalid->com.

[toc] | [prev] | [next] | [standalone]


#78907

FromTobiah <toby@tobiah.org>
Date2014-10-09 11:26 -0700
Message-ID<srAZv.410332$1s.99074@fx05.iad>
In reply to#78671
>> for i in range(1,10):
>>      print (str(i)*i)
>
> Seymour, please don't do this. When you "help" someone by just giving
> him the answer to a homework problem, you get him past his immediate
> issue of "I need to submit my homework for this problem". That lets
> him get through his course without understanding the code he's
> creating (because he's not the one creating it). He'll either run into
> more trouble before graduating the course, or (far worse) he'll
> graduate successfully, without having the competence that the course
> is supposed to teach - and the world will be given a qualified
> programmer who doesn't know his stuff. That damages the world, damages
> the reputation of the course, and gives python-list a reputation as a
> homework assignment solver... none of which I want. I'm pretty sure
> you don't want it either.
>
> So don't do people's homework for them. PLEASE!!

Wow.  How do you react when someone does something that's
actually harmful?  I don't think you'd have the words! :)


[toc] | [prev] | [next] | [standalone]


#78913

FromChris Angelico <rosuav@gmail.com>
Date2014-10-10 08:38 +1100
Message-ID<mailman.14728.1412890690.18130.python-list@python.org>
In reply to#78907
On Fri, Oct 10, 2014 at 5:26 AM, Tobiah <toby@tobiah.org> wrote:
>> So don't do people's homework for them. PLEASE!!
>
>
> Wow.  How do you react when someone does something that's
> actually harmful?  I don't think you'd have the words! :)

You just saw it. Doing someone's homework *is* harmful. Harms the
student, harms the course, harms the industry.

ChrisA

[toc] | [prev] | [next] | [standalone]


#78672

FromDave Angel <davea@davea.name>
Date2014-10-03 19:13 -0400
Message-ID<mailman.14589.1412377843.18130.python-list@python.org>
In reply to#78653
diarmuid.higgins@mycit.ie Wrote in message:
> Hi
> 
> I have just started an introductory course on Python. I have never even seen a programming language before so I am struggling a bit. Our lecturer has given us a number of excercises to complete and I am stuck on the one I have listed below. Please help 
> 

Which part are you having trouble with? 

> Q2. Implement a function called printNumTriangle.


A function definition starts with the keyword 'def'



-- 
DaveA

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web