![]() |
|
Not outputting - Printable Version +- Sinisterly (https://sinister.li) +-- Forum: Coding (https://sinister.li/Forum-Coding) +--- Forum: Python (https://sinister.li/Forum-Python) +--- Thread: Not outputting (/Thread-Not-outputting) |
Not outputting - BlueCat - 06-17-2014 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? RE: Not outputting - The Real Slim Shady - 06-17-2014 im gonna hazard a guess that full_name() != Full_name() RE: Not outputting - alok9shm - 06-17-2014 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 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()Quote:enter first name: Alok 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()Quote:enter first name: Alok Best of luck. RE: Not outputting - Ex094 - 06-17-2014 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()RE: Not outputting - BlueCat - 06-17-2014 As I've said in another thred. I'm on my phone so it automatically puts them in capitals. And thanks both of you RE: Not outputting - Anima Templi - 06-17-2014 I would advice you to stop posting code from your phone. It only opens up for more confusion. RE: Not outputting - Cosh - 06-21-2014 (06-17-2014, 01:10 AM)BlueCat Wrote: Started learning python today. Easy, but this thing has me puzzled. return First + Last should work I think your variables are capitalized and the return isn't . |