Click here to Skip to main content
15,920,708 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Basicly what i want to happen is the user inputs a number and one gets subtracted from said input.
updated after solution 1

What I originally had
b = input(int("pick a number")
def test(t):
	t-1
	return t
print(b test)

When i run it from the terminal i get:
def test(t):
  ^
SyntaxError: invalid syntax

************************************************************

What i have now


def test(t):
	return t-1
b = input("pick a number")
print (test(b))

However i still get an error
Traceback (most recent call last):
  File "deftest2.py", line 5, in <module>
    b = input(int("pick a number"))
ValueError: invalid literal for int() with base 10: 'pick a number'
</module>

I have tried taking out the "int" from input but i still get errors.



Thank you for your time.
Posted
Updated 20-Aug-11 10:49am
v5

This is not because of def. The def part is correct, except one bug: you don't subtract one, because the result of subtraction is lost; you return unchanged t.

Should be:

def test(t):
    return t - 1


The error is shown due to the previous line, which is simply gibberish; hard to understand how did you want to get b. The error on def is shown because brackets on the previous line are not balanced.

From the context, one can guess that you wanted to get b from user's input. In this case, you should have done:

def test(t):
    return t - 1

parameter = input("Input numeric parameter: ")
print test(parameter)


—SA
 
Share this answer
 
The input is a string, so that is what you need to convert to an int:

def test(t):
  return t-1

b = int(input("pick a number"))
print(test(b))
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900