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 15 2098 ky*******@gmail.com 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
Claudio Grondi wrote: ky*******@gmail.com 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 ky*******@gmail.com wrote: Claudio Grondi wrote: ky*******@gmail.com 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
> 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.
;-)
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 ky*******@gmail.com 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..."
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 ;) ky*******@gmail.com 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 ;-)
Rune Strand wrote: ky*******@gmail.com 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? ky*******@gmail.com wrote: ky*******@gmail.com wrote:
Claudio Grondi wrote:
ky*******@gmail.com 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 ky*******@gmail.com 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.
> 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
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!!!
<ky*******@gmail.com> wrote in message
news:11*********************@y41g2000cwy.googlegro ups.com... 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.
On Mon, 26 Jun 2006 10:47:58 -0700, ky*******@gmail.com 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) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: lester |
last post by:
a pre-beginner's question:
what is the pros and cons of .net, compared to ++
I am wondering what can I get if I continue to learn C# after I have learned
C --> C++ --> C# ??
I think there...
|
by: Grrrbau |
last post by:
I'm a beginner.
I'm looking for a good C++ book.
Someone told me about Lafore's "Object-Oriented Programming in C++".
What do you think?
Grrrbau
|
by: japin0 |
last post by:
Hi,
I am a absolute beginner in ASP ..I do have a bit of exposure to .VBS
and other scripting languages.
I need your guidance, where do I start? I had been to MS website Quick
start guide but it...
|
by: MHoffman |
last post by:
I am just learning to program, and hoping someone can help
me with the following:
for a simple calculator, a string is entered into a text
box ... how do I prevent the user from entering a text...
|
by: Jeremy |
last post by:
hello,
I am trying to calculate the standard deviation with my program, but I
ran into a small problem with squaring negative value's. Which cannot
be done.. Ehm let me explain let's say;
...
|
by: Jacky Luk |
last post by:
import java.awt.Graphics;
public class printtest extends java.applet.Applet
{
public void init()
{
}
public void paint (Graphics g)
{
|
by: macca |
last post by:
Hi, I'm looking for a good book on PHP design patterns for a OOP
beginner - Reccommendations please?
Thanks
Paul
|
by: Daniel |
last post by:
Looking to see if anyone can offer some suggestions on some good VB.net
books?
looking for beginner to intermidiate and to expert..
Any suggestions?
--
ASP, SQL2005, DW8 VBScript
|
by: a |
last post by:
Dear all vb.net developer
I want to know the time I need to master vb.net?
I'm beginner
|
by: ddg_linux |
last post by:
I have been reading about and doing a lot of php code examples from
books but now I find myself wanting to do something practical with
some of the skills that I have learned.
I am a beginner php...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |