Untitled - MARKUP 0.65 KB
                                
                                    ''''Tomasz Kostrzewa id_62 Odgadywanie liczby naturalnej<100'''

x,y,z = 1,99,50
print('AI: Pomyśl liczbę naturalną < 100, a ja ją odgadnę.',
      '\nPodam Ci liczbę, a Ty odpowiedz kodem:',
      '\nza dużo - 3; za mało - 1; zgadłem - 2')
res = int(input(str(z)+' > '))
while res not in (1,2,3):
    res = int(input('? >'))

while res != 2 and x <= y:
    if res == 1: x = z+1
    else:  y = z-1
    z = ( x + y) // 2
    res = int(input(str(z) + ' > '))
    while res not in (1, 2, 3):
        res = int(input('? >'))

if res == 2: print('Zgadlem! To ', z)
else: print('Przedzial jest pusty!')
                                
                            

Paste Hosted With By Wklejamy.pl