Ask coding questions

← Back to all posts
Why is it throwing an error on me?
ROCKINGRAYQUAZA

Hey there!Everyone hope you are having a good day

Now, i am updating ths post as due to some help from @Coder100 and @Codejira and due to some of my own changes i am able to function the program but now another problem comes,now the program is not reading the block from line 193 to 200..it is giving me a blank list at the end or None..
see below

So please help me..

Any help would be appreciated :)

Voters
ROCKINGRAYQUAZA
Comments
hotnewtop
PattanAhmed

@ROCKINGRAYQUAZA Hi,
Is this error solved?
Thanks!

ROCKINGRAYQUAZA

doing wait @PattanAhmed

ROCKINGRAYQUAZA

i have tried @CodingCactus process and it worked @PattanAhmed

ROCKINGRAYQUAZA

I have mentioned all who have helped me in creating this program in the credit @CodingCactus @PattanAhmed and many more so be sure to check it out both of you :)

PattanAhmed
PattanAhmed
ROCKINGRAYQUAZA

i have posted my game check in share repl section @PattanAhmed

PattanAhmed

@ROCKINGRAYQUAZA Yep, It's Amazing!

Codejira

Before choosing a nickname, assign fp2 = fp. I suggest line 184.
Line 193 can be deleted then.

This is not tested, but I think it should do the trick.

ROCKINGRAYQUAZA

bro i have done some changes with the help of @MarkKohler and i don't wish to change anything as the program is up running again but thanks for your advise :) @Codejira

Codejira

You have to change some if conditions.
Where you wrote if fp==("1" or "Charmander"): I believe if fp == "1" or fp == "Charmander": is what you want.
In your if elif block on lines 192 - 200 the conditions never evaluate to True. That's why rfp never gets a value assigned, resulting in the NameError: name 'rfp' is not defined a little later.

Also pay attention to capitalization: "Charmander" and "charmander" are two different strings and "Charmander" == "charmander" evaluates to `False'.

ROCKINGRAYQUAZA

that is why is specified fp = fp.lower
btw thanks bro :) @Codejira

ROCKINGRAYQUAZA

bro so what should i do to evalute "rfp" condition to true??
@Codejira

Codejira

Hi @ROCKINGRAYQUAZA
fp = fp.lower is a good thing to do. But see my initial reply, where I copied your code
if fp==("1" or "Charmander"):

I see you got that sorted out already.

The other edits look good to me, too. Does it work already?

ROCKINGRAYQUAZA

no bro not now:( @Codejira

AustinZhang1

@ROCKINGRAYQUAZA @Codejira the fp = fp.lower() does not actually help, as the input is asking for a number, not a string.

ROCKINGRAYQUAZA

Yes but what if the user enters "charmander" instead of "1" We have to take care about everything bro :) @AustinZhang1

AustinZhang1

@ROCKINGRAYQUAZA No offense, but your variables are a bit confusing.

AustinZhang1

@ROCKINGRAYQUAZA I think I may have found the error.
Over here:


You defined fp as Charmander, Squirtle, or Bulbasaur.(note the capital first letter.)
Then here,

You checked if fp was 1/2/3/charmander/bulbasaur/squirtle, however, the first letter is not capitalized! Therefore fp will never be the same as what you checked for because of the first capital letter.
I forked this repl and fixed the error: forked repl
I hope this helps!

Codejira

@ROCKINGRAYQUAZA, you decide what input is allowed. If you accept both "1" and "charmander", you can take care of capitalization with the str.lower() method.

Personally I favour the numbers-only-approach, because you can never overestimate a users stupidity ;)
Think of "ChArMaNdEr", "Charmendar", ...
not to talk about 1 versus 10 keystrokes.

Codejira

@AustinZhang1, @ROCKINGRAYQUAZA, it works, yeah :)

But I'm afraid I found another bug:

When you enter a nickname it gets assigned to fp on line 187. Therefor in the last if else block no condition will ever be True and no name will be appended to the rival_team. The [None] on the last output-line is the empty rival_team list (although I wonder if it should read []).

ROCKINGRAYQUAZA

yes you got what problem i was facing :(
thanks for everyone's help now I will be doing some changes on my own and if the problem persists I will reask for it....Thanks everybody for helping me out ;) @Coder100 @AustinZhang1 @Codejira

ROCKINGRAYQUAZA

still idk why this is happening i tried several time but nothing happens :( @Codejira

Coder100

Solution. I changed the if statement because currently it's not going to work

Another way to do it is to use global:

ROCKINGRAYQUAZA

bro now it is showing me none as the output @Coder100

Coder100

yes, that means invalid input @ROCKINGRAYQUAZA

ROCKINGRAYQUAZA

so now what to do... I know i may sound stupid to you but i am beginner so i am a lot curious about this @Coder100

Coder100

ok, so just a sec @ROCKINGRAYQUAZA

Coder100

@ROCKINGRAYQUAZA

first off, this code is all wrong, its always going to choose charmander, use what I gave you.

ROCKINGRAYQUAZA

I USED WHAT YOU GAVE ME AND THE OUTPUT WAS SOMETHNG LIKE WAAIT A SEC. @Coder100

Coder100
ROCKINGRAYQUAZA
Coder100

@ROCKINGRAYQUAZA

you still haven't fixed this! That's why it's not working!

ROCKINGRAYQUAZA

I SENT YOU A PIC SEE THAT I DON'T WANT IT TO BE NONE IT IS COMING WHEN IO INSERTED YOUR PROGRAM
@Coder100

Coder100

The code has to be:

Right now it's being evaluated as:

which is always false because fp is a string!

@ROCKINGRAYQUAZA

Coder100

well it's not my fault you haven't done what I told you to do @ROCKINGRAYQUAZA

ROCKINGRAYQUAZA

Doing bro @Coder100

Coder100
Coder100

Ok, how is it going @ROCKINGRAYQUAZA

ROCKINGRAYQUAZA

bro i did what you asked but still its providing me ['None'] or [''] and the program is completely refusing to check the if..else block between line 194 and 200 i have been redoing the program so i was checking it line by line for errors so i eraser a few lines from rival_first_pokemon section so if you run the program now enter only 1 for now @Coder100

ROCKINGRAYQUAZA

should i invite you to the repl so that you can make necessary changes in the repl as that will be more convenient @Coder100

Coder100

rfp is not defined

ROCKINGRAYQUAZA

So what to do?? @Coder100

Coder100

im looking at it, but how do you reproduce it @ROCKINGRAYQUAZA

Coder100

ok got it @ROCKINGRAYQUAZA

ROCKINGRAYQUAZA

Please if you want to see the program in the repl community very soon..
I want to get all of your opinion..
Of course plz answer the question :\ XD