Help with getting program to print in an outside file

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 1058 Views - Last Post: 11 November 2016 - 10:39 PM Rate Topic: -----

#16 andrewsw   User is offline

  • no more Mr Potato Head
  • member icon

Reputation: 6957
  • View blog
  • Posts: 28,696
  • Joined: 12-December 12

Re: Help with getting program to print in an outside file

Posted 11 November 2016 - 10:39 PM

Note that you don't have to quote every post, there is a Reply button further down the page, or use the Fast Reply box.



Quote

AttributeError: 'float' object has no attribute 'split'

This error is quite clear. mynum is a number, you know this as you used float() to create the number, and a number doesn't have a split() method. A string does so you can use str() in the same way you used float().

In Javascript, splitting on the empty string "" will split a word into individual characters. This is useful and I'm not sure of another language that does this. However, Python doesn't, and you'll receive an error. But you don't need to do this because a Python string is already a sequence:

x, y, z = "123"

Of course, you should only do this if you know that there are exactly three characters/digits.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2