Hey there! Sign in to join this conversationNew here? Join for free
    • Thread Starter
    Online

    18
    ReputationRep:
    I typed in this on python
    player1 = input("What is your name")
    start = input("Nice to meet you, what is your age?", player1)
    But I get this error
    http://prntscr.com/h6olkz

    Why is this? When I did this last year it worked perfectly fine, has python been updated or something?
    Attached Images
     
    Offline

    15
    ReputationRep:
    What you're trying to do here is print the value of variable player 1 to your message, however, the syntax you used is for listing multiple arguments, here's the correct line:

    start = input("Nice to meet you, what is your age?" + player1)

    as you can see I simply changed the comma to an addition symbol
    Offline

    6
    ReputationRep:
    As an alternative to 0xFFFFail's answer, you could use something called string interpolation.

    For instance the following snippet should work

    start = input("Nice to meet you %s, what is your age" % player1)

    Where %s is where to substitute the player1 string
    Posted on the TSR App. Download from Apple or Google Play
    Offline

    7
    ReputationRep:
    I think formatting strings is much easier and less confusing. You can also procedurally generate variables, it's great.

    print("Nice to meet you {0}, what is your age?".format(player1))

    where .format() arguments are in a list format and {i} denotes the position in that list
 
 
 
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • Poll
    Did TEF Bronze Award affect your UCAS choices?
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

    Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

    Quick reply
    Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.