2017-11-21 1 views
1

저는 현재 돼지 라틴어 코드를 Python으로 작업하고 있습니다. 두 가지 오류가 발생했습니다. 첫 번째 오류는 자음을 처리합니다. 단어가 두 개의 자음으로 시작하면 두 글자가 끝에오고 'ay'가 붙습니다. 그레이드adgray이됩니다. 내가 고정 무엇에파이썬 돼지 라틴어 - 자음 다루기

#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'

답변

0
#Pig latin 

pig= ("ay") 
word = raw_input("Enter a word: ")# prompt for a phrase and assign result to a variable 
vowels="aeiou" # list of vowels 

words = word.split() 

for i in range(len(words)): 
    if words[i][0] in vowels: # is first letter a vowel 
     print words[i] + 'way', # if first letter is a vowel, print word + 'way' 
    elif words[i][1] in vowels: 
     print words[i][1:] + word[i][0] + 'ay', # assign second letter of phrase to a string variable, for later use 
    else: 
     print words[i][2:] + words[i][0:2] + 'ay', # otherwise print word with first two letters moved to end & added 'ay' 

일부 노트 :

내 두 번째 문제는 내가 아래에 내 코드를 실행하려고하면 내가 잘못된 구문 오류를 얻을이다

  1. 구문 오류는 닫지 않은 괄호로 인한 것입니다.

  2. for 루프로 진행되는 이상한 일들이 있었는데 wordwords이 있어야했을 것입니다. 각 단어 뒤에는 줄 바꿈이 없도록

  3. 나는 단어가 내가 인쇄 문장의 마지막에 쉼표를 추가 한 두 개의 모음

  4. 로 시작하는 경우 처리 완료 좀 더리스트 슬라이스를 사용할 수 있었다

  5. input() 당신이 원한 것을 나는 믿습니다 숫자입니다

+0

raw_input() 당신이 @setholopo 감사 (그것은, 한 줄에 그들이 inputed 된 다만 방법을 모든 단어를 출력) lus, 나는 당신의 제안과 수정을 사용하여 작동하도록했다. * raw_input() *이 에러로 돌아 왔을 때, 나는 input()을 사용하여 작업 할 수 있었다. –

+0

아, 파이썬 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

관련 문제