elizeub

Jogo de Adivinhar em python

Aug 8th, 2021 (edited)
1,026
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.20 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. #  Advinhe o Numero.py
  5. #  
  6. #  Copyright 2021 Elizeu Barbosa Abreu <[email protected]>
  7. #  
  8. #  This program is free software; you can redistribute it and/or modify
  9. #  it under the terms of the GNU General Public License as published by
  10. #  the Free Software Foundation; either version 2 of the License, or
  11. #  (at your option) any later version.
  12. #  
  13. #  This program is distributed in the hope that it will be useful,
  14. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. #  GNU General Public License for more details.
  17. #  
  18. #  You should have received a copy of the GNU General Public License
  19. #  along with this program; if not, write to the Free Software
  20. #  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  21. #  MA 02110-1301, USA.
  22. #  
  23. #  
  24. from time import sleep
  25. import os
  26. from random import randint
  27.  
  28. def cls():
  29.     os.system('clear')
  30.  
  31. def titulo():
  32.     print('{}{:^50}{}'.format('\033[7m', 'JOGO ADVINHE O NÚMERO', '\033[m'))
  33.  
  34. def game():
  35.     count = 0
  36.     humano = 1000
  37.     computador = randint(1, 10)
  38.     # primeira pagina
  39.     cls()
  40.     titulo()
  41.     nome = str(input('''
  42.     Olá sou a I.A. mais conhecida como Inteligência artificial.
  43. Vou pensar em um número e espero que você advinhe na menor quantidade de tentativas...
  44. Mais antes quero saber um pouco mais sobre você...
  45.  
  46. >>>> Qual é o seu nome? '''))
  47.  
  48. # segunda página
  49.     cls()
  50.     titulo()
  51.    
  52.     humano = int(input(f'''
  53. Olá {nome}, que bom te conhecer...
  54. Pensei em um número entre 0 e 10...
  55. Tente advinhar o número que pensei!!!
  56. Espero que você acerte na primeira tentativa!!!
  57.  
  58. >>>> Digite o número que pensei: '''))
  59.  
  60.     while humano != computador:
  61.         if humano > computador:
  62.             humano = int(input(f'\n{nome}, não foi desta vez!\nTente outro número menor: '))
  63.             count += 1
  64.         if humano < computador:
  65.             humano = int(input(f'\n{nome}, não foi desta vez!\nTente outro número maior: '))
  66.             count += 1
  67.     else:
  68.         count += 1
  69.         print(f'''
  70. Parabéns {nome},
  71. Você acertou em {count} tentativas!!!''')
  72.  
  73. while True:
  74.     game()
  75.     sleep(7)
  76.     cls()
  77.     titulo()
  78.     print('\nQuando quiser sair tecle [ctrl+C]...')
  79.     sleep(2)
  80.  
Advertisement
Add Comment
Please, Sign In to add comment