Advertisement
elizeub

Jogo Cara e Coroa em Python

Jul 18th, 2021 (edited)
535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.46 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #  Cara ou Coroa.py
  4. #  
  5. #  Copyright 2021 Elizeu Barbosa Abreu <elizeubcorreios@gmail.com>
  6. #  
  7. #  This program is free software; you can redistribute it and/or modify
  8. #  it under the terms of the GNU General Public License as published by
  9. #  the Free Software Foundation; either version 2 of the License, or
  10. #  (at your option) any later version.
  11. #  
  12. #  This program is distributed in the hope that it will be useful,
  13. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. #  GNU General Public License for more details.
  16. #  
  17. #  You should have received a copy of the GNU General Public License
  18. #  along with this program; if not, write to the Free Software
  19. #  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  20. #  MA 02110-1301, USA.
  21. #  
  22. #
  23.  
  24. import os
  25. from random import randint
  26. from time import sleep
  27.  
  28. # os.system(clear) limpa a tela
  29. def cls():
  30.     os.system('clear')
  31.  
  32. # Loop atraves do while enquanto a variavel ''continua'' vor verdadeira
  33. continua = True
  34. while continua:
  35.    
  36.     # Título  
  37.    
  38.     print('\n{:^40}'.format('CARA OU COROA?'))
  39.    
  40.     # Entrada de valores pelo usuário
  41.    
  42.     print('\nREGRA DO JOGO:\n\nDigite 1 para escolher CARA ou 2 para escolher COROA\nEm seguida tecle ENTER...')
  43.     num = int(input('\nEntre com a escolha: '))
  44.    
  45.    
  46.     if num == 1:
  47.         escolhido = 'cara'
  48.     elif num == 2:
  49.         escolhido = 'coroa'
  50.     else:
  51.         print('\nEscolha inválida!')
  52.         # Para o algoritmo caso uma opção inválida seja digitada
  53.         break
  54.        
  55.     # Tempo determinado pelo sleep da biblioteca time e função cls limpa a tela
  56.     cls()
  57.     print('\n' * 3)
  58.     print('MOEDA LANÇADA AO AR...')       
  59.     sleep(1)
  60.     cls()
  61.    
  62.     print('\n' * 3)
  63.     print('MOEDA CAINDO...')
  64.     sleep(1)
  65.     cls()
  66.    
  67.     print('\n' * 3)
  68.     print('CONFERINDO A MOEDA...')
  69.     sleep(2)
  70.     cls()  
  71.        
  72.        
  73.     # Sorteio realizado pelo computador pelo randint   
  74.     sorteado = randint(1,2)
  75.     if sorteado == 1:
  76.         pc = 'cara'
  77.     else:
  78.         pc = 'coroa'
  79.    
  80.     cls()
  81.    
  82.     # Comparação entre os dados digitados pelo usuário e o sorteado pelo computador
  83.     if num == sorteado:
  84.         print('\n' * 2)
  85.         print('\nParabéns! Você ganhou!\nVocê escolheu {} e saiu {}!!!!'.format(escolhido.upper(), pc.upper()))
  86.     else:
  87.         print('\n' * 2)
  88.         print('\nPerdeu!\nVocê escolheu {} e saiu {}! '.format(escolhido.upper(), pc.upper()))
  89.    
  90.     sleep(3)
  91.     cls()
  92.     print('\n' * 3)
  93.     print('PREPARANDO UM NOVO JOGO...')
  94.     sleep(3)
  95.     cls()
  96.    
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement