Login
|
Signup
langref.org
-
python
,
clojure
,
erlang
, and
fantom
add..
all
cpp
csharp
fsharp
go
groovy
haskell
java
ocaml
perl
php
ruby
scala
Home
All
Solved
Unsolved
Strings
Numbers
Regex
Lists
Maps
Structure
Files
Dates
OOP
Networking
XML
Algorithms
Misc
Parallel
View Problem
Strings
Declaration
Define a string containing variables and expressions
Given variables a=3 and b=4 output
"3+4=7"
python
class EvalDict(dict):
def __getitem__(s, k):
return eval(k, s)
a=3; b=4
"%(a)d+%(b)d=%(a+b)d" % EvalDict(locals())
class EvalDict(dict):
def __getitem__(s, k):
return eval(k, s)
a=3; b=4
"%(a)d+%(b)d=%(a+b)d" % EvalDict(locals())
python
a=3; b=4
"%d+%d=%d" % (a, b, a+b)
a=3; b=4
"%d+%d=%d" % (a, b, a+b)
clojure
(format "%d + %d = %d" a b (+ a b))
(format "%d + %d = %d" a b (+ a b))
erlang
A = 3, B = 4,
io:format("~B+~B=~B~n", [A, B, (A+B)]).
-module(stvarexp).
-export([start/0]).
start() ->
A = 3, B = 4,
io:format("~B+~B=~B~n", [A, B, (A+B)]).
fantom
echo("$a+$b=${a+b}")
class SolutionXX
{
static Void main()
{
echo("$a+$b=${a+b}")
}
}
Submit a new solution for
python
,
clojure
,
erlang
, or
fantom
There are 25 other solutions in
additional
languages (
cpp
,
csharp
,
fsharp
,
go
...)