Skip to main content
added 35 characters in body
Source Link

You can simplify this code quite a bit using lists. First, you need to collect the 10 inputs into a list:

list = [] # Initializes a list
for x in range(10): # Repeats 10 times
 list.append(int(input("enter number: "))) # Appends the integer version of the input number to the list

Then, you can use the max() and pop() functions in Python to do thing to the list:

for y in range(10): # Repeats 10 times
 x = list.pop(list.index(max(list))) # Sets x equal to the biggest number in the list, which also gets removed
 if x % 2 == 1: # Checks if x is odd
  print(x) # Prints x if x is odd
  break # Stops the loop

Here is the full code:

list = []
for x in range(10):
 list.append(int(input("enter number: ")))
for y in range(10):
 x = list.pop(list.index(max(list)))
 if x % 2 == 1:
  print(x)
  break

You can simplify this code quite a bit using lists. First, you need to collect the 10 inputs into a list:

list = [] # Initializes a list
for x in range(10): # Repeats 10 times
 list.append(int(input("enter number: "))) # Appends the integer version of the input number to the list

Then, you can use the max() and pop() functions in Python to do thing to the list:

for y in range(10): # Repeats 10 times
 x = list.pop(list.index(max(list))) # Sets x equal to the biggest number in the list, which also gets removed
 if x % 2 == 1: # Checks if x is odd
  print(x) # Prints x if x is odd

Here is the full code:

list = []
for x in range(10):
 list.append(int(input("enter number: ")))
for y in range(10):
 x = list.pop(list.index(max(list)))
 if x % 2 == 1:
  print(x)

You can simplify this code quite a bit using lists. First, you need to collect the 10 inputs into a list:

list = [] # Initializes a list
for x in range(10): # Repeats 10 times
 list.append(int(input("enter number: "))) # Appends the integer version of the input number to the list

Then, you can use the max() and pop() functions in Python to do thing to the list:

for y in range(10): # Repeats 10 times
 x = list.pop(list.index(max(list))) # Sets x equal to the biggest number in the list, which also gets removed
 if x % 2 == 1: # Checks if x is odd
  print(x) # Prints x if x is odd
  break # Stops the loop

Here is the full code:

list = []
for x in range(10):
 list.append(int(input("enter number: ")))
for y in range(10):
 x = list.pop(list.index(max(list)))
 if x % 2 == 1:
  print(x)
  break
Source Link

You can simplify this code quite a bit using lists. First, you need to collect the 10 inputs into a list:

list = [] # Initializes a list
for x in range(10): # Repeats 10 times
 list.append(int(input("enter number: "))) # Appends the integer version of the input number to the list

Then, you can use the max() and pop() functions in Python to do thing to the list:

for y in range(10): # Repeats 10 times
 x = list.pop(list.index(max(list))) # Sets x equal to the biggest number in the list, which also gets removed
 if x % 2 == 1: # Checks if x is odd
  print(x) # Prints x if x is odd

Here is the full code:

list = []
for x in range(10):
 list.append(int(input("enter number: ")))
for y in range(10):
 x = list.pop(list.index(max(list)))
 if x % 2 == 1:
  print(x)