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
Font size 10 being understood as Font size 14 in HTML Basics II
23. Many selectors, many properties
5/11-6/11 Says its wrong, still accepts it but later won't
5., 6. & 7. Some best practices to avoid errors
9/9 Unexpected Indent
Exercises 6. and 8. - Common problems
Error Messages on Lists Within Lists
5/8 stuck
How to make image and text responsive next to each other on a background?
5., 6. & 7. Some best practices to avoid errors
Innovation Cloud Project
Can't get pass 92% Neighborhood Guides: Images 2
I Don't understand my mistakes on exercice "3. ArrayList"
Do you want to improve your coding skills?
3. Error msg: Add the class "pull-left", or "pull-right"
Given me an error syntax while coding object oriented programing,OOP LAB quiz 3,please where im i missing it?
5/19 Functions Calling Functions Help
Problem with 9
Images and Links1 - In-completing
I'm not sure the images on here verses the actual code but here is another try
TypeError: 'list' object is not callable
Where is the problem I don't understand this lesson help me
Where I fault ? help me
When will the projects be working again?
Locked my self out of my account
Need Help with MOVE - supporting content
7/11 creating class methods
Revoke course registration?
8. Error msg: Set the border-bottom to '1px solid #dbdbdb'
What features do you want to see in a Pro Product?
Paid, charged but no Pro account | Payment issue
A cool code
Unable to find error in my jquery progaram
Exercises 6. and 8. - Common problems
Listing Everybody
The Big if()
Help with 4/6 please!
Innovation Cloud btn:hover
Project "Best Bite"
I cant figure divisions
Plz help on part 8 says that the second paragraph is sixe 16 when it should be 10!
I am stuck on lesson 12 of css: an overview, help plz
Python Codebit Question?
Hangman simulator, Unindent Does not match any outer indentation level
Where I fault ? help me
4. Displaying the Balance
Compressing text
The big if, the flying circus
Not able to access movies database from /actors
6.5 Show a destination (link_to "See more")
8: Part of the Whole. What am I doing wrong?
How much dedicated RAM do I need to run Codecademy?
4. What is wrong with my code?
Python Paddleball Game
Need help with 23?
5. Filters II unable to display pubdate via index.html
Slip and slide
9.2 <p class="likes">+ {{ product.likes }} </p>
Cant find my error
jQuery lesson 3-11
Lesson 18: Show It If You Know It! Color not changing
Please someone help me with if statement
I need help on 2. Taking up space
5/19 Functions Calling Functions Help

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
Can someone explain how to take a screen shot?
Question 12
I dont get it
HTML Basics ll Question on Font Size
Can anyone help?
Psuedo selectors
Multiple selectors
Font Family
2. Multiple Selectors
HTML and CSS font error?
I cannot make my second div apear
After writing this i am getting an error in submit button
Lesson 5: link it up, IDK what to do!
Introduction-so confused
HTML AND CSS link error?
Can't see my footer
About You- Make sure you have defined all the variables?
Code Processing Error
Stuck on question 13
HTML Basics II -Exercise 10 - Font-family error
Problem with Question 11....cant we take image from desktop or otherwebsite
There is an error message popping up: $expect is not defined"
[reported #34] 7. font-size: 2rem; fails despite being correct
Is there a bug in question 11?
Font size error
Making a website lesson 5 Anchor elements
None of the image link addresses I use work in editor
<p> tags are nested error
[reported #34] 7. font-size: 2rem; fails despite being correct
Submenu in bootstrap 3
What did I do wrong
I am also having trouble on 5. Anchor Elements
Lesson 21 need help
22/26 dont understand
13: Putting It All Together
Cant remember the code to change the font?
Cant remember the code to change the font?
Comments
This code is not wrking
Lesson 10
Lesson 4 no text on webpage
Topic 26
Still stuck on Clickable Photo Page
7 making comments confused still at beggining code NEED HELPPPP
Comments
Css/html
I cannot move forward, help please (12 сss)
One Selector to rule them all error
My friend 'circles' are actually squares!
Oops, try again. It looks like your header's font-size is 32px instead of 16px
Pseudo selector
Please Help! Font size and color
Style sheet

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