rainwater_stillicide

Challenge: BASIC001

30 posts in this topic

Once again Perl is awesome.


($a,$ = ($b,$a);

0

Share this post


Link to post
Share on other sites

In python:

a = 10

b = 20

a = a*2

b = a/2

Is this too simplified??

0

Share this post


Link to post
Share on other sites

In python:

a = 10

b = 20

a = a*2

b = a/2

Is this too simplified??

It's not too simplified (it does take two variables and swap them) but it doesn't do it in a general way, it will only work for certain numbers (i.e., where b = 2a).

Try and come up with a solution which can work for an arbitrary pair of numbers.

0

Share this post


Link to post
Share on other sites

In python:

a = 10

b = 20

a = a*2

b = a/2

Is this too simplified??

It's not too simplified (it does take two variables and swap them) but it doesn't do it in a general way, it will only work for certain numbers (i.e., where b = 2a).

Try and come up with a solution which can work for an arbitrary pair of numbers.

It is just too easy to do in Python. Don't make it too hard on yourself. Here is the easiest way to do it in Python.


a,b=b,a

0

Share this post


Link to post
Share on other sites

Old thread but...


a = 2
b = 3
print a, b
a, b = b, a
print a, b

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now