Turn on thread page Beta
    • Thread Starter
    Offline

    20
    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

    9
    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

    15
    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
 
 
 
Reply
Submit reply
Turn on thread page Beta
Updated: November 13, 2017

University open days

  • Sheffield Hallam University
    City Campus Postgraduate
    Wed, 17 Oct '18
  • Northumbria University
    All faculties Undergraduate
    Wed, 17 Oct '18
  • Staffordshire University
    Nursing and Midwifery Undergraduate
    Wed, 17 Oct '18
Poll
Who is most responsible for your success at university

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

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