473,385 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Pycharm Not showing output

Hi guys, I just started learning python and i write a simple code using function but it is not showing me output in pycharm which i want it show me "Process finished with exit code 0" please help me out. Thanks in advance.


Expand|Select|Wrap|Line Numbers
  1. x="volvo"
  2. def myfunc():
  3. global x
  4. x="audi"
  5. print("This is " + x)
  6. myfunc()
Jan 22 '20 #1

✓ answered by SioSio

What results do you want?
"This is audi" or "This is volvo" ?
Expand|Select|Wrap|Line Numbers
  1. x="volvo"
  2. def myfunc():
  3.     global x
  4.     x="audi"
  5.     print("This is " + x)
  6.     return
  7. myfunc()
  8.  

13 4482
dev7060
636 Expert 512MB
There should be indentation in the body of the function.
Jan 22 '20 #2
Thanks for your reply but my indentation is correct i just showed my code above. And when you use pycharm it will auto adjust your python code into correct sequence but When i write in notepad ++ it shows me correct output.
Jan 22 '20 #3
dev7060
636 Expert 512MB
...but my indentation is correct i just showed my code above
No it is not.

And when you use pycharm it will auto adjust your python code into correct sequence but When i write in notepad ++ it shows me correct output.
This "auto-adjusting" thing may be placing the function call inside the function body which means the function is never called and hence no output.
Jan 22 '20 #4
Its very confusing this indentation part i mean to say when i write the above code in notepad ++ with correct indentation space it show me the output but not in pycharm. Pycharm automatically adjust correct indentation space when you write code in it.
Jan 22 '20 #5
SioSio
272 256MB
What results do you want?
"This is audi" or "This is volvo" ?
Expand|Select|Wrap|Line Numbers
  1. x="volvo"
  2. def myfunc():
  3.     global x
  4.     x="audi"
  5.     print("This is " + x)
  6.     return
  7. myfunc()
  8.  
Jan 23 '20 #6
Hi,as you can see my code i used global keyword to change global variable value "volvo" to "audi"
This set of code gives me output "This is audi" but my real question is whenever i use def myfunc() in pycharm it execute the code it and shows "process finished with exit code 0" instead of "This is audi"
Jan 23 '20 #7
SioSio
272 256MB
As dev7060 pointed out, it seems to be a problem with indentation.
Did the code shown in the previous reply not work?
Jan 24 '20 #8
Thanks buddy it works i have to use return whenever i want to call a function. I tried it with different set of codes. Works good.
Jan 25 '20 #9
dev7060
636 Expert 512MB
..i have to use return whenever i want to call a function..
Why would you return something from a function when there's nothing to return?
Jan 25 '20 #10
SioSio
272 256MB
Even better if I write "return None".
Explicit is better than implicit.
Jan 25 '20 #11
dev7060
636 Expert 512MB
Nowhere it is mentioned that writing it explicitly is considered a best practice. There's a time and place when to mention it explicitly. return None is never used if there are no other possible return values from the function. For example, the code posted by the OP where the function has only one path.
It does make sense in the following case:
Expand|Select|Wrap|Line Numbers
  1. def get_name(x):
  2.     if belong_to_US(x):
  3.         return x.name
  4.     else:
  5.         return None
  6.  
It is also used in the cases when there is a requirement to break out of a function early. But I find no significance of adding it to the OP's code.
Jan 25 '20 #12
SioSio
272 256MB
Title:
The Zen of Python
Author:
(Tim Peters)
Jan 25 '20 #13
dev7060
636 Expert 512MB
Should have provided the context to prove your point.
Jan 25 '20 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: MKoool | last post by:
I just installed python 2.4 for windows. I was using the cygwin version previously, but wanted to use the official python 2.4 release to install a module that reads off some registry entries. ...
6
by: R. Stormo | last post by:
I have a problem showing output that is comming from a script. If I make a script running at commandline it do work and everything are showing. But when I try to execute it from within my proggy...
9
by: Bryan Olson | last post by:
Here's a module to show stderr output from console-less Python apps, and stay out of the way otherwise. I plan to make a ASPN recipe of it, but I thought I'd run it by this group first. To use...
2
by: bildo | last post by:
Just loaded my Laptop with XP Pro, SQL 8.0, and IIS server for the first time. I installed student cd samples and they run fine on the browser for SQL and Access databases when i just type the url...
5
by: John Kotuby | last post by:
Hi all, This is my first time trying to creaet and use a custome Web Control in a Web Site project in ASP.NET 2.0 with VS 2005 and VB. I created the control in a separate Web Control Library...
0
by: =?Utf-8?B?ZGlzcGxheW5hbWU=?= | last post by:
The following code used to outputs to Excel 2003 fine. Do I need to change it to output to Excel 2007? <% Response.ContentType = "application/vnd.ms-excel" Response.AddHeader...
18
by: curi444 | last post by:
i installed wamp5 in windows xp.it shows all services are working.but when am opened a php file using browser it show a white page only,not show the out put. what is the reason?
5
by: Gwenne Moses | last post by:
Hello there, Pls help me with this. I want to output data from database(mySql).Output them in pdf form using FPDF (like a report). My problem is that, Not all the data from the db are being...
0
by: gurjit | last post by:
Hello, Pls help me with this. I want to output data from database(mySql).Output them in pdf form using FPDF (like a report). My problem is that, Not all the data from the db are being outputted....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.