Be a Supporter!

Making lists in python?

  • 400 Views
  • 1 Reply
New Topic Respond to this Topic
Twessel
Twessel
  • Member since: Sep. 30, 2006
  • Offline.
Forum Stats
Member
Level 14
Blank Slate
Making lists in python? 2013-02-14 03:16:32 Reply

Trying to write a program that accepts multiple user inputs and translates the strings into pig latin. It works great for one word, but I'm having trouble getting them all into one sentence. Halp??

:pic related

Making lists in python?


smoke meth and hail satan

Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to Making lists in python? 2013-02-14 07:11:28 Reply

Noticed a few problems that you might be able to address:

1) Can you post the actual code and not just a screenshot of it (preferably using code tags)?
2) Your return statement is referencing the undefined variable user_inputs. What variable was that supposed to be?
3) What is the function doing that you are considering erroneous behaviour?

And here's a few things you could do to improve it:

1) You code is very un-pythonic. Don't wrap round brackets around your if statements. Don't use camel case for variable names; use underscores. Don't capitalise the first letter in variable names; that's for classes. Don't put your comments out of alignment with the code your commenting; keep them with the same indentation.
If you're going to start writing Python you may as well learn the Pythonic way to write it otherwise other Python programmers won't touch your code with a 10 foot pole.

2) Your for statement is pretty pointless. You can just use the in keyword to check if a character is in your string of vowels like this:

if userInput[0] in Vowels:
    newWord = userInput+"yay"

if userInput[1] in Vowels:
    prefix = userInput[1:]
    suffix = userInput[0:1]