Skip to content
Sign upLog in
← Back to Community

How do I define my variable?

Profile icon
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
Profile icon
ColmCallan04
Profile icon
frederickptonne
Profile icon
AaliyahBishop
Comments
hotnewtop
Profile icon
Aqtion

This should fix your problem

Screen Shot 2020-05-03 at 2.50.03 PM

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.

Screen Shot 2020-05-03 at 2.53.27 PM

Profile icon
AaliyahBishop

@kbadrinath_tcsp ty so much this makes sense now

Profile icon
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.

Profile icon
Aqtion

Thanks for the [email protected]

Profile icon
AaliyahBishop

@CodeLongAndPros
how to define newScore?

Profile icon
CodeLongAndPros

@AaliyahBishop
Indent ln 11 by one