Ask coding questions

← Back to all posts
How do I define my variable?
AaliyahBishop

So I've created a new program for the same purpose, to create a heads and tails game but it says my flip variable is undefined how do i define it?

Answered by Aqtion [earned 5 cycles]
View Answer
Voters
AaliyahBishop
Comments
hotnewtop
Aqtion

This should fix your problem

i just changed the code a little. I will explain what i did down here. So basically the reason it is saying flip is undefined is because you have to include flip in the parameters of the function you are declaring. For example, you would have to do def coinFlip(flip):, and then blah blah blah. But, you also have to assign flip a temporary value, i did "" cause thats the easiest.

On a side note after running your program to test it I found that your program was not returning the user's score, as it is supposed to, so I fixed that as well. What was wrong with that was that flip was a string, but you were checking it as if it was an integer, which meant the program just stopped there. Thus, you can make a new variable, I called it flip1 for conciseness, and made it's value int(flip), so you can use flip1 instead of flip in your if statement. Hope these answers helped, and if they did, you can mark this as the answer.

AaliyahBishop

@kbadrinath_tcsp ty so much this makes sense now

CodeLongAndPros

Look up on namespaces.
You have lines 5-6 in the function coinFlip and 7-11 in __main___
You need to indent 7-11 by one.

Aqtion

Thanks for the [email protected]

AaliyahBishop

@CodeLongAndPros how to define newScore?

CodeLongAndPros

@AaliyahBishop Indent ln 11 by one