Re: New to Python
- From: "Arnaud Delobelle" <arnodel@xxxxxxxxxxxxxx>
- Date: 5 Mar 2007 11:14:56 -0800
On Mar 5, 6:33 pm, "dnwu...@xxxxxxxxx" <dnwu...@xxxxxxxxx> wrote:
I am trying to get a program to add up input from the user to get to
the number 100 using a loop. However, I am having some issues. Here
is what I have so far. I know I am just trying to hard, but I am
stuck. Thank you for any help.
print "We need to count to 100"
high_number = 100
total = 0
number = input("Enter your first number ")
sum = number + total
while sum < high_number:
print "Not there yet..."
number = input("Enter another number ")
print "We are there!!!"
There is no need for 'sum' and 'total'. Here's a working version of
your program. Look at the differences with your attempt.
----------
print "We need to count to 100"
high_number = 100
total = input("Enter your first number ") # first total is the fist
number
while total < high_number:
print "Not there yet..."
number = input("Enter another number ")
total = total + number # Add the new number to the total
print "We are there!!!"
----------
Good luck !
As others have pointed out, 'input' is a function to be careful with.
You could use answer=raw_input(...) and then convert the result to an
int by using number=int(answer).
--
Arnaud
.
- Follow-Ups:
- Re: New to Python
- From: dnwurtz@xxxxxxxxx
- Re: New to Python
- References:
- New to Python
- From: dnwurtz@xxxxxxxxx
- New to Python
- Prev by Date: Re: Project organization and import
- Next by Date: Re: New to Python
- Previous by thread: Re: New to Python
- Next by thread: Re: New to Python
- Index(es):
Relevant Pages
|
Loading