You are viewing a single thread.
View all comments View context
11 points

Hey ChatGPT. I need you to walk through a for loop for me. Every time the loop completes I want you to say completed. I need the for loop to iterate off of a variable, n. I need the for loop to have an exit condition of n+1.

permalink
report
parent
reply
5 points
*

Didn’t work. Output this:

`# Set the value of n
n = 5

Create a for loop with an exit condition of n+1

for i in range(n+1):
# Your code inside the loop goes here
print(f"Iteration {i} completed.")

This line will be executed after the loop is done

print(“Loop finished.”)`

Interesting. The code format doesn’t work on Kbin.

permalink
report
parent
reply
6 points

Interesting. The code format doesn’t work on Kbin.

Indent the lines of the code block with four spaces on each line. The backtick version is for short inline snippets. It’s a Markdown thing that’s not well communicated yet in the editor.

permalink
report
parent
reply
3 points
*

I think I fucked up the exit condition. It was supposed to create an infinite loops as it increments n, but always needs 1 more to exit.

permalink
report
parent
reply
2 points

What if you just told it to exit on n = -1? If it only increments n, it should also go on forever (or, hell, just try a really big number for n)

permalink
report
parent
reply
1 point
*

You need to put back ticks around your code `like this`. The four space thing doesn’t work for a lot of clients

permalink
report
parent
reply

Technology

!technology@lemmy.world

Create post

This is a most excellent place for technology news and articles.


Our Rules


  1. Follow the lemmy.world rules.
  2. Only tech related content.
  3. Be excellent to each other!
  4. Mod approved content bots can post up to 10 articles per day.
  5. Threads asking for personal tech support may be deleted.
  6. Politics threads may be removed.
  7. No memes allowed as posts, OK to post as comments.
  8. Only approved bots from the list below, to ask if your bot can be added please contact us.
  9. Check for duplicates before posting, duplicates may be removed
  10. Accounts 7 days and younger will have their posts automatically removed.

Approved Bots


Community stats

  • 16K

    Monthly active users

  • 13K

    Posts

  • 592K

    Comments