#๐ homework help
26 messages ยท Page 1 of 1 (latest)
@late light
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.
# Read input and split input into tokens
tokens = input().split()
pressure_samples = []
for token in tokens:
pressure_samples.append(int(token))
print(f'All data: {pressure_samples}')
if __name__ == '__main__':
sum_selected = 0
for index, element in enumerate(pressure_samples):
if index % 2 == 0 and element >= 60:
print('Index', index, ': value is', element)
sum_selected += element
print(f'Sum of selected elements is: {sum_selected}')
Input
36 69 59 20 60 61
Your output
All data: [36, 69, 59, 20, 60, 61]
Index 4 : value is 60
Sum of selected elements is: 60
Expected output
All data: [36, 69, 59, 20, 60, 61]
Index 4: value is 60
Sum of selected elements is: 60
print by default automatically inserts spaces between each argument. You can override that by specifying a sep argument:
!e
print(1, 2, 3)
print(1, 2, 3, sep='')
@mighty spire :white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | 1 2 3
002 | 123
But, just using an f-string there would be a better idea.
i tried sep but it removes all spaces
Ya, then you add the spaces that you do want to the existing strings.
how do i do that
': value is '
oh i see what your saying i was just over thinking it ty
You're welcome. Like I said though, I'd just use f-strings there. It will likely be cleaner.
idk what thoes are i might learn them later in the lesson
Who wrote this code?
i was puting parts of my leson then replaceing them with the thing i needed for the prompt
like looking back at other parts of the lesson
Not sure what you mean, but you're using an f-string on the last line already.
!f-string
Creating a Python string with your variables using the + operator can be difficult to write and read. F-strings (format-strings) make it easy to insert values into a string. If you put an f in front of the first quote, you can then put Python expressions between curly braces in the string.
>>> snake = "pythons"
>>> number = 21
>>> f"There are {number * 2} {snake} on the plane."
"There are 42 pythons on the plane."
Note that even when you include an expression that isn't a string, like number * 2, Python will convert it to a string for you.
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.
๐ homework help