Login
|
Signup
langref.org
-
python
add..
all
clojure
cpp
csharp
erlang
fantom
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)
Submit a new solution for
python
There are 28 other solutions in
additional
languages (
clojure
,
cpp
,
csharp
,
erlang
...)