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.V.N.Sarma డి.వి.ఎన్.శర్మ
<dvnsa...@gmail.com> wrote:
> b = "3"+b[2:]  #Removing the decimal point so that there are digits only in

my_number = 3.14159
my_number = "3"+my_number[2:]
print(my_number)

This is the error code I got:

== RESTART: C:/Users/Rafael/Documents/01 - BIZ/CODING/Python Code/PPC_56.py ==
Traceback (most recent call last):
  File "C:/Users/Rafael/Documents/01 - BIZ/CODING/Python
Code/PPC_56.py", line 2, in <module>
    my_number = "1"+my_number[2:]
TypeError: 'float' object is not subscriptable
>>>

I am really trying to understand how to modify strings, floats and
variables from different sources.
In case of a text file, your code works, but if I apply the same to a
float assigned to a variable, it does not work.
What am I doing wrong here? Thank you so much for your patience.



> the file
> n = len(b)
> for i in range(n-3):
>     if b[i:i+4] == get_year:  # Taking 4 digit long chunks from successive
> positions in b and seeing whether they are equal to get_year
>         count += 1  # If they are equal increase the count by 1
>
> regards,
> Sarma.
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
  • Re: [Tutor] C... Alan Gauld via Tutor
    • Re: [Tut... D . V . N . Sarma డి . వి . ఎన్ . శర్మ
      • Re: ... Alan Gauld via Tutor
      • Re: ... Alan Gauld via Tutor
        • ... Mats Wichmann
          • ... D . V . N . Sarma డి . వి . ఎన్ . శర్మ
          • ... Alan Gauld via Tutor
          • ... D . V . N . Sarma డి . వి . ఎన్ . శర్మ
          • ... Rafael Knuth
          • ... Alan Gauld via Tutor
          • ... Rafael Knuth
          • ... Alan Gauld via Tutor
          • ... Rafael Knuth
          • ... Marc Tompkins
          • ... boB Stepp
          • ... eryk sun
          • ... Alan Gauld via Tutor
          • ... Mats Wichmann
          • ... Alan Gauld via Tutor
          • ... boB Stepp
          • ... eryk sun

Reply via email to