i need to make a program that adds numbers, but asking first the user how many numbers he wants to add, and then adding them. any one knows how to do that

Recommended Answers

All 4 Replies

Not exactly sure on what you want to do? Sounds like homework, please show some effort first!

any one knows how to do that

Yes off course many off us now how to that,you should try something yourself.

Here is an explaination.
For first question use int(raw_input('how many questions: ') or python 3 int(input('...').
This will return an integer.
Then you make an empty list my_list = [ ].
So make for loop with range('..'),where you put variable from first question.
Then a new question inside the loop where you bind that question to a variable,that question will loop as many times as the first question variable return because you put it in a range function.
Then you append that question variable to the empty list my_list.append('...')
So outside the for loop you do sum(my_list)

remember to use try to catch TypeError

remember to use try to catch TypeError

Yes,we can take that later how to catch errors(Exception handling).
When you new is more important to get the code to run and understand the logic.
Then is a good exercice to try and catch all error a user input question can give.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.