Login Register






Not outputting filter_list
Author
Message
Not outputting #1
Started learning python today. Easy, but this thing has me puzzled.

Isn't this suppose to output?

Code:
Def full_name(): First = input('enter first name: ') Last = input('last name here: ') Return first + last Full_name()

Somewhat it doesn't output?







Reply

RE: Not outputting #2
im gonna hazard a guess that full_name() != Full_name()

Reply

RE: Not outputting #3
Error 1: Don't confuse yourself with Caps and Smalls. If you have used a function Full_name(), then call full_fame() and not Full_name.
Similarly, if you use a variable first, then use first everywhere for it and not First.


Error 2: Indent your code properly.
Look where your code calls the full_name function. Its inside the function block itself [Recursive function?]
Remove the whitespace before the full_name() function call to pull it away from the function block.

Here is the correct code:
Code:
def full_name(): first = input('enter first name: ') last = input('last name here: ') print first + last full_name()

And you got to use def instead of Def.
Then you have to use the print function to get the output on screen. You did not print the values, you just used Return.

Now, the output:
Quote:enter first name: Alok
last name here: Sharma
AlokSharma <----- the output

So, the space between first and last name is missing. So, we will use a better code.
Code:
def full_name(): first = input('enter first name: ') last = input('last name here: ') print "%s %s" % (first,last) #The first %s is replaced by the value of first variable in braces [first] and the second one with [last] ans the space in between. full_name()
Now this gives out the following Output:
Quote:enter first name: Alok
last name here: Sharma
Alok Sharma <----- a better output

Now, something more better:
Code:
def full_name(): first = input('enter first name: ') last = input('last name here: ') print "Dear %s %s, Welcome to Hackcommunity!" % (first,last) full_name()
Now this gives out the following Output:
Quote:enter first name: Alok
last name here: Sharma
Dear Alok Sharma, Welcome to Hackcommunity! <----- a far better output

Best of luck.
[Image: MUJ8qSW.png]
-----------------------------------
Now learning:
Android Development, Java
Working on:
An FTP Client for Android
-----------------------------------

Reply

RE: Not outputting #4
1) Variable names are case sensitive, BlueCat and blueCat are 2 different Variable names. Also the definition of a function is done by def not Def, also it's return

Code:
def full_name(): First = input('enter first name: ') Last = input('last name here: ') return First + Last full_name()

we've got our first error now second

2) You've called the full_name() function inside itself, but hang on! You didn't actually call if on the outside, that is why you are not getting any prompt. So change the code:

Code:
def full_name(): First = input('enter first name: ') Last = input('last name here: ') return First + Last full_name()

Since you want to print the string First and Last combined, we will use the print() function because it outputs the string to the console whereas the return function you used simply exits the function and give the value of that function to what called it. Hence,

Code:
def full_name(): First = input('enter first name: ') Last = input('last name here: ') print(First + Last) full_name()
My Blog: http://www.procurity.wordpress.com
Donations: 1HLjiSbnWMpeQU46eUVCrYdbkrtduX7snG

Reply

RE: Not outputting #5
As I've said in another thred. I'm on my phone so it automatically puts them in capitals. And thanks both of you







Reply

RE: Not outputting #6
I would advice you to stop posting code from your phone. It only opens up for more confusion.

Reply

RE: Not outputting #7
(06-17-2014, 01:10 AM)BlueCat Wrote: Started learning python today. Easy, but this thing has me puzzled.

Isn't this suppose to output?

Code:
Def full_name(): First = input('enter first name: ') Last = input('last name here: ') Return first + last Full_name()

Somewhat it doesn't output?

return First + Last
should work

I think your variables are capitalized and the return isn't .

Reply