Guide to Asking Coding Questions
h
Mosrod (294)

Guide to Asking Coding Questions

Why?

Good questions help your question be solved faster, and people will want to answer your question

Bad questions waste time, you will often not get answers that you asked for, and people will often ignore your questions

Quick Questions Guide

Do This

  • Always ask your questions in English
  • Explain what you want the code to do
  • Explain what the code does
  • Include error messages
  • Share the repl with the line numbers
  • When you figure out the answer, update your post
  • Put the repl link, instead of pasting code

Don't Do This

  • Don't post homework questions
  • Don't use caps in the title
  • Don't use words like 'HELP' or 'PLEASE' in the title
  • Don't post questions that already have an answer (Search Box)
  • Don't post feedback or bugs on Talk, use repl.it/feedback for feedback, or repl.it/bugs for bugs

Steps For Better Questions

  1. Understand the code

    • Read your code and figure out what each line does
    • If a concept is unfamiliar, Google it
    • You can also use a debugger to help you
  2. Describe the problem

    • Explain what you want the code to do
    • Explain what the code does (error messages)
  3. Provide the code

    • Share a repl that has your code
    • Share the line number(s) of your code issue
    • Make sure that the code you shared has the issue
  4. Format code consistently

    • Make sure your code is easy to read
  5. Check for typos

    • Make sure the code does not have any typos that would cause the problem
  6. Explain what you did to troubleshoot the problem

    • Make a list of what you think the problem is and try to fix your problem by going through the list
  7. Make a guess on what you think the problem might be

    • Use the list from the previous step
  8. Proofread the question

    • Make sure you provided everything
    • Clear all confusions that you think there might be
  9. Update people on the question

    • If you figured out the answer, edit the post to tell people
    • When you get an answer, fully understand it
    • Be nice to people who answer your question
    • Remember that the people wanted to answer your question, but didn't have to
  10. Things to NOT do

    • Don't post homework questions
    • Only post questions in English
    • Do not use caps in the title
    • Do not use "HELP" or "PLEASE" in the title
    • Don't post questions that have already been answered (Use search box)
    • Don't post feedback or bugs on Talk, use repl.it/feedback for feedback, or repl.it/bugs for bugs

Example:

Question

We have some Python code with an error: repl

rannumexe = int(input())
if rannumexe = 1:
    print('hi' + rannumexe)

Step 1

We show what each line does using comments.

rannumexe = int(input())  # Asks the user to input a rannumexe
if rannumexe = 1:  # If the rannumexe equals 1
    print('hi' + rannumexe)  # Print hi and the rannumexe

Step 2

We want the code to input a number, and if the number is one, print "hi" and the number.

Our problem is that we have an invalid syntax error on line 2 in the main.py file.

  File "main.py", line 2
    if rannumexe = 1:
                 ^
SyntaxError: invalid syntax

Step 3

Our repl with the issue is located here.

We have an issue on line 2

Step 4

We can change "rannumexe" to "number" to clear confusion

number = int(input())  # Asks the user to input a number
if number = 1: # If the number equals 1
    print('hi' + number)  # Print hi and the number

Step 5

We don't have any typos

Step 6

Our problem could be that we improperly used the if statement

Step 7

The problem could be about using the if statement incorrectly

Step 8

Our final question:

Title:

Invalid syntax error about equal signs

Content:

I have an invalid syntax error on line 2 in the main.py file of this repl. The program should take a number as an input, check if the number is equal to one, and if so, print "hi" and the number. The error point to the equal signs and I think this issue is with the incorrect syntax of the if statement. Help is appreciated :).

number = int(input())  # Asks the user to input a number
if number = 1: # If the number equals 1
    print('hi' + number)  # Print hi and the number
  File "main.py", line 2
    if rannumexe = 1:
                 ^
SyntaxError: invalid syntax

Steps based on Gordon Zhu's post.

If you have any suggestions or feedback, post it in the comments below.

You are viewing a single comment. View All
DUN0040 (2)
def start(name):
  while True:
    cmd = input(name+"#local.mail> ")
    if cmd == "exit" or cmd == "e":
      ("Exited mail")
      break
    elif cmd == "ls" or cmd == "list":
      for root, dirs, files in os.walk("local/mail"):  
        for filename in files:
          print(filename)
    elif cmd == "r" or cmd == "read":
      arg = input("Mail subject: ")
      try:
        m = open("local/mail/"+arg,"r")
        if arg == "Good!":
          replit.clear()
          print("\n"+m.read()+"\n")
          input("[ENTER] to continue...")
          ("Good job. You beat the game! That is all for now. I worked on this completely in school! Hope you enjoyed.")
          sys.exit()
        else:
          print("\n"+m.read()+"\n")
      except (FileNotFoundError, IsADirectoryError):
        g("Can't find email! Does it exist?")
    elif cmd == "h" or cmd == "help":
      g("\nMAIL HELP\nlist (ls) - List all emails\n(r)ead - Read an email\n(e)xit - Exit mail\n")

This entire thing isn't working. I want to hide the Translation Response until you look at the Intercepted Email but it shows up at the start no matter what even though it is supposed to be hidden. Someone please help me.

def start():
  while True:
    cmd = input("T.I.D> ")
    if cmd == "m" or cmd == "mail":
      while True:
        cmd = input(colored("T.I.D.mail> ","green"))
        if cmd == "exit" or cmd == "e":
          g("Exited mail")
          break
        elif cmd == "ls" or cmd == "list":
          for root, dirs, files in os.walk("T.I.D/mail"):  
            for filename in files:
              print(filename)
        elif cmd == "r" or cmd == "read":
          arg = input("Mail subject: ")
          if arg == "Intercepted Email":
            nm = open("local/mail/Translation Response")
            nm.write("Subject: Translation Response Good job. As soon as you had decoded it we had moved it onto our computer and deleted it from yours. So if you didn't get to see it it was: The plan is almost in motion. I have the lithium that we needed. Now we just need to get the mercury and the plan will come into action. S8;cAs Ash Morgan We don't know what the last jumble of characters mean but possibly it is the password to Ash Morgan's computer. Once again, good job. I have decided to put you up for promotion with L. (The Boss) You better not screw it up anymore like you have in the past. The entire world's counting on you. X")
            nm.close()
            sEnding.ending = True
          try:
            m = open("T.I.D/mail/"+arg,"r")
            print("\n"+m.read()+"\n")
          except (IsADirectoryError, FileNotFoundError):
            g("Can't find email, does it exist?")
    elif cmd == "ls" or cmd == "list":
      for root, dirs, files in os.walk("TID/files"):
        for filename in files:
          print(filename)
    elif cmd == "clear":
      replit.clear()
    elif cmd == "r" or cmd == "read":
      arg = input(colored("File name: ","green"))
      try:
        f = open("steve/files/"+arg,"r")
        print("\n"+f.read()+"\n")
      except:
        g("Unable to read file, does it exist? Remember to include the file extension.")
    elif cmd == "h" or cmd == "help":
      g("\nHELP\n(h) - Display this menu\n(r)ead - Read a file on the computer\nlist (ls) - List all files on the computer\n(m)ail - Open the mail application\n(e)xit - Exit the computer")
    elif cmd == "e" or cmd == "exit":
      g("Exited computer")
      break
    else:
      g("Unknown command: "+cmd)

I think it's in here but I'm not sure.

Mosrod (294)

@DUN0040 Ask your question in https://repl.it/talk/ask so helpers get notified.