This is a Number-Guessing Game.

66 views
Skip to first unread message

Dr.Bhavani Rao Reddi

unread,
Apr 6, 2017, 1:18:50 AM4/6/17
to MIT App Inventor Forum

Good morning,
This is a Number-Guessing Game.
It allows the user to put in three numbers as bidding numbers. 
Then the App displays a list of 10 random numbers.
If the any of the bidder numbers present in the random numbers, the message alert should be " Found the bidder number. "
I tried with these blocks. Though bidder number present in the Random numbers, the message alert is showing " Not found".
What is wrong with my blocks?
BlocksCapture.PNG
RandomBid.png
RandomBidDesign.PNG

Pavitra

unread,
Apr 6, 2017, 3:43:16 AM4/6/17
to MIT App Inventor Forum
You are checking whether a list is inside a list which obviously, returns to false. So, the blocks under "while" block in "btnHammer. Click" does not execute.

Also, you show an alert "No number found" for whatever the case, which shouldn't be.

So, what I recommend you is change the "while" block to "if-else" one and it will definitely work!

Pavitra

unread,
Apr 6, 2017, 3:46:12 AM4/6/17
to MIT App Inventor Forum
You must first use "for each item in list" block and it will return an item one by one and check whether it is present in the list using "if-else" block.

Abraham Getzler

unread,
Apr 6, 2017, 10:47:33 AM4/6/17
to MIT App Inventor Forum
You are taking an intersection of two sets.
See attached for a general result procedure to calculate and return 
an intersection, with sample test data.

ABG

INTERSECTION.PNG

Dr.Bhavani Rao Reddi

unread,
Apr 7, 2017, 4:21:04 PM4/7/17
to MIT App Inventor Forum
Thanks again, ABG.
Solved blocks and the .aia
NumberGuess.aia
GuessNumberBlocks.PNG

Abraham Getzler

unread,
Apr 7, 2017, 4:58:31 PM4/7/17
to MIT App Inventor Forum
Whoa, this can't possibly be right.

1:
In the button to generate 10 random numbers, you are playing with fire.

You reuse the variable number that is used to count  to 10 numbers,
as the next random number itself!
I can't believe you got away with this.

Have mercy on the reader of this code and create a new variable specific 
to holding the next random number, called next_random_number.
Use the local variable block, it's time you learned about it.
Pass the random number through it into its destination(s).

2:
Also, where do you clear the two destinations before you start 
generating the numbers?
Shouldn't that happen at the top of the generate button event?


3.
In btnHammer, you used an improper test for empty list.
The INTERSECTION procedure returns a list always.
If there are no winners, that list will be empty.
Since you take that value twice, you should devote a global variable
to save that, for brevity.  Call the new global variable winners, initially an empty list.
Note the s at the end of the name, to denote plural,
to remind us it's a list.
Set winners  to the result of the intersection,
and change the test from "is it a number" to
"is the length of the list winners > 0".

4.
It's time you learned the csv from list block,
which can take a list and turn it into a piece of text
with all the items from the list, separated by commas.
(csv = Comma Separated Values.)

ABG


Abraham Getzler

unread,
Apr 7, 2017, 5:07:09 PM4/7/17
to MIT App Inventor Forum
See attached for how wrong it is to use "is number" against a list.
ABG

bologna.PNG

Dr.Bhavani Rao Reddi

unread,
Apr 8, 2017, 2:06:49 AM4/8/17
to MIT App Inventor Forum
Thank you, ABG for your time.
I will come back to this post once I get sufficient proficiency in programming.
I confess that I cannot fully decipher your analysis as of now.
Reply all
Reply to author
Forward
0 new messages