Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. import random
  2.  
  3.  
  4. def main():
  5. print("Wpisz liczbę: ")
  6. result = int(input())
  7. tries = 0
  8. finish = False
  9. smallerNumber = 1
  10. greaterNumber = 100
  11.  
  12. while not finish:
  13. compResult = int((smallerNumber+greaterNumber)/2)
  14. print("Komputer zgaduje... Liczba: " + str(compResult))
  15. tries += 1
  16. if compResult == result:
  17. print("Komputer zgadł liczbę " + str(compResult) + " w " + str(tries) + " próbach")
  18. finish = True
  19. elif compResult > result:
  20. greaterNumber = compResult-1
  21. print("Nacisnij dowolny klawisz, w celu kolejnej proby komputer. Bedzie to proba numer " + str(tries+1))
  22. # input()
  23. elif compResult < result:
  24. smallerNumber = compResult+1
  25. print("Nacisnij dowolny klawisz, w celu kolejnej proby komputer. Bedzie to proba numer " + str(tries+1))
  26. # input()
  27.  
  28.  
  29. if __name__ == "__main__":
  30. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement