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
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.
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
--
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
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
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:
>>
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')
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
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)
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
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
11 matches
Mail list logo