## How to add two numbers?

This is the place for queries that don't fit in any of the other categories.

### How to add two numbers?

Figured we needed at least one coding post.

So how do I get a result of adding a and b?
My code gives me "SyntaxError: can't assign to operator":
Code: Select all
`a = 2b = 2a + b = cprint c`
Friendship is magic!

R.I.P. Tracy M. You will be missed.

stranac

Posts: 1790
Joined: Thu Feb 07, 2013 3:42 pm

### Re: How to add two numbers?

Hey

You see how you wanted the variable a to contain the value of 2, so you have the a first followed by = (which means assign) and then the 2,
to assign the value of a + b to c, the c needs to go first and then assign it using = to the result of adding a + b.
The altered code is shown below.

Code: Select all
`a = 2b = 2c = a + bprint c`
Due to the reasons discussed here we will be moving to python-forum.io/ on October 1 2016
This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.

Yoriz

Posts: 1672
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

### Re: How to add two numbers?

That was really helpful - thanks!

How do I get Python to display "Hello, World" on a blank screen?
Quanto lignum posset materiae materietur marmota Chuck si materiam possit materiari foedans, penitus lignum?
KevinD

Posts: 29
Joined: Fri Feb 08, 2013 3:15 am

### Re: How to add two numbers?

Thanks, Yoriz!
That worked.

KevinD:

Even I know that one.
You use print for that, like my 'print c'.

This should work:
Code: Select all
`print '"Hello, World"'`
Friendship is magic!

R.I.P. Tracy M. You will be missed.

stranac

Posts: 1790
Joined: Thu Feb 07, 2013 3:42 pm

### Re: How to add two numbers?

When I run this code:
Code: Select all
`print '"Hello, World"'`
I'm getting this weird problem:
Code: Select all
`SyntaxError: invalid syntax`

What the heck am I doing wrong?
New Users, Read This
• Use code tags when posting code.
• Include any errors with your post (in code tags).
• Describe your problem; not your chosen solution.
• Make examples the minimum length to demonstrate your issue.

Mekire

Posts: 1711
Joined: Thu Feb 07, 2013 11:33 pm
Location: Tucson, Arizona

### Re: How to add two numbers?

Mekire wrote:When I run this code:
Code: Select all
`print '"Hello, World"'`
I'm getting this weird problem:
Code: Select all
`SyntaxError: invalid syntax`

What the heck am I doing wrong?

I'm guessing you are using python 3, print changed to a function so you need to use print like this.
Code: Select all
`print('"Hello, World"')`

Due to the reasons discussed here we will be moving to python-forum.io/ on October 1 2016
This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.

Yoriz

Posts: 1672
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

### Re: How to add two numbers?

Can we think of any more pre-beginner questions to post?
Quanto lignum posset materiae materietur marmota Chuck si materiam possit materiari foedans, penitus lignum?
KevinD

Posts: 29
Joined: Fri Feb 08, 2013 3:15 am