标签:inpu creat word \n int not ted python code
Author: Notus(hehe_xiao@qq.com)
Create: 2019-02-26
Update: 2019-02-26
Python version: 3.7.1
'''
检查输入的两个词是否构成变位词, 即字母相同,顺序不同。
@Author: Notus(hehe_xiao@qq.com)
@Create: 2019-02-26
@Update: 2019-02-26
@Version: 0.1
'''
def areAnagram(word1, word2):
word1_sorted = sorted(word1)
word2_sorted = sorted(word2)
return word1_sorted == word2_sorted
twowords = input("输入两个由空格分隔的单词:")
word1, word2 = twowords.split(" ")
if areAnagram(word1, word2):
print("构成Anagram")
else:
print("不构成Anagram")
C:\Users\Notus\Desktop>python a.py
输入两个由空格分隔的单词:word drow
构成Anagram
C:\Users\Notus\Desktop>python a.py
输入两个由空格分隔的单词:kkkk dddd
不构成Anagram
标签:inpu creat word \n int not ted python code
原文地址:https://www.cnblogs.com/leo1875/p/10440989.html