Jump to content

Another Python problem

Jerahmy

I cannot figure out how the code needs to go. Can anyone help? I am making a pig latin translator.

 

Instructions:

 

Set new_word equal to the slice from the 1st index all the way to the end of new_word.

Use[1:len(new_word)] to do this.

 

pyg = 'ay'
original = raw_input('Enter a word:')
word = original.lower()
first = word[0]
new_word = word + first + pyg
if len(original) > 0 and original.isalpha():
    print original
else:
    print 'empty'

Link to comment
Share on other sites

Link to post
Share on other sites

Codecademy

Spoiler
Spoiler
Spoiler
Spoiler
Spoiler
Spoiler
Spoiler
Spoiler
Spoiler
Spoiler

What are you looking for?

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

can you tell me what you want to go in and what you want to be output by the program?

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, Enderman said:

can you tell me what you want to go in and what you want to be output by the program?

The output needs to be harliecay. If it helps, im on Code-academy. 

Link to comment
Share on other sites

Link to post
Share on other sites

12 minutes ago, Jerahmy said:

The output needs to be harliecay. If it helps, im on Code-academy. 

but what is the input?

 

this might be similar to what you are trying to do:

well if you have a word = hello

then you can use [0:len(word)-2] to get everything from first to second last letter

 

so word[0:len(word)-2] returns "hell"

because h=0 e=1 l=2 l=3 o=4

length is 5

so if you go from 0 to 3 then you get hello without the last letter

 

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to comment
Share on other sites

Link to post
Share on other sites

22 minutes ago, Enderman said:

can you tell me what you want to go in and what you want to be output by the program?

Sorry, the input is "Charlie"

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Jerahmy said:

Sorry, the input is "Charlie"

oh i see

well you first want the stuff from 1 to end

then you want to add the letter at 0

then you want to add ay

 

so you can use word[A:B] to get what section of the word you want

if you want to start with h (position 1) then you make A 1

 

then you want to end with the last letter, which is len(word)-1

the -1 is because len(word) = 7 but the last letter is position 6

 

so that means to get "harlie" you need to do word[1:len(word)-1]

 

after that you can just add the first letter, which is word[0], and then add "ay"

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to comment
Share on other sites

Link to post
Share on other sites

20 minutes ago, Enderman said:

oh i see

well you first want the stuff from 1 to end

then you want to add the letter at 0

then you want to add ay

 

so you can use word[A:B] to get what section of the word you want

if you want to start with h (position 1) then you make A 1

 

then you want to end with the last letter, which is len(word)-1

the -1 is because len(word) = 7 but the last letter is position 6

 

so that means to get "harlie" you need to do word[1:len(word)-1]

 

after that you can just add the first letter, which is word[0], and then add "ay"

Im not going to lie. I have no idea what you just said. :)

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, Jerahmy said:

Im not going to lie. I have no idea what you just said. :)

charlie is a string

 

c  h  a   r   l   i  e

0  1  2  3  4  5  6

 

you want letters 1 to 6, then 0, then "ay"

 

since you want this to work for any length word, instead of 6 use     len(word)-1

the [A:B] function takes all the letters from A to B

in this case you want all the letters from 1 to      len(word)-1       so you do        word[   1  :  len(word)-1   ]

 

thats the first part

then you want to add the first letter of the word, so you go        +word[0]

 

then you want to add "ay" so you go     +"ay"

 

 

word[   1  :  len(word)-1   ]    +    word[0]     +      "ay"

prints out            harlecay

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, SSL said:

@Enderman @Jerahmy

 

You two need to read about slicing in Python.

I already know how, I was teaching him how to do it

What's the problem

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, Enderman said:

I already know how, I was teaching him how to do it

What's the problem

 

Everything should be as simple as possible but no simpler. Your example doesn't take account the word[1:] notation, which is functionally identical to word[a:len(word)-1].

Link to comment
Share on other sites

Link to post
Share on other sites

7 minutes ago, SSL said:

 

Everything should be as simple as possible but no simpler. Your example doesn't take account the word[1:] notation, which is functionally identical to word[a:len(word)-1].

Try reading the instructions next time.

I wonder how many marks you've lost on exams for not bothering to read the instructions...

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to comment
Share on other sites

Link to post
Share on other sites

7 minutes ago, Enderman said:

Try reading the instructions next time.

I wonder how many marks you've lost on exams for not bothering to read the instructions...

 

I don't care about instructions if they're wrong. In the real world, programs are designed to interfaces and performance constraints; specifics of implementation are not important and should be ignored if they are stupid.

 

Codeacademy is shit; I wouldn't be surprised if the people who wrote this "tutorial" know nothing about Python.

Link to comment
Share on other sites

Link to post
Share on other sites

18 minutes ago, SSL said:

 

I don't care about instructions if they're wrong. In the real world, programs are designed to interfaces and performance constraints; specifics of implementation are not important and should be ignored if they are stupid.

 

Codeacademy is shit; I wouldn't be surprised if the people who wrote this "tutorial" know nothing about Python.

I think that's a personal opinion. Thousands of people learnt to program from there just fine...

 

If you use that kind of "this is stupid, im not going to follow the instructions" logic on your tests you must have failed university or something

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to comment
Share on other sites

Link to post
Share on other sites

27 minutes ago, SSL said:

 

I don't care about instructions if they're wrong. In the real world, programs are designed to interfaces and performance constraints; specifics of implementation are not important and should be ignored if they are stupid.

 

Codeacademy is shit; I wouldn't be surprised if the people who wrote this "tutorial" know nothing about Python.

 

7 minutes ago, Enderman said:

I think that's a personal opinion. Thousands of people learnt to program from there just fine...

 

If you use that kind of "this is stupid, im not going to follow the instructions" logic on your tests you must have failed university or something

 

37 minutes ago, Enderman said:

Try reading the instructions next time.

I wonder how many marks you've lost on exams for not bothering to read the instructions...

 

45 minutes ago, SSL said:

 

Everything should be as simple as possible but no simpler. Your example doesn't take account the word[1:] notation, which is functionally identical to word[a:len(word)-1].

Calm down guys. No need to get into an argument over this. Everyone has their own opinion.

Link to comment
Share on other sites

Link to post
Share on other sites

9 minutes ago, Enderman said:

I think that's a personal opinion. Thousands of people learnt to program from there just fine...

 

If you use that kind of "this is stupid, im not going to follow the instructions" logic on your tests you must have failed university or something

 

If you want to believe either of those things, I can't stop you. Meanwhile I'll sit here having a degree and a job as a web developer, dealing with garbage code written by people who learned on codeacademy.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×