I’m a real noob. Online course presented this problem and I can’t figure it out. What it’s supposed to output is at the bottom.
def odd_numbers(maximum):
return_string = "" # Initializes variable as a string
# Complete the for loop with a range that includes all
# odd numbers up to and including the "maximum" value.
for :
# Complete the body of the loop by appending the odd number
# followed by a space to the "return_string" variable.
# This .strip command will remove the final " " space
# at the end of the "return_string".
return return_string.strip()
print(odd_numbers(6)) # Should be 1 3 5
print(odd_numbers(10)) # Should be 1 3 5 7 9
print(odd_numbers(1)) # Should be 1
print(odd_numbers(3)) # Should be 1 3
print(odd_numbers(0)) # No numbers displayed
I tried this…
def odd_numbers(maximum):
return_string = "" # Initializes variable as a string
# Complete the for loop with a range that includes all
# odd numbers up to and including the "maximum" value.
for n in range(maximum):
return range(1, n, 2)
# Complete the body of the loop by appending the odd number
# followed by a space to the "return_string" variable.
return_string = ", "
# This .strip command will remove the final " " space
# at the end of the "return_string".
return return_string.strip()
print(odd_numbers(6)) # Should be 1 3 5
print(odd_numbers(10)) # Should be 1 3 5 7 9
print(odd_numbers(1)) # Should be 1
print(odd_numbers(3)) # Should be 1 3
print(odd_numbers(0)) # No numbers displayed
and it printed out this…
range(1, 0, 2) range(1, 0, 2) range(1, 0, 2) range(1, 0, 2)
It works when I use the list function but that’s not the form it should be in because I keep getting it wrong. It’s been 3 days — Please HELP!!
New contributor
Ebo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.