By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,968 Members | 1,852 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,968 IT Pros & Developers. It's quick & easy.

How to name any elements of a list

P: 7
Hi, I have some problem with my code:

Expand|Select|Wrap|Line Numbers
  1. from time import*
  2. from turtle import*
  3.  
  4.  
  5. mot = input("Quel est votre mot?")
  6. longueurMot = len(mot)
  7. lettre = list(mot)
  8.  
  9. a = 0
  10. b = -1
  11. while a != longueurMot:
  12.     a = a +1
  13.     b = b +1
  14.     down()
  15.     forward(100)
  16.     left(90)
  17.     forward(50)
  18.     left(90)
  19.     forward(100)
  20.     left(90)
  21.     forward(50)
  22.     left(90)
  23.     up()
  24.     forward(50)
  25.     left(90)
  26.     forward(25)
  27.     write(lettre[b])
  28.     left(180)
  29.     forward(25)
  30.     left(90)
  31.     forward(150)
  32. lettreEntrée = input("Entrez une lettre svp.")
  33. while lettreEntrée != lettre[]:
  34.     print("Cette lettre ne fait pas partie du mot. Réessayez.")
  35.     lettreEntrée = input("Entrez une lettre svp.")
  36.     if lettreEntrée == lettre[]:
  37.         break
  38.  
When I ask to write a letter, I want to know if this letter is in my list. If not, I want to print : This letter is not in my word.

P.S.: I am french so sorry if you don't understand some words :)
Nov 9 '14 #1
Share this Question
Share on Google+
2 Replies


bvdet
Expert Mod 2.5K+
P: 2,851
The "in" operator can be applied to a sequence such as a string or list.
Expand|Select|Wrap|Line Numbers
  1. >>> word = "example"
  2. >>> if "e" in word:
  3. ...     print "This letter is in my word"
  4. ... else:
  5. ...     print "This letter is not in my word"
  6. ...     
  7. This letter is in my word
  8. >>> 
Nov 10 '14 #2

P: 7
Thank you very much :D
Nov 10 '14 #3

Post your reply

Sign in to post your reply or Sign up for a free account.