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

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

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