#how to

44 messages · Page 1 of 1 (latest)

sick garden
#
def convert(number):
    why = []
    if number %3 ==  0 :
        why.append("Pling")
    elif number % 5 == 0:
        why.append("Plang")
    elif number % 7 == 0:
        why.append("Plong")
    else:
        return str(number)
    return why[0]
Code Run
self.assertEqual(convert(15), "PlingPlang")
Test Failure
AssertionError: 'Pling' != 'PlingPlang'
- Pling
+ PlingPlang

when we get number like 15 35 105 which will have more than one factors then the dictionary should append both pling and plong but its is showing only pling

stone storm
#

What does your last line of code do?

sick garden
#

it return the the first index of the dictionary

stone storm
#

So you return the first sound or all the sounds?

sick garden
#

all the sounds

#

right now i am returning only first sounds but i want to return all the sounds

stone storm
#

So you need to change the return line, right? So it doesn't return just the first element

#

Note, why is a list and not a dictionary

sick garden
#

i tried doing why[:-1]

weary juniper
#

do you understand what data type you need to return and what data type you are returning?

stone storm
#

That would return the last element. I thought you wanted all the elements?

#

Or, all but the last?

sick garden
#

i need to return complete line but each word is stored in different index like in case of 15 why[0] == pling and why[1] == plang .the question is how do i make a line by word

stone storm
#

What does the list contain, and what do you want to return? If you want to return the entire list, you don't need to use any index.

sick garden
#

i want entire list

stone storm
#

return why would return the entire list

#

If you have a list and want to return it, just return it

sick garden
#
Test Failure
AssertionError: ['Pling'] != 'PlingPlangPlong'```
stone storm
#

Yes. Your list contains one item, Pling.

#

Is that what you expect? Is that not what you expect?

sick garden
#

but i want my list to contain all items as the number of factors like in case of 105 factor are 3 5 7 so it should contain pling plang plong

stone storm
#

Why would it contain all three? Look at your code and at the input. What lines would execute that would cause it to have all three?

sick garden
#

first it should check first line if is true then append it and go to next line and check again for second line and do it till last This is what i want

#

but i think my code is not doing that

#

it just appending first case and return just that value

weary juniper
#

did you do what he suggested above?

return why would return the entire list
If you have a list and want to return it, just return it
stone storm
#

Look at what the code does. Is it doing what you're describing?

#

If it's doing something different, can you fix it?

sick garden
#
Test Failure
AssertionError: "['Pling']" != 'Pling'
- ['Pling']
? --     --
+ Pling  ``` yes i did that throws more error
stone storm
#

Focus on one thing at a time 🙂

#

Which test do you want to focus on?

sick garden
#

105 one

#

i am trying to fix

stone storm
#

👍

#

Do you see the issue with the code?

sick garden
#

yes the issue if the if statement is false then only it will go to next elif condition

#

that not what i wnat

#

i want to check every condition

stone storm
#

Sounds about right

sick garden
#

i am not getting idea is how to check each condition

stone storm
#

How do you check one condition?

sick garden
#

by using if

stone storm
#

Can you do that three times to check three conditions?

#

Sleep time for me. Good luck.