#for循环
word =input("Enter a word:")print("\nHere's each letter in your word:")for letter in word:print(letter)
Enter a word:lzq
Here's each letter in your word:
l
z
q
#range函数print("Counting:")for i inrange(10):print(i,end=" ")print("\n\nCounting by five:")for i inrange(0,50,5):print(i,end=" ")print("\n\nCounting backwards:")for i inrange(10,0,-1):print(i,end=" ")
# len()函数和in运算符
message =input("Enter a message:")print("\nThe length of your message is:",len(message))print("\nThe most common letter in the English language'e'")if"e"in message:print("is in your message.")else:print("is not in your message.")
Enter a message:lzq like to study.
The length of your message is: 18
The most common letter in the English language'e'
is in your message.
#字符串的索引import random
word ="index"print("The word is:%s\n"%word)
high =len(word)
low =-len(word)for i inrange(10):
position = random.randrange(low,high)#不包含highprint("word[%d]:%s"%(position,word[position]))
The word is:index
word[2]:d
word[-4]:n
word[3]:e
word[-1]:x
word[3]:e
word[1]:n
word[-1]:x
word[-2]:e
word[-5]:i
word[3]:e
#for循环word = input("Enter a word:")print("\nHere's each letter in your word:")for letter in word: print(letter) Enter a word:lzqHere's each letter in your word:lzq#range函数print(&qu