Passing a keyboard input into a function

num = input()
def f(a):
add = a + 1
return add
def p(b):
add2 = b + 3
return add2
print(p(f(num)))

So this is my code, what it is supposed to do is take a input into function f(), then add 1, then pass variable add onto function p() which adds 3, then it is supposed to print out the inputed number
Ex: num = 1
Code would print out: 5

Can yall please help me figure out if this is possible and if so, how to do this?

Please use the </> preformatted text button to show your code with the indentation as you wrote it.

I think the code is good except for one thing.

The input function returns a string and you need to convert the
string into an integer.

num = int(input())

Beware that if you do not enter a number you will see an error reported.
We can show you how to handle errors if you wish as a follow up.

1 Like

Oh I’m really new to this forum page, let me fix the code real quick.

Thanks for telling me the fix! I got it to work! :smiley:

The 2 lines after each def line need to be indented.

I am on mobile so i can’t do that at the moment.
How do i mark a post as solved?

Alas, I’m not sure you can. - Cameron Simpson cs@cskk.id.au