+ 1

I cant find the error here

Here the percentage consumed cant be found out and also saying tha 'cntr' is not defined while i defined it before https://code.sololearn.com/c9eI464BQA0B/?ref=app

30th Jun 2019, 6:50 AM
Y AD Ù
Y AD Ù - avatar
6 Respuestas
+ 4
I think the best way to handle it would be to let one function return the word count and let the other function do something with it. No global variables needed. Right now, your read() function returns a string which I think is rather unexpected. Either have it print the string or return the word count. Having multiple variables access/change global variables can cause problems, especially if your program gets more complex (or you start using threads etc.)
30th Jun 2019, 7:28 AM
Anna
Anna - avatar
+ 4
Adding to Airree, here's how: define it outside functions, then inside each function add this line: global cntr
30th Jun 2019, 7:05 AM
Mo Hani
Mo Hani - avatar
+ 3
Exactly: cntr isn't defined. Its scope is inside the read function, so when the function finishes, it will not exist anymore. If you want it to work, you should maybe declare it in a global scope
30th Jun 2019, 7:03 AM
Airree
Airree - avatar
+ 2
Declare cntr in a global scope
30th Jun 2019, 7:05 AM
Airree
Airree - avatar
+ 2
Yes Anna is saying right but still may another way
30th Jun 2019, 9:34 AM
Tanuraj singh
Tanuraj singh - avatar
+ 1
Ohhh is it ....so how can i do it Airree
30th Jun 2019, 7:04 AM
Y AD Ù
Y AD Ù - avatar