+ Post New Thread
Results 1 to 4 of 4
Coding Thread, starting with python help in Coding and Web Development; I am using a tutorial to get used to python by makeing simple games. In the tutorial it tells me ...
  1. #1
    llawwehttam's Avatar
    Join Date
    Nov 2008
    Location
    Birmingham
    Posts
    223
    Thank Post
    56
    Thanked 3 Times in 3 Posts
    Blog Entries
    2
    Rep Power
    14

    starting with python help

    I am using a tutorial to get used to python by makeing simple games.

    In the tutorial it tells me to

    Code:
    28. if guess == number:
    29. guessesTaken = str(guessesTaken)
    30. print('Good job, ' + myName + '! You guessed my
    number in ' + guessesTaken + ' guesses!')
    Now myName is a str object but guessesTaken is an int.

    When I run the code in the tutorial (above) I get an error

    line 31, in <module>
    print('Good job, ' + PlayerName + '! You guessed my number in ' + guessesTaken + ' guesses!')
    TypeError: cannot concatenate 'str' and 'int' objects

    my name for things is slightly different than the tutorial but neither work.

    How to I get it to display int objects?

  2. #2
    llawwehttam's Avatar
    Join Date
    Nov 2008
    Location
    Birmingham
    Posts
    223
    Thank Post
    56
    Thanked 3 Times in 3 Posts
    Blog Entries
    2
    Rep Power
    14
    sorry i just worked it out. I forgot to

    guessTaken = str(guessTaken)

    or something similar

    had a few typo's in there now.

    Wow I am suddenly enjoying learning programming!!!

  3. #3

    Join Date
    Apr 2009
    Location
    Leeds
    Posts
    120
    Thank Post
    6
    Thanked 16 Times in 15 Posts
    Rep Power
    13
    Thats one way of doing it, the other way is to use string manipulation which you should cover later.

    This is where the code would look like:

    Code:
    28. if guess == number:
    29. guessesTaken = str(guessesTaken)
    30. print('Good job, ' + myName + '! You guessed my
    number in ' + '%d' guessesTaken + ' guesses!')

  4. Thanks to BTCC_Fan from:

    llawwehttam (23rd December 2009)

  5. #4

    Join Date
    Feb 2009
    Posts
    45
    Thank Post
    1
    Thanked 5 Times in 5 Posts
    Rep Power
    11
    Quote Originally Posted by llawwehttam View Post
    I am using a tutorial to get used to python by makeing simple games.
    .....
    Python
    Python Programming Language -- Official Website

    and documentation off the Home page
    Python Documentation Index

SHARE:
+ Post New Thread

Similar Threads

  1. python rss read script
    By RabbieBurns in forum Scripts
    Replies: 10
    Last Post: 29th September 2009, 10:35 PM
  2. Replies: 5
    Last Post: 13th August 2009, 12:56 PM
  3. [Video] Star Trek Meets Monty Python
    By mattx in forum Jokes/Interweb Things
    Replies: 1
    Last Post: 10th June 2009, 10:19 AM
  4. Replies: 0
    Last Post: 30th September 2008, 03:24 PM
  5. Python LDAP module version problem
    By CyberNerd in forum Coding
    Replies: 6
    Last Post: 14th December 2006, 01:18 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •