frustrated stupid newbie question
Scott Kurland
skurland at juggler.net
Tue Mar 12 22:07:33 EST 2002
> > > > Why isn't this $%^*#$% program working?
> > >
> > > > #Searching for perfect numbers
> > > >
> > > > howhigh= input ("How high should I check?")
> > > > for number in range (1,howhigh):
> > > > factorsum = 0
> > > > halfnumber=number/2
> > > > for checking in range (1,halfnumber):
> > > > if number/checking == int (number/checking):
> > > > factorsum = factorsum + checking
> > > > if number == factorsum:
> > > > print number
> > > >
> > >
> > > What do you mean it isn't working? It ran without crashing when I
tried
> > it.
> > > Here is the output from a sample run:
> > >
> > > >>>
> > > How high should I check?50
> > > 10
> > >
> > > Are you expecting some other type of output? What are you expecting?
> >
> > Well, I was expecting failure, which we got. What I hoped for was the
two
> > perfect numbers between 1 and 50, 6 and 28.
>
> You really should play with the interpreter window open, or add more print
> statements to your code so that you can see what is happening at all of
the
> intermediate steps. Consider the data in this interactive session:
The former didn't help. I'll try the latter. Thank you.
>
> >>> howhigh = 10
> >>> range(1,howhigh)
> [1, 2, 3, 4, 5, 6, 7, 8, 9]
> >>> range(1, howhigh + 1)
> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
> >>> for number in range(1, howhigh + 1):
> print "for number = ", number,
> print "halfnumber = ", number/2
>
>
> for number = 1 halfnumber = 0
> for number = 2 halfnumber = 1
> for number = 3 halfnumber = 1
> for number = 4 halfnumber = 2
> for number = 5 halfnumber = 2
> for number = 6 halfnumber = 3
> for number = 7 halfnumber = 3
> for number = 8 halfnumber = 4
> for number = 9 halfnumber = 4
> for number = 10 halfnumber = 5
> >>>
>
> Is this what you expect of the data in the intermediate steps?
Nope, I was hoping for .5, 1, 1.5....
>
> > > > Flame away, I can't feel dumber than this.
> > >
> > > Oh, now what newsgroup mistreated you so, that you would expect such a
> > > thing? We don't do that here in comp.lang.python!
>
> > Goodness! I'll have to mind my manners carefully, then; usenet has
roughened
> > them some.
> >
> > Thank you, Sheila.
>
> Are you saying, that we need to watch out for flames from you???
> Oh, dear!
> (donning my asbestos suit...)
No, no, I'll do my best to be a Good Boy, honest.
More information about the Python-list
mailing list