Skip to main content
Notes about edit should go into the Edit Summary
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Use loops!

odd_nums = []
for i in xrange(10):
    value = int(raw_input('Enter an integer: '))
    if value % 2 != 0:
        odd_nums.append(value)

if len(odd_nums) != 0:
    print max(odd_nums)
else:
    print "No odd values"

How to read this line:

for i in xrange(10):

for i in xrange(10):

This line means starting at 0 (the default starting point for xrange()), and ending at 10-1 (upper bound is not included), execute the following code with i set to the current iteration of the loop. This executes the code exactly 10 times (i = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9).

The rest was made as similar to your code as possible, and so should be understandable.


Edit: changed input to value, as per comments, as well as added some explanation.

Use loops!

odd_nums = []
for i in xrange(10):
    value = int(raw_input('Enter an integer: '))
    if value % 2 != 0:
        odd_nums.append(value)

if len(odd_nums) != 0:
    print max(odd_nums)
else:
    print "No odd values"

How to read this line:

for i in xrange(10):

This line means starting at 0 (the default starting point for xrange()), and ending at 10-1 (upper bound is not included), execute the following code with i set to the current iteration of the loop. This executes the code exactly 10 times (i = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9).

The rest was made as similar to your code as possible, and so should be understandable.


Edit: changed input to value, as per comments, as well as added some explanation.

Use loops!

odd_nums = []
for i in xrange(10):
    value = int(raw_input('Enter an integer: '))
    if value % 2 != 0:
        odd_nums.append(value)

if len(odd_nums) != 0:
    print max(odd_nums)
else:
    print "No odd values"

How to read this line:

for i in xrange(10):

This line means starting at 0 (the default starting point for xrange()), and ending at 10-1 (upper bound is not included), execute the following code with i set to the current iteration of the loop. This executes the code exactly 10 times (i = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9).

The rest was made as similar to your code as possible, and so should be understandable.

added 3 characters in body
Source Link
mleyfman
  • 5.3k
  • 1
  • 25
  • 48

Use loops!

odd_nums = []
for i in xrange(10):
    value = int(raw_input('Enter an integer: '))
    if value % 2 != 0:
        odd_nums += [value].append(value)

if len(odd_nums) != 0:
    print max(odd_nums)
else:
    print "No odd values"

How to read this line:

for i in xrange(10):

This line means starting at 0 (the default starting point for xrange()), and ending at 10-1 (upper bound is not included), execute the following code with i set to the current iteration of the loop. This executes the code exactly 10 times (i = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9).

The rest was made as similar to your code as possible, and so should be understandable.


Edit: changed input to value, as per comments, as well as added some explanation.

Use loops!

odd_nums = []
for i in xrange(10):
    value = int(raw_input('Enter an integer: '))
    if value % 2 != 0:
        odd_nums += [value]

if len(odd_nums) != 0:
    print max(odd_nums)
else:
    print "No odd values"

How to read this line:

for i in xrange(10):

This line means starting at 0 (the default starting point for xrange()), and ending at 10-1 (upper bound is not included), execute the following code with i set to the current iteration of the loop. This executes the code exactly 10 times (i = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9).

The rest was made as similar to your code as possible, and so should be understandable.


Edit: changed input to value, as per comments, as well as added some explanation.

Use loops!

odd_nums = []
for i in xrange(10):
    value = int(raw_input('Enter an integer: '))
    if value % 2 != 0:
        odd_nums.append(value)

if len(odd_nums) != 0:
    print max(odd_nums)
else:
    print "No odd values"

How to read this line:

for i in xrange(10):

This line means starting at 0 (the default starting point for xrange()), and ending at 10-1 (upper bound is not included), execute the following code with i set to the current iteration of the loop. This executes the code exactly 10 times (i = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9).

The rest was made as similar to your code as possible, and so should be understandable.


Edit: changed input to value, as per comments, as well as added some explanation.

deleted 6 characters in body
Source Link
mleyfman
  • 5.3k
  • 1
  • 25
  • 48

Use loops!

odd_nums = []
for i in xrange(0, 10):
    value = int(raw_input('Enter an integer: '))
    if value % 2 != 0:
        odd_nums += [value]

if lengthlen(odd_nums) != 0:
    print max(odd_nums)
else:
    print "No odd values"

How to read this line:

for i in xrange(0, 10):

This line means starting at 0 (the default starting point for xrange()), and ending at 10-1 (upper bound is not included), execute the following code with i set to the current iteration of the loop. This executes the code exactly 10 times (i = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9).

The rest was made as similar to your code as possible, and so should be understandable.


Edit: changed input to value, as per comments, as well as added some explanation.

Use loops!

odd_nums = []
for i in xrange(0, 10):
    value = int(raw_input('Enter an integer: '))
    if value % 2 != 0:
        odd_nums += [value]

if length(odd_nums) != 0:
    print max(odd_nums)
else:
    print "No odd values"

How to read this line:

for i in xrange(0, 10):

This line means starting at 0, and ending at 10-1 (upper bound is not included), execute the following code with i set to the current iteration of the loop. This executes the code exactly 10 times (i = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9).

The rest was made as similar to your code as possible, and so should be understandable.


Edit: changed input to value, as per comments, as well as added some explanation.

Use loops!

odd_nums = []
for i in xrange(10):
    value = int(raw_input('Enter an integer: '))
    if value % 2 != 0:
        odd_nums += [value]

if len(odd_nums) != 0:
    print max(odd_nums)
else:
    print "No odd values"

How to read this line:

for i in xrange(10):

This line means starting at 0 (the default starting point for xrange()), and ending at 10-1 (upper bound is not included), execute the following code with i set to the current iteration of the loop. This executes the code exactly 10 times (i = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9).

The rest was made as similar to your code as possible, and so should be understandable.


Edit: changed input to value, as per comments, as well as added some explanation.

edited body
Source Link
mleyfman
  • 5.3k
  • 1
  • 25
  • 48
Loading
edited body
Source Link
mleyfman
  • 5.3k
  • 1
  • 25
  • 48
Loading
added 25 characters in body
Source Link
mleyfman
  • 5.3k
  • 1
  • 25
  • 48
Loading
added 185 characters in body
Source Link
mleyfman
  • 5.3k
  • 1
  • 25
  • 48
Loading
Source Link
mleyfman
  • 5.3k
  • 1
  • 25
  • 48
Loading