A lot of confusion is caused by the print function converting an integer or
float
to a string before printing to console. thus both '1234 and '1234' are
shown as
1234 on the console. Similarly '15.4' and 15.4 are displayed as 15.4. There
is no way
to tell which is a string, which is an int and whic
On Wed, Apr 12, 2017 at 4:03 AM, boB Stepp wrote:
>
> I have not used the decimal module (until tonight). I just now played
> around with it some, but cannot get it to do an exact conversion of
> the number under discussion to a string using str().
Pass a string to the constructor:
>>> d =
On Wed, Apr 12, 2017 at 3:40 AM, boB Stepp wrote:
>
> I have to say I am surprised by this as well as the OP. I knew that
> str() in general makes a nice printable representation
The single-argument str() constructor calls the object's __str__
method (or __repr__ if __str__ isn't defined). In Py
On Tue, Apr 11, 2017 at 3:43 PM, Alan Gauld via Tutor wrote:
> On 11/04/17 19:44, Mats Wichmann wrote:
>
>> import decimal
>>
>> Pi_Number =
>> str(decimal.Decimal(3.14159265358979323846264338327950288419716939))
>>
>
> Unfortunately that doesn't work either:
>
" " + str(decimal.Decimal(
>
On Tue, Apr 11, 2017 at 2:18 PM, Marc Tompkins wrote:
> On Tue, Apr 11, 2017 at 9:48 AM, Rafael Knuth
> wrote:
>
>> I tested this approach, and I noticed one weird thing:
>>
>> Pi_Number = str(3.14159265358979323846264338327950288419716939)
>> Pi_Number = "3" + Pi_Number[2:]
Minor note: If the
On 11/04/17 19:44, Mats Wichmann wrote:
> import decimal
>
> Pi_Number =
> str(decimal.Decimal(3.14159265358979323846264338327950288419716939))
>
Unfortunately that doesn't work either:
>>> " " + str(decimal.Decimal(
... 3.14159265358979323846264338327950288419716939))
' 3.1415926535897931
On 04/11/2017 10:48 AM, Rafael Knuth wrote:
> Thanks for the clarification.
> I tested this approach, and I noticed one weird thing:
>
> Pi_Number = str(3.14159265358979323846264338327950288419716939)
> Pi_Number = "3" + Pi_Number[2:]
> print(Pi_Number)
>
> == RESTART: C:\Users\Rafael\Documents\
On 11/04/17 17:48, Rafael Knuth wrote:
> Pi_Number = str(3.14159265358979323846264338327950288419716939)
> Pi_Number = "3" + Pi_Number[2:]
> print(Pi_Number)
> 3141592653589793
>
> How come that not the entire string is being printed, but only the
> first 16 digits?
There are two problems h
On Tue, Apr 11, 2017 at 9:48 AM, Rafael Knuth
wrote:
> I tested this approach, and I noticed one weird thing:
>
> Pi_Number = str(3.14159265358979323846264338327950288419716939)
> Pi_Number = "3" + Pi_Number[2:]
> print(Pi_Number)
>
> == RESTART: C:\Users\Rafael\Documents\01 - BIZ\CODING\Python
>
>>> b = "3"+b[2:] #Removing the decimal point so that there are digits only in
>>
>> my_number = 3.14159
>
> Here you assign a floating point number to mmy_number but
> the code Sama wrote was for working with strings read
> from a text file.
>
> You would need to convert it first:
>
> my_number =
On 2017-04-08 05:49, Rafael Knuth wrote:
Dear Sama,
thank you so much for your explanation and sorry to bother you on the
same subject again.
I learn the most by taking code apart line by line, putting it
together, taking apart again, modifying it slightly ... which is
exactly what I did with yo
On 08/04/17 13:49, Rafael Knuth wrote:
>> b = "3"+b[2:] #Removing the decimal point so that there are digits only in
>
> my_number = 3.14159
Here you assign a floating point number to mmy_number but
the code Sama wrote was for working with strings read
from a text file.
You would need to conve
Dear Sama,
thank you so much for your explanation and sorry to bother you on the
same subject again.
I learn the most by taking code apart line by line, putting it
together, taking apart again, modifying it slightly ... which is
exactly what I did with your code.
On Tue, Apr 4, 2017 at 3:20 PM, D
On 2017-04-03, Mats Wichmann wrote:
> If you're talking about 4-digit year numbers using a Western
> calendar in digits of PI, the overlap effect seems unlikely to
> matter - let's say the year is 1919, do we think PI contains
> the sequence 191919? count would report back one instead of two
> in
On 04/04/17 12:04, Rafael Knuth wrote:
> Sarma: thank you so much, I checked your code, it works. However, can
> you enlighten me what it exactly does?
It just iterates over the PI string manually and compares
the birth date with the first 4 PI string characters.
It would probably be more pythoni
Sarma: thank you so much, I checked your code, it works. However, can
you enlighten me what it exactly does?
I do not understand it (yet). Thank you in advance.
file_path = "C:/Users/Rafael/PythonCode/PiDigits.txt"
with open (file_path) as a:
b = a.read()
get_year = input("What year were you
Small correction.
file_path = "C:/Users/Rafael/PythonCode/PiDigits.txt"
with open(file_path) as a:
b = a.read()
get_year = input("What year were you born? ")
count = 0
b= '3'+b[2:]
n = len(b)
for i in range(n-3):
if b[i:i+4] == get_year:
count += 1
print("Your birth date occurs %
On 04/04/17 00:37, D.V.N.Sarma డి.వి.ఎన్.శర్మ wrote:
> I will go for this modification of the original code.
> count = 0
> b= '3'+b[2:]
> n = len(b)
> for i in range(n-4):
> if b[i:i+4] == get_year:
> count += 1
While I think this works OK, I would probably suggest
that this is one of
I will go for this modification of the original code.
file_path = "C:/Users/Rafael/PythonCode/PiDigits.txt"
with open(file_path) as a:
b = a.read()
get_year = input("What year were you born? ")
count = 0
b= '3'+b[2:]
n = len(b)
for i in range(n-4):
if b[i:i+4] == get_year:
count
On 04/03/2017 10:16 AM, Alan Gauld via Tutor wrote:
> On 03/04/17 16:42, D.V.N.Sarma డి.వి.ఎన్.శర్మ wrote:
>> Sorry. That was stupid of me. The loop does nothing.
>
> Let me rewrite the code with some different variable names...
>
with open(file_path) as a:
b = a.read()
>
> with o
On 03/04/17 16:42, D.V.N.Sarma డి.వి.ఎన్.శర్మ wrote:
> Sorry. That was stupid of me. The loop does nothing.
Let me rewrite the code with some different variable names...
>>> with open(file_path) as a:
>>> b = a.read()
with open (file_path) as PI_text:
PI_as_a_long_string = PI_text.read
On 03/04/17 16:42, D.V.N.Sarma డి.వి.ఎన్.శర్మ wrote:
> Sorry. That was stupid of me. The loop does nothing.
>
On the contrary, the loop does an awful lot, just
not what the OP was expecting.
>>> with open(file_path) as a:
>>> b = a.read()
>>> for year in b:
>>> if get_year in b:
>>>
Sorry. That was stupid of me. The loop does nothing.
regards,
Sarma.
On Mon, Apr 3, 2017 at 8:44 PM, Alan Gauld via Tutor
wrote:
> On 03/04/17 16:07, D.V.N.Sarma డి.వి.ఎన్.శర్మ wrote:
> > Modifying the code as shown below may work.
>
> I doubt it.
>
> > with open(file_path) as a:
> > b
On 03/04/17 16:07, D.V.N.Sarma డి.వి.ఎన్.శర్మ wrote:
> Modifying the code as shown below may work.
I doubt it.
> with open(file_path) as a:
> b = a.read()
>
> get_year = input("What year were you born? ")
>
> count = 0
> for year in b:
Once more I ask, what does this loop do?
> if get
Modifying the code as shown below may work.
file_path = "C:/Users/Rafael/PythonCode/PiDigits.txt"
with open(file_path) as a:
b = a.read()
get_year = input("What year were you born? ")
count = 0
for year in b:
if get_year in b:
count += 1
print("Your birth date occurs %s times in
On 03/04/17 13:22, Rafael Knuth wrote:
> with open (file_path) as a:
> b = a.read()
>
> get_year = input("What year were you born? ")
>
> for year in b:
Can you explain what you think this loop line is doing?
I'm pretty sure it's not doing what you expect.
> if get_year in b:
>
26 matches
Mail list logo