Basic question

I know this is very basic, I’m new to Python. What’s the problem with the below, is it even close to being correct? Thanks

def circle_calc(x,y):
    return (x*y)
y = 3.14
x = input("Input number ")
print (circle_calc)

Traceback (most recent call last):
File “main.py”, line 13, in
x = input(int("Input number "))
ValueError: invalid literal for int() with base 10: 'Input number ’

The order is off and since you haven’t formatted it I also I’m not sure about your indentation, here’s an example of a function that returns a value:

def output(name):
    name = input("What's your name? ")
    return name

the variable has to come before the return

7 Likes

the code in your error message:

x = input(int("Input number "))

is different from the code you posted:

x = input("Input number ")

anyway, here:

x = input(int("Input number "))

you try to convert the string "input number" to a integer, which won’t work. You first need to get input, and convert this input into an integer.

8 Likes

Thanks for the replies and apologies for the formatting.

Still struggling with it. What’s the problem with the below and what would the line be to convert the input to an int?

def circle_calc(x,y):
	y = 3.14
	x = input ("Input number")
	return x*y
print (circle_calc)
4 Likes

convert the input into an integer it’s initially a string,

int(input("Input number: "))

7 Likes

This now:-

def circle_calc(x,y):
	y = 3.14
	x = int(input("Input number: "))
	return x*y
print (circle_calc)

<function circle_calc at 0x7f574f67c200>

That line is asking for a representation of the function object. It is not an invocation.

We should note that the function expects x and y to receive values in the argument list of the function call. The values need to be passed into the function, not assigned locally.

def circle_calc(x, y):
    return x * y

print (circle_calc(10, 3.14))    # 31.4

One might have some preparation in advance of the call…

from math import pi as PI
diameter = int(input('Input diameter: '))
print (circle_calc(diameter, PI))
9 Likes