Using backticks to format your code

prices={"banana":4,"apple":2,"orange":1.5,"pear":3}
stock={"banana":6,"apple":0,"orange":32,"pear":15}
for key in prices:
    print key
    print "price: %s" %prices[key]
    print "stock: %s" %stock[key]
2 Likes

Just in case someone curious end up here and is wondering what is the backticks thing he is talking about, here is the trick:

Whenever you would like to paste code, since this forum supports Markdown syntax you can use three backticks before and after your code block like so:

```
def my_func(x):
my_var = 0
if x > my_var:
sum = my_var + x
else:
print “Odelay!”
return sum
```

and it will retain proper indentation and even have nifty syntax highlighting:

def my_func(x):
    my_var = 0
    if x > my_var:
      sum = my_var + x
    else:
      print "Odelay!"
    return sum

The key to get a backtick character is highlighted in blue on this US keyboard layout:

12 Likes

In case anybody’s interested in slightly more complete guide than just showing how to use backticks to format code, there are two ways to format code:

1. Indent each line four spaces (can be done by highlighting code and pressing the </> button in the formatting bar)

    code
    is
    formatted
    with
    indentation

2. Put three backticks (`````) and a new line before and after the code:

```
code
is
formatted
with
backticks
```

Protip: If the syntax highlighting isn’t very good automatically (it’s usually pretty good, though), you can specify the language after the first three backticks:

```javascript
```python

And if you specify the language as text, it won’t highlight anything :slight_smile:

I hope this helps somebody!

10 Likes

Thanks @zystvan for the added content :slight_smile:

I also keep this markdown cheatsheet handy!

5 Likes

i :scream: :scream: still need help i don’t get it :scream: :rage:

1 Like

Hey @pewdiepielover,

Copy/paste this into your post, and replace “code here” with your actual code :slight_smile:

```
code here
```
1 Like

A post was split to a new topic: Need help in the Flipboard lesson

I still dont get how to post your code

1 Like

To format your code to make it visible:
1. Paste your code.
2. Select all of your code.
3. Do Ctrl + Shift + C (Windows) or CMD + Shift + C (Mac OSX) to format your code.

OR

1. Paste your code in.
2. Insert 3 backticks (`) before and after your code:

```
Code goes here
```
2 Likes

thanks @jibblyj i think i got it

2 Likes

Hello everyone :smile:

How to insert code into a post: put your code between back quotes …
How to add back quotes ?


Or click here to watch the video

Option 1: On your keyboard the key above tab

Option 2: type out your code, then select your code with your mouse/cursor then press Ctrl + Shift + C

Option 3: Type out your code select with mouse/cursor then click on the option preformatted text in CodeCademy toolbar


End result when you are typing out your code, in the right hand side box you should see code as well …

I hope you found this useful, feel free to like, share ect

4 Likes

YES! Useful!

I’m having problems with indenting, where I didn’t before; this, indeed, makes life that little bit easier - and why not!
Thanks for the tip.

2 Likes

Thank you! That’s very helpful!

1 Like