#raindrop python help

19 messages · Page 1 of 1 (latest)

hoary pecan
#

self.assertEqual(convert(15), "PlingPlang")
TEST FAILURE
AssertionError: 'Pling' != 'PlingPlang'

  • Pling
  • PlingPlang
young pawn
#
  1. Do you understand what the test is doing?
  2. Do you understand what the test is expecting and why?
  3. Do you understand what your code returns and how it differs?
  4. Do you understand why your code is returning what it returns?
#

You might also want to share your code. Please use codeblocks and not screenshots.

mossy thicket
#

We have no way to help you unless you show your code

hoary pecan
#

this is the code

def convert(number):
all=""
if number%3==0:
all="Pling"
elif number%5==0:
all+="Plang"
elif number%7==0:
all+="Plong"
else:
all=str(number)
return all

young pawn
molten estuaryBOT
hoary pecan
#
def convert(number):
    all=""
    if number%3==0:
        all="Pling"
    elif number%5==0:
        all+="Plang"
    elif number%7==0:
        all+="Plong"
    else:
        all=str(number)
    return all
young pawn
#

What about my questions? 🙂

hoary pecan
#
  1. yes I understand what the test is doing
    2.yes I do
    3.yes
    4.yes
young pawn
#

If you understand why your code is returning what it is returning and why it is wrong, do you know how to fix it?

#

@hoary pecan ?

hoary pecan
#

my code is returning the all variable , which has PlingPlangPlong according to the number which has factors of 3,5,7 respectively

young pawn
#

Which lines execute in what order when it is called with 15?

hoary pecan
#

I got it now

#

it was because I was using elif

#

I used if and code got solved! thanks

#
    all=""
    if number%3==0:
        all="Pling"
    if number%5==0:
        all+="Plang"
    if number%7==0:
        all+="Plong"
    if number%3!=0 and number%5!=0 and number%7!=0:
        all=str(number)
    return all
young pawn
#

Nicely solved!!