I am new to the world of Python, and this is my first program in Python. I come from the world of R so this is a bit unintuitive to me.
When I execute
In[15]: import math
...: import random
...: random.random()
...: math.sqrt(85)
...:
in interactive mode (i.e. on >>>
prompt), I get the output of math.sqrt()
. I don't see the random number at all. However, when I execute random.random()
and math.sqrt()
separately, I do get both the results. Why is this? How do I get both the results? I am asking this because I have the habit of selecting multiple lines in R and executing them in interactive mode, especially when I am trying to debug code. Executing only one line at a time will be excruciating when trying to debug, say, 2000-line code.
Here's what happens when I select multiple lines in R and then execute them:
runif(1,0,1)
sqrt(85)
It automatically parses these lines and generates the following output:
> runif(1,0,1)
[1] 0.01597949
> sqrt(85)
[1] 9.219544
I researched on SO and found Write multi-line statement on single line. I am unsure how to use the official answer from this thread.
Here's the output on PyCharm:
import math
import random
random.random()
math.sqrt(85)
Out[15]: 9.219544457292887
I am looking for some mechanism to see a random number and the sqrt of 85 without having to add any separator ,
or ;
, as I did in R code. I'd appreciate any thoughts.
Expected Input: One would run the code using "Execute Selection using Console" in PyCharm [Keyboard Shortcut: Alt + Shift + E]
import math
import random
random.random()
math.sqrt(85)
[Please note that I haven't used any separator ";" or ","--just as we do in R]
Expected Output:
random.random()
Out[16]: 0.183145720117748
math.sqrt(85)
Out[17]: 9.219544457292887