Re: Beginner Programmer Question

2006-06-26 Thread I V
On Mon, 26 Jun 2006 10:47:58 -0700, [EMAIL PROTECTED] wrote:
> whats the difference between raw input and input?

'input' is used to ask the user to input a python expression, which is
then run, and 'input' returns the result of executing that expression. For
example:


(define a function which prints something out)

>>> def func():
... print "You're calling a function"
... return "Function result"
...

(now, call input)

>>> res = input('Type python here: ')

(python outputs the prompt )

Type python here:

(and, if you type the python code to call a function after the prompt)

Type python here: func()

(then python calls the function, which prints out)

You're calling a function

(meanwhile, the result of calling the function gets assigned to 'res')

>>> print res
Function result

'raw_input' just returns whatever text the user typed in. That's what you
want to use here. 'raw_input' returns a string, which you'll need to
convert to a number with the 'int' function, like so:

text = raw_input('Type in a number: ')
number = int(text)




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


Re: Beginner Programmer Question

2006-06-26 Thread Terry Reedy

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>
> whats the difference between raw input and input?

*That* you should look up in the builtin functions section of chapter 1? of 
the library reference manual.  Chapter 2 of the same on builtin types is 
also important to skim and be able to refer back to.



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


Re: Beginner Programmer Question

2006-06-26 Thread [EMAIL PROTECTED]

Tim Chase wrote:
> > bigone = 100
> >
> > number = input("Whats the first number?")
> > number2 = input ("Whats the second number?")
> > nu3 = number+number2
> > while nu3 < bigone:
> > print ("Not there yet, next number please")
> >
> > print "Finally there!"
> >
> > thats what i thought maybe it was...but after the first two numbers it
> > just continually scrolls on the screen with finally there
>
> Gaak!  it's doing exactly what you told it to do! Bad program! :)
>
> Inside the loop it neither
> 1) gets further input from the user nor
> 2) reassigns/sums nu3
>
> Thus, neither of the elements of your condition (nu3 < bigone)
> change, so you're stuck in an infinite loop of printing "not
> there yet..."
>
> Here's some sample code that works and does about what you
> describe.  Tweak accordingly. :)
>
> total = 0
> target = 3600
> values = [
>  82, 69, 87, 83, 78, 65, 0, 89, 83, 85, 79, 76, 0, 83, 73,
>  72, 84, 0, 83, 65, 87, 0, 84, 79, 71, 0, 41, 0, 76, 76,
>  65, 0, 68, 78, 65, 0, 78, 79, 72, 84, 89, 80, 14, 71, 78,
>  65, 76, 14, 80, 77, 79, 67, 0, 78, 79, 0, 78, 79, 73, 84,
>  83, 69, 85, 81, 0, 75, 82, 79, 87, 69, 77, 79, 72, 0, 65,
>  0, 68, 69, 75, 83, 65, 0, 41
>  ]
>
> while total < target:
>  # still haven't found the value
>  value = values.pop() # so we get another number
>  print chr(value+32), #h have a little fun
>  total += value #accumulate our total
>  # and do it until we've accumlated more than target
> print "Hey...we're over %s" % target
>
>
> -tkc

I finally got it to work. Thanks all for the help. Im sure ill be back
with plenty more question!!!

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


Re: Beginner Programmer Question

2006-06-26 Thread Tim Chase
> bigone = 100
> 
> number = input("Whats the first number?")
> number2 = input ("Whats the second number?")
> nu3 = number+number2
> while nu3 < bigone:
> print ("Not there yet, next number please")
> 
> print "Finally there!"
> 
> thats what i thought maybe it was...but after the first two numbers it
> just continually scrolls on the screen with finally there

Gaak!  it's doing exactly what you told it to do! Bad program! :)

Inside the loop it neither
1) gets further input from the user nor
2) reassigns/sums nu3

Thus, neither of the elements of your condition (nu3 < bigone) 
change, so you're stuck in an infinite loop of printing "not 
there yet..."

Here's some sample code that works and does about what you 
describe.  Tweak accordingly. :)

total = 0
target = 3600
values = [
 82, 69, 87, 83, 78, 65, 0, 89, 83, 85, 79, 76, 0, 83, 73,
 72, 84, 0, 83, 65, 87, 0, 84, 79, 71, 0, 41, 0, 76, 76,
 65, 0, 68, 78, 65, 0, 78, 79, 72, 84, 89, 80, 14, 71, 78,
 65, 76, 14, 80, 77, 79, 67, 0, 78, 79, 0, 78, 79, 73, 84,
 83, 69, 85, 81, 0, 75, 82, 79, 87, 69, 77, 79, 72, 0, 65,
 0, 68, 69, 75, 83, 65, 0, 41
 ]

while total < target:
 # still haven't found the value
 value = values.pop() # so we get another number
 print chr(value+32), #h have a little fun
 total += value #accumulate our total
 # and do it until we've accumlated more than target
print "Hey...we're over %s" % target


-tkc




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


Re: Beginner Programmer Question

2006-06-26 Thread Michael Goettsche
[EMAIL PROTECTED] wrote:
> I am doing alot of reading and trying to teach myself how to program.
> I can not figure out how to make "Write a program that continually
> reads in numbers from the user and adds them together until the sum
> reaches 100." this work. If someone could show me the correct code so i
> can learn from that it would be much appreciated. Thanks
> 

sum = 0
while sum <= 100:
 number = int(raw_input("Enter a number\n"))
 sum = sum + number
print "Finally there"

As long as the sum is <= 100 the program asks for a number and adds it 
to the sum variable. If the variable is >= 100, it exits and outputs the 
string.

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


Re: Beginner Programmer Question

2006-06-26 Thread Claudio Grondi
[EMAIL PROTECTED] wrote:
> [EMAIL PROTECTED] wrote:
> 
>>Claudio Grondi wrote:
>>
>>>[EMAIL PROTECTED] wrote:
>>>
I am doing alot of reading and trying to teach myself how to program.
I can not figure out how to make "Write a program that continually
reads in numbers from the user and adds them together until the sum
reaches 100." this work. If someone could show me the correct code so i
can learn from that it would be much appreciated. Thanks

>>>
>>>Isn't it your homework?
>>>Why can't you figure it out?
>>>What have you tried?
>>>
>>>Claudio
>>
>>I am doing alot of reading, and the problem didnt come with an answer.
>>I dont understand how to get it to continually input numbers and add
>>all those together
> 
> 
> #Add up to 100 program
> 
> #What number are you adding up to?
> bigone = 100
> 
> number = input("Whats the first number?")
> number2 = input ("Whats the second number?")
> nu3 = number+number2
> while nu3 < bigone:
  # you are missing the input and building the sum here:
number3 = input ("Whats the next number?")
nu3 = nu3 + number3
> print ("Not there yet, next number please")
  # so nu3 gets never changed and your loop runs forever.
> 
> 
> print "Finally there!"
> 
> thats what i thought maybe it was...but after the first two numbers it
> just continually scrolls on the screen with finally there
Yes, because you have no input command in the loop and no sum changing 
the value of nu3.
But you should get scrolling with "Not there yet, next number please" 
not with "Finally there!" according to your code.

I suppose your next question will be what tutorial is the best for a 
newbie, so I suggest you start with:
   http://wiki.python.org/moin/BeginnersGuide

Claudio
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beginner Programmer Question

2006-06-26 Thread [EMAIL PROTECTED]

Rune Strand wrote:
> [EMAIL PROTECTED] wrote:
> > Rune Strand wrote:
> > > >
> > > > I am doing alot of reading, and the problem didnt come with an answer.
> > > > I dont understand how to get it to continually input numbers and add
> > > > all those together
> > >
> > > Use while, raw_input, sys.argv[1] and int() and break the loop when the
> > > sum is above 100.
> > >
> > > ;-)
> >
> > thanks for the help..but i am extremley new and what you said makes no
> > sense to me
>
> In the code you posted above here: Move the input into the while loop.
> You may prefer raw_input() to input().
>
> I don't want to write the code for you ;-)

whats the difference between raw input and input?

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


Re: Beginner Programmer Question

2006-06-26 Thread Rune Strand

[EMAIL PROTECTED] wrote:
> Rune Strand wrote:
> > >
> > > I am doing alot of reading, and the problem didnt come with an answer.
> > > I dont understand how to get it to continually input numbers and add
> > > all those together
> >
> > Use while, raw_input, sys.argv[1] and int() and break the loop when the
> > sum is above 100.
> >
> > ;-)
>
> thanks for the help..but i am extremley new and what you said makes no
> sense to me

In the code you posted above here: Move the input into the while loop.
You may prefer raw_input() to input().

I don't want to write the code for you ;-)

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


Re: Beginner Programmer Question

2006-06-26 Thread SuperHik
Rune Strand wrote:
>> I am doing alot of reading, and the problem didnt come with an answer.
>> I dont understand how to get it to continually input numbers and add
>> all those together
> 
> Use while, raw_input, sys.argv[1] and int() and break the loop when the
> sum is above 100.
> 
> ;-)
> 
I don't think you understood his problem. He is trying to learn how to 
*program*, not just learn Python ;)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beginner Programmer Question

2006-06-26 Thread SuperHik
[EMAIL PROTECTED] wrote:
> I am doing alot of reading and trying to teach myself how to program.
> I can not figure out how to make "Write a program that continually
> reads in numbers from the user and adds them together until the sum
> reaches 100." this work. If someone could show me the correct code so i
> can learn from that it would be much appreciated. Thanks
> 

summ = 0
while summ < 100:
 usr = input('Enter a number:')
 summ += usr   #that's same as>>> summ = summ + usr
 print summ

print "now continue with whatever you want..."
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beginner Programmer Question

2006-06-26 Thread [EMAIL PROTECTED]

Rune Strand wrote:
> >
> > I am doing alot of reading, and the problem didnt come with an answer.
> > I dont understand how to get it to continually input numbers and add
> > all those together
>
> Use while, raw_input, sys.argv[1] and int() and break the loop when the
> sum is above 100.
>
> ;-)

thanks for the help..but i am extremley new and what you said makes no
sense to me

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


Re: Beginner Programmer Question

2006-06-26 Thread Rune Strand
>
> I am doing alot of reading, and the problem didnt come with an answer.
> I dont understand how to get it to continually input numbers and add
> all those together

Use while, raw_input, sys.argv[1] and int() and break the loop when the
sum is above 100.

;-)

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


Re: Beginner Programmer Question

2006-06-26 Thread [EMAIL PROTECTED]

[EMAIL PROTECTED] wrote:
> Claudio Grondi wrote:
> > [EMAIL PROTECTED] wrote:
> > > I am doing alot of reading and trying to teach myself how to program.
> > > I can not figure out how to make "Write a program that continually
> > > reads in numbers from the user and adds them together until the sum
> > > reaches 100." this work. If someone could show me the correct code so i
> > > can learn from that it would be much appreciated. Thanks
> > >
> > Isn't it your homework?
> > Why can't you figure it out?
> > What have you tried?
> >
> > Claudio
>
> I am doing alot of reading, and the problem didnt come with an answer.
> I dont understand how to get it to continually input numbers and add
> all those together

#Add up to 100 program

#What number are you adding up to?
bigone = 100

number = input("Whats the first number?")
number2 = input ("Whats the second number?")
nu3 = number+number2
while nu3 < bigone:
print ("Not there yet, next number please")


print "Finally there!"

thats what i thought maybe it was...but after the first two numbers it
just continually scrolls on the screen with finally there

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


Re: Beginner Programmer Question

2006-06-26 Thread [EMAIL PROTECTED]

Claudio Grondi wrote:
> [EMAIL PROTECTED] wrote:
> > I am doing alot of reading and trying to teach myself how to program.
> > I can not figure out how to make "Write a program that continually
> > reads in numbers from the user and adds them together until the sum
> > reaches 100." this work. If someone could show me the correct code so i
> > can learn from that it would be much appreciated. Thanks
> >
> Isn't it your homework?
> Why can't you figure it out?
> What have you tried?
>
> Claudio

I am doing alot of reading, and the problem didnt come with an answer.
I dont understand how to get it to continually input numbers and add
all those together

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


Re: Beginner Programmer Question

2006-06-26 Thread Claudio Grondi
[EMAIL PROTECTED] wrote:
> I am doing alot of reading and trying to teach myself how to program.
> I can not figure out how to make "Write a program that continually
> reads in numbers from the user and adds them together until the sum
> reaches 100." this work. If someone could show me the correct code so i
> can learn from that it would be much appreciated. Thanks
> 
Isn't it your homework?
Why can't you figure it out?
What have you tried?

Claudio
-- 
http://mail.python.org/mailman/listinfo/python-list


Beginner Programmer Question

2006-06-26 Thread kydavis77
I am doing alot of reading and trying to teach myself how to program.
I can not figure out how to make "Write a program that continually
reads in numbers from the user and adds them together until the sum
reaches 100." this work. If someone could show me the correct code so i
can learn from that it would be much appreciated. Thanks

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