Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

python programming (upper and lowercase variables)

  • 06-09-2011 11:41AM
    #1
    Registered Users, Registered Users 2 Posts: 27


    Hi anyone,
    i am trying to write a python if statement (i am new to it). i want it to carry out a function if a user enters a value for yes and no. i have it working but it fails if the users types the answer in anything other than lowercase... can anyone help...


Comments

  • Registered Users, Registered Users 2 Posts: 11,264 ✭✭✭✭jester77


    adrian7444 wrote: »
    Hi anyone,
    i am trying to write a python if statement (i am new to it). i want it to carry out a function if a user enters a value for yes and no. i have it working but it fails if the users types the answer in anything other than lowercase... can anyone help...

    Not familiar with python, but I would imagine that there is a toLowerCase function or equivalent that you can use to parse the input string so that you know it will always be in lower case.


  • Registered Users, Registered Users 2 Posts: 27 adrian7444


    thanks i'll look that up


  • Registered Users, Registered Users 2 Posts: 1,311 ✭✭✭Procasinator




  • Registered Users, Registered Users 2 Posts: 27 adrian7444


    i appreciate the link but to be honest i cant follow all that detail.
    this is what i am after....

    condition is as follows;

    if answer=="yes":

    **i want the programme to recognise all variables with yes that the user inputs, not just lowercase**

    i assume i need to put something around the "yes" to allow this.??????????


  • Registered Users, Registered Users 2 Posts: 11,264 ✭✭✭✭jester77


    adrian7444 wrote: »
    i appreciate the link but to be honest i cant follow all that detail.
    this is what i am after....

    condition is as follows;

    if answer=="yes":

    **i want the programme to recognise all variables with yes that the user inputs, not just lowercase**

    i assume i need to put something around the "yes" to allow this.??????????

    if answer.lower()=="yes":

    It doesn't matter what the user inputs, Yes, YES, YeS will all get parsed to yes


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 27 adrian7444


    thanks so much, really appreciate your help...


Advertisement