Skip to content
Sign UpLog In
This post is read-only. Explore Repls and connect with other creators on Community.View Community
The info in this post might be out of date, check out our docs instead. View docs
3

How do I define my variable?

AaliyahBishop
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?

3 years ago
Answered by AqtionView Answer
You are viewing a single comment. View All
2
Aqtion
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

3 years ago
1
AaliyahBishop
AaliyahBishop

@kbadrinath_tcsp ty so much this makes sense now

3 years ago