Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Cara ou Coroa.py
- #
- # Copyright 2021 Elizeu Barbosa Abreu <elizeubcorreios@gmail.com>
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 2 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- # MA 02110-1301, USA.
- #
- #
- import os
- from random import randint
- from time import sleep
- # os.system(clear) limpa a tela
- def cls():
- os.system('clear')
- # Loop atraves do while enquanto a variavel ''continua'' vor verdadeira
- continua = True
- while continua:
- # Título
- print('\n{:^40}'.format('CARA OU COROA?'))
- # Entrada de valores pelo usuário
- print('\nREGRA DO JOGO:\n\nDigite 1 para escolher CARA ou 2 para escolher COROA\nEm seguida tecle ENTER...')
- num = int(input('\nEntre com a escolha: '))
- if num == 1:
- escolhido = 'cara'
- elif num == 2:
- escolhido = 'coroa'
- else:
- print('\nEscolha inválida!')
- # Para o algoritmo caso uma opção inválida seja digitada
- break
- # Tempo determinado pelo sleep da biblioteca time e função cls limpa a tela
- cls()
- print('\n' * 3)
- print('MOEDA LANÇADA AO AR...')
- sleep(1)
- cls()
- print('\n' * 3)
- print('MOEDA CAINDO...')
- sleep(1)
- cls()
- print('\n' * 3)
- print('CONFERINDO A MOEDA...')
- sleep(2)
- cls()
- # Sorteio realizado pelo computador pelo randint
- sorteado = randint(1,2)
- if sorteado == 1:
- pc = 'cara'
- else:
- pc = 'coroa'
- cls()
- # Comparação entre os dados digitados pelo usuário e o sorteado pelo computador
- if num == sorteado:
- print('\n' * 2)
- print('\nParabéns! Você ganhou!\nVocê escolheu {} e saiu {}!!!!'.format(escolhido.upper(), pc.upper()))
- else:
- print('\n' * 2)
- print('\nPerdeu!\nVocê escolheu {} e saiu {}! '.format(escolhido.upper(), pc.upper()))
- sleep(3)
- cls()
- print('\n' * 3)
- print('PREPARANDO UM NOVO JOGO...')
- sleep(3)
- cls()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement