+ 8

I am very weak at functions😑😑

I am currently learning python and there functions always give me error. Is there a way i can learn functions more and strengthen my concepts??

4th Sep 2020, 5:40 PM
Kairav Bhatia
Kairav Bhatia - avatar
20 odpowiedzi
+ 5
Kairav Bhatia , Please work through this lessons, these are the basics of defining and using functions. https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2285/ https://www.sololearn.com/learn/Python/2286/ https://www.sololearn.com/learn/Python/2287/ When you feel a bit familiar with it, try the following task: (The following code takes 2 string: a first name and a last name) first_name = input('your first name: ') last_name = input('your last name: ') print('your name is', first_name, last_name) (you can take this code and run it to see the output) -> Your task is now to rework this code, so that the input and output will be done in a user defined function. All the information you need for this task is written in the the 3 lessons above. I am sure you can solve this. After this we will see the next steps. Happy coding! !!! If you run the code in playground, the input prompt will not been shown. A window will pop up and enable you to give 2 inputs.The input has to be like: Paul Simon (then tap submit)
5th Sep 2020, 11:54 AM
Lothar
Lothar - avatar
+ 7
If you use the variable in a loop, in your function, just before the loop start, give an amount to your variable. for ......... : counter += 1 The above code causes error if you didn't give an amount to counter before loop. So give it 0 for example before loop: counter=0 for ... : counter += 1 If the variable is string give it empty string before loop: mystr='' while ......... : mystr = mystr + new
4th Sep 2020, 6:31 PM
Khashayar Saghafi
Khashayar Saghafi - avatar
+ 6
What is your problem: Is it using build-in-functions that are provided from python like string functions, or do you have a problem in creating and using user defined functions? If you expect to get a good answer, we have to know where exactly your problem is. But this is not possible at the moment, because we can only guess what makes you struggle. So please provide us some code that illustrates your issues. Thanks!
4th Sep 2020, 6:29 PM
Lothar
Lothar - avatar
+ 4
As just Trying is the best way to learn I suggest you to do so.. You can post your not working codes and we will try to help you..... Maybe there is only a simple problem.....
4th Sep 2020, 5:42 PM
Alexander Thiem
Alexander Thiem - avatar
+ 3
Jan Markus Try deadlifts and bent-over row... After three months of serious training you will destroy the latissimus machine with your new strength!
4th Sep 2020, 6:48 PM
Crash
Crash - avatar
+ 3
Never do say uncle! It's gonna be alright step by step✌💪😉
5th Sep 2020, 8:35 PM
Saleh Ghazimoradi
Saleh Ghazimoradi - avatar
+ 2
Try to make everything a function, start out with simple functions. If you need help this is the best place to ask questions and get help. Are there any functions in particular that you can share with us, we can probably help point out some things that would make them more clear. https://code.sololearn.com/cgYRQ964kt3e/#py https://code.sololearn.com/c22WYGcF5CvG/#py https://code.sololearn.com/cTg2aoRlCEue/#py
4th Sep 2020, 6:00 PM
Steven M
Steven M - avatar
+ 2
Lother, i have problems with 'def' Or while defining functions not with inbuilt ones
4th Sep 2020, 7:07 PM
Kairav Bhatia
Kairav Bhatia - avatar
+ 2
Practice makes perfect.
5th Sep 2020, 9:08 AM
Sonic
Sonic - avatar
+ 2
The Sololearn tutorial for Python will explain this. Try to go and have a look through it.
5th Sep 2020, 10:44 PM
Sonic
Sonic - avatar
+ 2
If you come across something you don't understand, e.g. the meaning of the return statement do a search in this Q&A area for similar questions and try to see if there are any useful answers.
5th Sep 2020, 10:47 PM
Sonic
Sonic - avatar
+ 2
You can even type questions into the search bar of your web search engine to find answers from various sources.
5th Sep 2020, 10:49 PM
Sonic
Sonic - avatar
+ 2
Go through sololearn lessons slowly. Also try to practice some extra function codes. Make use of comment section too as it gives us more ideas.
6th Sep 2020, 8:01 AM
Amina Sajan
+ 1
What kind of error you got, only the name of the error would tell a lot.
4th Sep 2020, 5:58 PM
Seb TheS
Seb TheS - avatar
+ 1
I get problems like , i always get output 0 and many times that the variable doesn't exist and something like that
4th Sep 2020, 6:05 PM
Kairav Bhatia
Kairav Bhatia - avatar
+ 1
Functions are just lines of codes grouped and have a common name. Example Def morningRoutine: Getup Brush your teeth walk for 10 minutes eat breakfast Read books Code These are just steps in someone's morning routine. just like that a function, contains multiple lines of codes that do different things individually, but give a different result in group. Hope it's helpful
5th Sep 2020, 7:30 AM
Aman
Aman - avatar
+ 1
Make you own functions using "def"
5th Sep 2020, 9:42 AM
Aarav Baid
Aarav Baid - avatar
+ 1
Functions always return a value in any programming language 🙄
6th Sep 2020, 2:49 AM
Sanjay Kamath
Sanjay Kamath - avatar
0
Some tips 1.Mind the scope of variables used in function or defined outside the function 2.Use variable after defining it , don't define after call for variable 3.mind the case of alphabates in variables name.python is case sensitive.
4th Sep 2020, 6:31 PM
Divya Mohan
Divya Mohan - avatar
0
How do you get this output 0? Could you just post a example code here? Are you getting 0 or none? If you are getting none, then this ks because your function does not has a return statement If you get „The variable does not exist“ then this mainly has a reason...... You can not access a variable, which you did not set to a certain value before. Moreover variables defined within a function are not accessible outside that function..... 0 def f(): 1 x=3 2 3 print(f()) 4 print(x) >>none >>Variable „x“ does not exist In line 0 and 1 I defined the function f, which sets x to 3. In line 3 I called that function and printed the returned type. Nothing was returned, so Python printed „none“ (default returned value) In line 4 I want to print x. This results in a error, because x is only accessible in the function... If you could post a code we could try to improve it together...
4th Sep 2020, 7:05 PM
Alexander Thiem
Alexander Thiem - avatar