1

How would I be able to convert for example, turn 45 to turn(45)? Or in general reverse AnyValue to reverse(AnyValue) in python?

The user input could be:

reverse 45

And then the output could be:

reverse(45)
1
  • 2
    Welcome to Stack Overflow! It looks like you want us to write some code for you. While many users are willing to produce code for a coder in distress, they usually only help when the poster has already tried to solve the problem on their own. A good way to demonstrate this effort is to include the code you've written so far, example input (if there is any), the expected output, and the output you actually get (console output, stack traces, compiler errors - whatever is applicable). The more detail you provide, the more answers you are likely to receive. Commented Nov 18, 2012 at 15:04

2 Answers 2

2

You could use a regular expression to add the parenthesis around your numbers:

import re

s = "reverse 45"
output = re.sub(r'reverse (\d+)', r'reverse(\1)', s)
Sign up to request clarification or add additional context in comments.

Comments

-1
    python 3.2
    a = reverse 45
    a.replace(" ","(") + ")"

1 Comment

a = reverse 45 is not a valid Python syntax. Neither is python 3.2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.