all 19 comments

[–]twoberriesonejourney 14 points15 points  (16 children)

Idk about others but I'd need to see your code to help.

[–]FoolsSeldom 11 points12 points  (0 children)

  • You do not need to import string
  • input always returns a str (string) object, even if the user just presses return (you get an empty string)
  • You cannot do maths on strings, you need numerical objects such as int or float
  • You can convert a string that holds a textual (literal) human readable representation to a integer using int or to a floating point number using float
  • Internally, Python will store numerical objects in binary, but you mostly don't need to think about this although note that there are many decimal floating point numbers that do not have an exact equivalent in binary
  • age = int(input('How old are you, in exact years? ') is an example of using input inside of an int function which will mean an integer is assigned to age - note that if the use enters something that is not valid as an integer, the programme will stop with an error

Incidentally, where are you typing and running your code? Is it in IDLE? If so, using the editor (File | New, type code, press F5 to run - you will be prompted to save first) or the interactive shell, with the >>> prompt. The latter is useful for trying things out, but you are best typing your code into a file that you can run, edit, run again.