1
私は現在、PythonのPig Latinのコードに取り組んでいます。私は2つのエラーに遭遇しています、最初のものは子音を扱っています。単語が2つの子音で始まる場合、両方の文字が末尾に移動し、 'ay'が付加されます。グレードはadgrayになります。私は固定のものにPython Pig Latin-子音を扱う
#Pig latin
pig= ("ay")
word = input("Enter a word: ")# prompt for a phrase and assign result to a variable
vowels="aeiou" # list of vowels
words = word.split()
# for word in words
for i in range(len(word)):# assign first letter of phrase to a string variable, for later use
if word[i][0] in vowels: # is first letter a vowel
print(word[i] + 'way') # if first letter is a vowel, print word + 'way'
elif word[i][1] in vowels:
print(word[i][1:]+word[i][0] + 'ay' # assign second letter of phrase to a string variable, for later use
else:
print(word[i]+ [1:]=('ay') # otherwise print word with first two letters moved to end & added 'ay'
はありがとうございました何を望むか、私は信じ数字です@setholopo lus、何らかの理由で*あなたの提案や修正を使って動作させました。* raw_input()*がエラーを返すので、input()を使用するだけで動作させることができました。 –
ああ、Python 3を使用している必要があります。私は2.7を使用していました。 2.7については、私が言ったことは 'input()'と 'raw_input()'について(ほとんど)真実です。ここを見てください:https://stackoverflow.com/questions/4915361/whats-the-difference-between-raw-input -and-input-in-python3-x – setholopolus