Mensagens

A mostrar mensagens de setembro, 2021

Programa Python para encontrar diâmetro, circunferência e área de um círculo

import math import time def encontrar_diametro (): r = float ( input ( "Digite o valor do raio: " )) d = round (( 2 *r) , 3 ) print ( f'O diâmetro é de { d } ' ) time.sleep( 3 ) def encontrar_area (): r = float ( input ( "Digite o valor do raio: " )) a = round ((math.pi * math.pow(r , 2 )) , 3 ) print ( f'A circunferência é de { a } ' ) time.sleep( 3 ) def encontrar_circunferencia (): r = float ( input ( "Digite o valor do raio: " )) c = round (( 2 *math.pi*r) , 3 ) print ( f'A circunferência é de { c } ' ) time.sleep( 3 ) escolha= True while escolha: print ( " \t Círculo" ) print ( """ 1.Diâmetro 2.Circunferência 3.Área 4.Exit/Quit/Saída """ ) escolha= input ( "Escolha uma opção: " ) if escolha== "1" : print ( ' \n ' ) encontrar_diametro() elif escolha == "...

Número Decimal para Número Romano

def decimalromano (num): val = [ 1000 , 900 , 500 , 400 , 100 , 90 , 50 , 40 , 10 , 9 , 5 , 4 , 1 ] syb = [ "M" , "CM" , "D" , "CD" , "C" , "XC" , "L" , "XL" , "X" , "IX" , "V" , "IV" , "I" ] num_romano = '' i = 0 while num > 0 : for _ in range (num // val[i]): num_romano += syb[i] num -= val[i] i += 1 return num_romano numero = int ( input ( "Digite número inteiro: " )) print (decimalromano(numero))

Escrever uma folha de excel

import openpyxl # Criar Livro livro = openpyxl.Workbook() #Criar uma página livro.create_sheet( 'Frutas' ) # Selecionar uma página frutaspágina = livro[ 'Frutas' ] #Adicionar linha frutaspágina.append([ 'Frutas' , 'Quandidade' , 'Preço' ]) frutaspágina.append([ 'Banana' , '5' , '1.99€' ]) frutaspágina.append([ 'Pêra' , '7' , '2.5€' ]) frutaspágina.append([ 'Morango' , '10' , '2.5€' ]) #Guardar livro.save( 'Inventário.xlsx' )

Fazer aleatório de cartas

import random cartas = [] naipes = [ "Copas" , "Espadas" , "Ouros" , "Paus" ] cartas1 = [ "J" , "Q" , "K" , "A" ] deck = [] for i in range ( 2 , 11 ): cartas.append( str (i)) for j in range ( 4 ): cartas.append(cartas1[j]) for k in range ( 4 ): for l in range ( 13 ): card = (cartas[l] + " de " + naipes[k]) deck.append(card) random.shuffle(deck) numero = int ( input ( "Número da Simulação: " )) for m in range (numero): print (deck[m])

Classificação de triângulos

lado1 = float ( input ( "Digite a medida do lado 1: " )) lado2 = float ( input ( "Digite a medida do lado 2: " )) lado3 = float ( input ( "Digite a medida do lado 3: " )) if lado1 == lado2 and lado2 == lado3 and lado1 == lado3: print ( "É um triângulo equilátero." ) elif lado1 != lado2 and lado2 != lado3 and lado1 != lado3: print ( "É um triângulo escaleno." ) else : print ( "É um triângulo isósceles." ) # Outra Versão from tkinter import * # Função para classificar o triângulo def classificar_triangulo (l1 , l2 , l3): lados = sorted ([l1 , l2 , l3]) a , b , c = lados[ 0 ] , lados[ 1 ] , lados[ 2 ] if a + b <= c: return "Não é um triângulo válido" if a == b == c: classificacao_lados = "Equilátero" elif a == b or b == c: classificacao_lados = "Isósceles" else : classificacao_lados = "Escaleno" if a ** 2 + b ** 2 ...

Conversor de moedas (usando tkinter)

from tkinter import * from tkinter import ttk import requests root =Tk() class RealTimeCurrencyConverter(): def __init__ ( self , url): self .data= requests.get(url).json() self .currencies = self .data[ 'rates' ] def convert ( self , from_currency , to_currency , amount): initial_amount = amount if from_currency != 'USD' : amount = amount / self .currencies[from_currency] amount = round (amount * self .currencies[to_currency] , 4 ) return amount class convertermoeda(RealTimeCurrencyConverter): def __init__ ( self ): self .root = root self .janela() self .aplicacao() root.mainloop() def janela ( self ): self .root.title( "Converter Moedas" ) self .root.geometry( "445x300" ) self .root.resizable( False, False ) def aplicacao ( self ): # Moeda Inical self .moeda_inicial = StringVar() self .optio...

Converter moedas (simples)

import requests class RealTimeCurrencyConverter(): def __init__ ( self , url): self .data= requests.get(url).json() self .currencies = self .data[ 'rates' ] def convert ( self , from_currency , to_currency , amount): initial_amount = amount # first convert it into USD if it is not in USD. # because our base currency is USD if from_currency != 'USD' : amount = amount / self .currencies[from_currency] # limiting the precision to 4 decimal places amount = round (amount * self .currencies[to_currency] , 4 ) return amount def list (): print ( ' AOA - Angola Kwanza, ARS - Peso Argentino, EUR - Euro, ' 'USD- Dólar Americano, ' 'INR- Rupia Indiana, BRL - Real Brasileiro,' ' AUD- Dólar Australiano, \n GBP- Libras,' 'COP - Peso Colombiano, HUF- Florin, VES- Venuzuela,' ' JPY- Iene...

Fases da vida (terminal e Tkinter)

def perguntar (): try : idade = int ( input ( "Digite a tua idade : " )) if idade >= 18 : print ( "Tu és Adulto." ) elif idade>= 13 and idade<= 17 : print ( "Tu és Adolescente." ) elif idade >= 12 : print ( "Tu és Criança." ) except : print ( " \033 [1;31m Opa! entrada invalida :( \33 [0;0m" ) perguntar() escolha= True while escolha: print ( " \t Qual é sua Fase de vida?" ) print ( """ 1.Fases da vida 2.Exit/Quit/Saída """ ) escolha= input ( "Escolha uma opção: " ) if escolha== "1" : print ( ' \n ' ) perguntar() elif escolha== "2" : print ( " \n Fim do Programa" ) escolha = None else : print ( " \n \033 [1;31m Escolha não válida. \n Tente outra vez. \33 [0;0m" ) # Out...

Decodificar qcode

Outros Artigos: Fazer qrcode usando tkinter from pyzbar.pyzbar import decode from PIL import Image # Imagem teste1.png é um exemplo img = Image.open( 'teste1.png' ) result = decode(img) for i in result: print (i.data.decode( "utf-8" ))

qrcode usando tkinter

Imagem
Outros Artigos: Descodificar qrcode from tkinter import * import pyqrcode from PIL import Image , ImageTk root = Tk() root.title( " Aplicação QR code " ) root.geometry( "600x600" ) root.resizable( False, False ) root.configure( background = '#09A3BA' ) def generate (): if nome_salvar.get() != '' and nome_salvar.get() != '' : site1 = site.get() qr =pyqrcode.create(site1) img = qr.png(nome_salvar.get()+ ".png" , scale = 6 ) img = Image.open(nome_salvar.get()+ ".png" ) img = ImageTk.PhotoImage(img) canvas1.create_image( 200 , 150 , image =img) canvas1.image=img else : info = Label( text = "Please enter the data for QR code" , font =( 'ariel 15 bold' )) info.place( relx = 0.5 , rely = 0.7 ) site = StringVar() texto = Label( text = "Nome do Site: " , background = '#09A3BA' , fore...

Calcular troco usando tkinter

Imagem
from tkinter import * root = Tk() root.title( 'Calcular o troco ' ) root.geometry( "400x250" ) root.resizable( False, False ) root.configure( background = '#09A3BA' ) def calcular (): dr = dinheiro_recido.get() da = dinheiro_a_pagar.get() troco = dr-da if troco == 0 : troco = 'Não existe troco, dinheiro recebido \n é igual ao ' \ 'dinheiro a pagar.' elif troco < 0 : troco = 'Não existe troco, dinheiro recebido \n é inferior' \ ' ao dinheiro a pagar.' else : troco = troco return resultado.set(troco) # Introduzir Valores dinheiro_a_pagar_label = Label( text = "Dinheiro a Pagar:" , background = '#09A3BA' , foreground = "#FFFFFF" ) dinheiro_a_pagar_label.place( relx = 0.1 , rely = 0.1 ) dinheiro_a_pagar = DoubleVar() dpagar = Entry( textvariable =dinheiro_a_pagar) dpagar.plac...

Área do triângulo (usando tkinter)

from tkinter import * def calculate_area (): base1 = float (base.get()) altura1 = float (altura.get()) area = 1 / 2 * base1 * altura1 resultado_label.configure( text = 'Área do triângulo= {:.2f} ' .format(area)) root = Tk() root.title( 'Área do triângulo ' ) root.geometry( "500x500" ) root.resizable( False, False ) base_label = Label( text = 'Base: ' , font =( ' Verdana ' , 18 )) base_label.place( relx = 0.15 , rely = 0.1 ) base = DoubleVar() entrada_base = Entry( textvariable =base) entrada_base.place( relx = 0.4 , rely = 0.12 ) altura_label = Label( text = ' Altura: ' , font =( ' Verdana ' , 18 )) altura_label.place( relx = 0.15 , rely = 0.25 ) altura = DoubleVar() entrada_altura = Entry( textvariable =altura) entrada_altura.place( relx = 0.4 , rely = 0.27 ) resultado_label = Label( font =( ' Verdana ' , 18 ) , text = 'A àrea do triângulo é:' ) resultado_label.place( relx = 0.2 , rely = 0.65 ) r...

Tabuada (usando tkinter)

Imagem
  from tkinter import * root =Tk() class App(): def __init__ ( self ): self .root = root self .config() self .create_widgets() root.mainloop() def config ( self ): self .root.title( "Tabuada" ) self .root.geometry( "250x250" ) self .root.resizable( False, False ) def create_widgets ( self ): self .result_label = Label( text = "Digite um número: " ) self .result_label.place( relx = 0.35 , rely = 0.05 ) self .number = IntVar() self .number_entry = Entry( textvariable = self .number) self .number_entry.place( relx = 0.35 , rely = 0.15 ) self .button =Button( text = "ok" , width = 4 , command = self .update_result) self .button.place( relx = 0.4 , rely = 0.25 , relwidth = 0.25 ) def update_result ( self ): self .result_label[ "text" ] = ' \n ' .join([ "{x} * {y} = {result}" .fo...