An Obvious Interactive Problem

This is a companion discussion topic for the original entry at

Is this possible to solve this with Python 3.7. I can’t find any other way. Here is my code:

import random
x = 1000000
y = 0
for i in range(25):
	a = random.randint(y, x)
	b = input()
	if b == "Bigger":
		y = a+1
	elif b == "Smaller":
		x = a
	elif b == "Bingo!":

@Abdullah_1234, yes it is absolutely possible to solve this problem with python.
Toph already has a tutorial about it !!!
However, it might have been removed so I cannot find it.
Any clue, @hjr265 ?

I found two errors in your code.

  1. You are using a random number. You can’t use random number because it gives random number
    every time. You need to use binary search. You just need to replace
    a = random.randint(y, x) with
    a = int((x + y) / 2)
  2. Your’re using wrong qutations
    The one you used “ ”
    But it should be " "
    if you fix these you will get an Accepted verdict.
    Here is the AC code: [REDACTED]
1 Like

He wasn’t actually using wrong quotations.
It happens when you write something in the community.
The quotations are changed.

is it possible to with C? I tried binary search. Still shows CLE. Even though I managed to avoid strcmp() function. Any tips?

What’s wrong in my code?Showing CLE. Please check and help me.

#include <stdio.h>
int main()
    int a, l=0, h=1000000, i=0, p=0, j;
    for(i=0; i<25; i++)
        char str[20];

        printf("%d\n", p);
        scanf("%s", str);
            for(j=l; j<=h; j++)
                printf("%d\n", j);
                scanf("%s", str);
                if(strcmp(str, "Bingo!")==0)
        else if(strcmp(str, "Bingo!")==0)
        else if(strcmp(str, "Smaller")==0)
        else if(strcmp(str, "Bigger")==0)
    return 0;

the problem is in Binary search section!
you can’t just use random

I didn’t know about binary search before I started this problem that’s why I posted a silly question. I got AC after solving this problem with binary search🙂.

fflush(stdout) is required, or CPU limit exceeded will be shown in C