Re: The sum of ten numbers inserted from the user

2019-02-09 Thread Terry Reedy
On 2/9/2019 4:23 AM, Christian Gollwitzer wrote: Am 08.02.19 um 09:58 schrieb ^Bart: A colleague did: total=0 for n in range(10): n= int(input("Enter a number: ")) Here, you are reusing "n" for two different things: 1. The loop index, indicating which number you ask for 2. The number

Re: The sum of ten numbers inserted from the user

2019-02-09 Thread Christian Gollwitzer
Am 08.02.19 um 09:58 schrieb ^Bart: A colleague did: total=0 for n in range(10):     n= int(input("Enter a number: ")) Here, you are reusing "n" for two different things: 1. The loop index, indicating which number you ask for 2. The number entered from the user This is avery bad thing.

Re: The sum of ten numbers inserted from the user

2019-02-08 Thread ^Bart
x = 0 for jnk in range(10): x += int(input("Enter a number: ") print(x) It works, there's a missed ) A colleague did: total=0 for n in range(10): n= int(input("Enter a number: ")) total=total+n print(total) I understood your code is more clean! ^Bart --

Re: The sum of ten numbers inserted from the user

2019-02-07 Thread Ben Bacarisse
Grant Edwards writes: > On 2019-02-07, Ben Bacarisse wrote: >> Ian Clark writes: >> >>> This is my whack at it, I can't wait to hear about it being the wrong big o >>> notation! >>> >>> numbers=[] >>> >>> while len(numbers) < 10: >>> try: >>> chip = int(input('please enter an

Re: The sum of ten numbers inserted from the user

2019-02-07 Thread Ben Bacarisse
Bart writes: > On 07/02/2019 20:45, Ben Bacarisse wrote: >> Ian Clark writes: >> >>> This is my whack at it, I can't wait to hear about it being the wrong big o >>> notation! >>> >>> numbers=[] >>> >>> while len(numbers) < 10: >>> try: >>> chip = int(input('please enter an

Re: The sum of ten numbers inserted from the user

2019-02-07 Thread Grant Edwards
On 2019-02-07, Ben Bacarisse wrote: > Ian Clark writes: > >> This is my whack at it, I can't wait to hear about it being the wrong big o >> notation! >> >> numbers=[] >> >> while len(numbers) < 10: >> try: >> chip = int(input('please enter an integer: ')) >> except ValueError: >>

Re: The sum of ten numbers inserted from the user

2019-02-07 Thread Ben Bacarisse
Ian Clark writes: > This is my whack at it, I can't wait to hear about it being the wrong big o > notation! > > numbers=[] > > while len(numbers) < 10: > try: > chip = int(input('please enter an integer: ')) > except ValueError: > print('that is not a number, try again')

RE: The sum of ten numbers inserted from the user

2019-02-07 Thread Schachner, Joseph
I just realized that input has changed in Python 3 and I was using Python 2.7.13 with from __future__ import print_function and some others, but not that. In Python 3 the int( ) or float( ) cast is necessary because input( ) does what raw_input( ) did in Python 2; raw_input( ) name is therefore

Re: The sum of ten numbers inserted from the user

2019-02-07 Thread Ian Clark
This is my whack at it, I can't wait to hear about it being the wrong big o notation! numbers=[] while len(numbers) < 10: try: chip = int(input('please enter an integer: ')) except ValueError: print('that is not a number, try again') else: numbers.append(chip)

RE: The sum of ten numbers inserted from the user

2019-02-07 Thread Schachner, Joseph
Well of course that doesn't work. For starters, x is an int or a float value. After the loop It holds the 10th value. It might hold 432.7 ... It is not a list. The default start for range is 0. The stop value, as you already know, is not part of the range. So I will use range(10). In

Re: The sum of ten numbers inserted from the user

2019-02-07 Thread Joel Goldstick
On Thu, Feb 7, 2019 at 6:31 AM ^Bart wrote: > > I thought something like it but doesn't work... > > for n in range(1, 11): > x = input("Insert a number: ") The above, keeps replacing x with each input value. You don't want that. Think about appending the input value to a list > > for y in