We’re rewarding the question askers & reputations are being recalculated! Read more.
3 Changed to reflect improvements mentioned in comments
source | link

Here are a couple of places you might make your code more concise:

First, lines 2-11 take a lot of space, and you repeat these values again below when you assign list1. You might instead consider trying to combine these lines into one step. A list comprehension might allow you to perform these two actions in one step:

>>> def my_solution():
    list1numbers = [input('Enter a value: ') for i in range(10)]

A second list comprehension might further narrow down your results by removing even values:

    list2odds = [y for y in list1numbers if y % 2 != 0]

You could then see if your list contains any values. If it does not, no odd values were in your list. Otherwise, you could find the max of the values that remain in your list, which should all be odd:

    if len(list2) != []odds:
        return max(list2odds)
    else:
        return 'All declared variables have even values.'

In total, then, you might use the following as a starting point for refining your code:

>>> def my_solution():
    list1    numbers = [input('Enter a value: ') for i in range(10)]
    list2    odds = [y for y in list1numbers if y % 2 != 0]
    if len(list2) != [] if odds:
            return max(list2odds)
        else:
            return 'All declared variables have even values.'


>>> my_solution()
Enter a value: 10
Enter a value: 101
Enter a value: 48
Enter a value: 589
Enter a value: 96
Enter a value: 74
Enter a value: 945
Enter a value: 6
Enter a value: 3
Enter a value: 96
945

Here are a couple of places you might make your code more concise:

First, lines 2-11 take a lot of space, and you repeat these values again below when you assign list1. You might instead consider trying to combine these lines into one step. A list comprehension might allow you to perform these two actions in one step:

>>> def my_solution():
    list1 = [input('Enter a value: ') for i in range(10)]

A second list comprehension might further narrow down your results by removing even values:

    list2 = [y for y in list1 if y % 2 != 0]

You could then see if your list contains any values. If it does not, no odd values were in your list. Otherwise, you could find the max of the values that remain in your list, which should all be odd:

    if len(list2) != []:
        return max(list2)
    else:
        return 'All declared variables have even values.'

In total, then, you might use the following as a starting point for refining your code:

>>> def my_solution():
    list1 = [input('Enter a value: ') for i in range(10)]
    list2 = [y for y in list1 if y % 2 != 0]
    if len(list2) != []:
        return max(list2)
    else:
        return 'All declared variables have even values.'


>>> my_solution()
Enter a value: 10
Enter a value: 101
Enter a value: 48
Enter a value: 589
Enter a value: 96
Enter a value: 74
Enter a value: 945
Enter a value: 6
Enter a value: 3
Enter a value: 96
945

Here are a couple of places you might make your code more concise:

First, lines 2-11 take a lot of space, and you repeat these values again below when you assign list1. You might instead consider trying to combine these lines into one step. A list comprehension might allow you to perform these two actions in one step:

>>> def my_solution():
    numbers = [input('Enter a value: ') for i in range(10)]

A second list comprehension might further narrow down your results by removing even values:

    odds = [y for y in numbers if y % 2 != 0]

You could then see if your list contains any values. If it does not, no odd values were in your list. Otherwise, you could find the max of the values that remain in your list, which should all be odd:

    if odds:
        return max(odds)
    else:
        return 'All declared variables have even values.'

In total, then, you might use the following as a starting point for refining your code:

>>> def my_solution():
        numbers = [input('Enter a value: ') for i in range(10)]
        odds = [y for y in numbers if y % 2 != 0]
        if odds:
            return max(odds)
        else:
            return 'All declared variables have even values.'


>>> my_solution()
Enter a value: 10
Enter a value: 101
Enter a value: 48
Enter a value: 589
Enter a value: 96
Enter a value: 74
Enter a value: 945
Enter a value: 6
Enter a value: 3
Enter a value: 96
945
2 edited body
source | link

Here are a couple of places you might make your code more concise:

First, lines 2-11 take a lot of space, and you repeat these values again below when you assign list1. You might instead consider trying to combine these lines into one step. A list comprehension might allow you to perform these two actions in one step:

>>> def my_solution():
    list1 = [input('Enter a value: ') for xi in range(10)]

A second list comprehension might further narrow down your results by removing even values:

    list2 = [y for y in list1 if y % 2 != 0]

You could then see if your list contains any values. If it does not, no odd values were in your list. Otherwise, you could find the max of the values that remain in your list, which should all be odd:

    if len(list2) != []:
        return max(list2)
    else:
        return 'All declared variables have even values.'

In total, then, you might use the following as a starting point for refining your code:

>>> def my_solution():
    list1 = [input('Enter a value: ') for xi in range(10)]
    list2 = [y for y in list1 if y % 2 != 0]
    if len(list2) != []:
        return max(list2)
    else:
        return 'All declared variables have even values.'


>>> my_solution()
Enter a value: 10
Enter a value: 101
Enter a value: 48
Enter a value: 589
Enter a value: 96
Enter a value: 74
Enter a value: 945
Enter a value: 6
Enter a value: 3
Enter a value: 96
945

Here are a couple of places you might make your code more concise:

First, lines 2-11 take a lot of space, and you repeat these values again below when you assign list1. You might instead consider trying to combine these lines into one step. A list comprehension might allow you to perform these two actions in one step:

>>> def my_solution():
    list1 = [input('Enter a value: ') for x in range(10)]

A second list comprehension might further narrow down your results by removing even values:

    list2 = [y for y in list1 if y % 2 != 0]

You could then see if your list contains any values. If it does not, no odd values were in your list. Otherwise, you could find the max of the values that remain in your list, which should all be odd:

    if len(list2) != []:
        return max(list2)
    else:
        return 'All declared variables have even values.'

In total, then, you might use the following as a starting point for refining your code:

>>> def my_solution():
    list1 = [input('Enter a value: ') for x in range(10)]
    list2 = [y for y in list1 if y % 2 != 0]
    if len(list2) != []:
        return max(list2)
    else:
        return 'All declared variables have even values.'


>>> my_solution()
Enter a value: 10
Enter a value: 101
Enter a value: 48
Enter a value: 589
Enter a value: 96
Enter a value: 74
Enter a value: 945
Enter a value: 6
Enter a value: 3
Enter a value: 96
945

Here are a couple of places you might make your code more concise:

First, lines 2-11 take a lot of space, and you repeat these values again below when you assign list1. You might instead consider trying to combine these lines into one step. A list comprehension might allow you to perform these two actions in one step:

>>> def my_solution():
    list1 = [input('Enter a value: ') for i in range(10)]

A second list comprehension might further narrow down your results by removing even values:

    list2 = [y for y in list1 if y % 2 != 0]

You could then see if your list contains any values. If it does not, no odd values were in your list. Otherwise, you could find the max of the values that remain in your list, which should all be odd:

    if len(list2) != []:
        return max(list2)
    else:
        return 'All declared variables have even values.'

In total, then, you might use the following as a starting point for refining your code:

>>> def my_solution():
    list1 = [input('Enter a value: ') for i in range(10)]
    list2 = [y for y in list1 if y % 2 != 0]
    if len(list2) != []:
        return max(list2)
    else:
        return 'All declared variables have even values.'


>>> my_solution()
Enter a value: 10
Enter a value: 101
Enter a value: 48
Enter a value: 589
Enter a value: 96
Enter a value: 74
Enter a value: 945
Enter a value: 6
Enter a value: 3
Enter a value: 96
945
1
source | link

Here are a couple of places you might make your code more concise:

First, lines 2-11 take a lot of space, and you repeat these values again below when you assign list1. You might instead consider trying to combine these lines into one step. A list comprehension might allow you to perform these two actions in one step:

>>> def my_solution():
    list1 = [input('Enter a value: ') for x in range(10)]

A second list comprehension might further narrow down your results by removing even values:

    list2 = [y for y in list1 if y % 2 != 0]

You could then see if your list contains any values. If it does not, no odd values were in your list. Otherwise, you could find the max of the values that remain in your list, which should all be odd:

    if len(list2) != []:
        return max(list2)
    else:
        return 'All declared variables have even values.'

In total, then, you might use the following as a starting point for refining your code:

>>> def my_solution():
    list1 = [input('Enter a value: ') for x in range(10)]
    list2 = [y for y in list1 if y % 2 != 0]
    if len(list2) != []:
        return max(list2)
    else:
        return 'All declared variables have even values.'


>>> my_solution()
Enter a value: 10
Enter a value: 101
Enter a value: 48
Enter a value: 589
Enter a value: 96
Enter a value: 74
Enter a value: 945
Enter a value: 6
Enter a value: 3
Enter a value: 96
945