#๐ Help with python question
14 messages ยท Page 1 of 1 (latest)
@slender anvil
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
What is the problem?
ill send smth else gimme a sec
im struggling to get this question fully correct instead of partially
def number_string(startNumber, endNumber, separator, show):
# Create a list of numbers from startNumber to endNumber
numbers = list(range(startNumber, endNumber + 1))
# Check if the show parameter is 'even'
if show == "even":
# Use list comprehension to filter even numbers
filtered_numbers = [str(num) for num in numbers if num % 2 == 0]
# Check if the show parameter is 'odd'
elif show == "odd":
# Use list comprehension to filter odd numbers
filtered_numbers = [str(num) for num in numbers if num % 2 != 0]
# Join the filtered numbers into a string using the separator
return separator.join(filtered_numbers)
# Examples
result1 = number_string(startNumber=5, endNumber=16, separator="*", show="even")
print(result1) # Output: 6*8*10*12*14*16
result2 = number_string(startNumber=5, endNumber=16, separator="#", show="odd")
print(result2) # Output: 5#7#9#11#13#15
```python
I don't see a problem. I copied your code onto my workspace, and tried the testcases, it works fine for me.
Sorry I'm not helping.
!e
def number_string(startNumber, endNumber, separator, show):
# Create a list of numbers from startNumber to endNumber
numbers = list(range(startNumber, endNumber + 1))
# Check if the show parameter is 'even'
if show == "even":
# Use list comprehension to filter even numbers
filtered_numbers = [str(num) for num in numbers if num % 2 == 0]
# Check if the show parameter is 'odd'
elif show == "odd":
# Use list comprehension to filter odd numbers
filtered_numbers = [str(num) for num in numbers if num % 2 != 0]
# Join the filtered numbers into a string using the separator
return separator.join(filtered_numbers)
# Examples
result1 = number_string(startNumber=5, endNumber=16, separator="*", show="even")
print(result1) # Output: 6*8*10*12*14*16
result2 = number_string(startNumber=5, endNumber=16, separator="#", show="odd")
print(result2) # Output: 5#7#9#11#13#15
result3 = number_string(startNumber=1, endNumber=9, separator="*", show="odd") #Failed Test Case 1
print(result3)
result4 = number_string(startNumber=2, endNumber=8, separator="#", show="even") #Failed Test Case 2
print(result4)
@bronze spruce :white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | 6*8*10*12*14*16
002 | 5#7#9#11#13#15
003 | 1*3*5*7*9
004 | 2#4#6#8
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.