#๐Ÿ”’ homework help

26 messages ยท Page 1 of 1 (latest)

late light
#

idk why its printing with the extra space

fickle hearthBOT
#

@late light

Python help channel opened

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.

late light
#
# 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

mighty spire
#

!e

print(1, 2, 3)
print(1, 2, 3, sep='')
fickle hearthBOT
#

@mighty spire :white_check_mark: Your 3.12 eval job has completed with return code 0.

001 | 1 2 3
002 | 123
mighty spire
#

But, just using an f-string there would be a better idea.

late light
#

i tried sep but it removes all spaces

mighty spire
mighty spire
#

': value is '

late light
#

oh i see what your saying i was just over thinking it ty

mighty spire
#

You're welcome. Like I said though, I'd just use f-strings there. It will likely be cleaner.

late light
mighty spire
#

Who wrote this code?

late light
#

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

mighty spire
#

Not sure what you mean, but you're using an f-string on the last line already.

#

!f-string

fickle hearthBOT
#
Format-strings

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.

late light
#

(f is this what your talking about

#

oh i didnt know thats what thats called i see

fickle hearthBOT
#
Python help channel closed

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