Mensagens

A mostrar mensagens de abril, 2024

Jogo do número Primo

from tkinter import Tk , Label , IntVar , Radiobutton , Button import random def is_prime (n): if n <= 1 : return False elif n <= 3 : return True elif n % 2 == 0 or n % 3 == 0 : return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2 ) == 0 : return False i += 6 return True def selecionar (): escolha1 = resposta1.get() if (escolha1 == 1 and is_prime(escolha_aleatoria)) \ or (escolha1 == 0 and not is_prime(escolha_aleatoria)): resultado_texto.config( text = "Parabéns! Você acertou!" ) else : resultado_texto.config( text = "Ops! Você errou!" ) def novo_jogo (): global escolha_aleatoria escolha_aleatoria = random.randint( 0 , 30 ) escolha_número.config( text =escolha_aleatoria) resultado_texto.config( text = "" ) root = Tk() root.geometry( "400x400" ) root.resizable( 0 , 0 ) root.config( bg = "#10...

Raiz Quadrado(usando Tkinter)

from tkinter import * import math root = Tk() root.geometry( "300x300" ) root.resizable( 0 , 0 ) root.config( bg = "#d9ead3" ) root.title( "Raiz Quadrado" ) def app (): n = Número.get() rquadrado = round (math.sqrt(n) , 2 ) if rquadrado < 0 : rquadrado = 'Não tem raiz quadrado' resultado.set(rquadrado) def limpar (): Número_entrada.delete( 0 , END) titulo = Label( text = "Raiz Quadrado" , font =( "Arial" , "15" , "bold" ) , bg = "#d9ead3" , fg = "#bf9000" ) titulo.place( relx = 0.3 , rely = 0.05 ) texto_sub1 = Label( text = "Número :" , font =( "Arial" , "12" , "bold" ) , bg = "#d9ead3" , fg = "#bf9000" ) texto_sub1.place( relx = 0.2 , rely = 0.25 ) Número = IntVar() Número_entrada = Entry( textvariable =Número , font =( "Arial...

Calcular calorias diárias (usando tkinter)

from tkinter import * def calcular_calorias ( event=None ): try : peso = float (entry_peso.get()) altura = float (entry_altura.get()) idade = int (entry_idade.get()) genero = var_genero.get() atividade = var_atividade.get() if genero == 1 : # Masculino if atividade == 1 : # Sedentário resultado = ( 10 * peso) + ( 6.25 * altura) - ( 5 * idade) + 5 elif atividade == 2 : # Levemente ativo resultado = ( 10 * peso) + ( 6.25 * altura) - ( 5 * idade) + 5 + 200 elif atividade == 3 : # Moderadamente ativo resultado = ( 10 * peso) + ( 6.25 * altura) - ( 5 * idade) + 5 + 400 elif atividade == 4 : # Muito ativo resultado = ( 10 * peso) + ( 6.25 * altura) - ( 5 * idade) + 5 + 600 elif genero == 2 : # Feminino if atividade == 1 : # Sedentário resultado = ( 10 * peso) + ( 6.25 * altura) - ( 5 * id...

Nomes de Bandas (usando Tkinter)

from tkinter import * import random import pyperclip root = Tk() root.geometry( "400x400" ) root.resizable( 0 , 0 ) root.config( bg = "#103030" ) root.title( "Nomes de Bandas" ) titulo = Label( text = "Nomes de Bandas" , font =( "Arial" , "28" , "bold" ) , bg = "#103030" , fg = "#49e3e3" ) titulo.place( relx = 0.08 , rely = 0.05 ) def app (): adjetivos = [ "Os Enigmáticos" , "Os Radiantes" , "Os Místicos" , "Os Rebeldes" , "Os Virtuosos" , "Os Cósmicos" ] substantivos = [ "Guerreiros do Som" , "Viajantes do Tempo" , "Sábios do Rock" , "Cavaleiros do Caos" , "Pioneiros do Éter" , "Poetas do Vento" ] nome_banda = random.choice(adjetivos) + " " + random.choice(substantivos) mensagem = f"Nome da Banda: \n { nome_banda ...

Converter Texto em Braille

from tkinter import * root = Tk() root.geometry( "400x400" ) root.resizable( 0 , 0 ) root.config( bg = "#103030" ) root.title( "Converter Texto em Braille " ) titulo = Label( text = "Converter Texto em Braille" , font =( "Arial" , "21" , "bold" ) , bg = "#103030" , fg = "#49e3e3" ) titulo.place( relx = 0.03 , rely = 0.05 ) sub1 = Label( text = "Digite o Texto" , font =( "Arial" , "15" , "bold" ) , bg = "#103030" , fg = "#49e3e3" ) sub1.place( relx = 0.3 , rely = 0.2 ) texto = StringVar() texto_entrada = Entry( textvariable =texto , font =( "Arial" , "12" , "bold" ) , bg = "white" , fg = "blue" , justify = 'center' ) texto_entrada.place( relx = 0.05 , rely = 0.3 , relwidth = 0.9 ) texto_entrada.focus() def limpar (): texto_e...

A Bandeira reflete o estado a que o 25 de Abril actualmente

import turtle # Função para desenhar um retângulo colorido def draw_rectangle (x , y , width , height , color): t.penup() t.goto(x , y) t.pendown() t.color(color) t.begin_fill() for _ in range ( 2 ): t.forward(width) t.right( 90 ) t.forward(height) t.right( 90 ) t.end_fill() # Função para desenhar um círculo colorido def draw_circle (x , y , radius , color): t.penup() t.goto(x , y - radius) t.pendown() t.color(color) t.begin_fill() t.circle(radius) t.end_fill() # Inicialização da tela e tartaruga screen = turtle.Screen() screen.setup( width = 600 , height = 400 ) screen.bgcolor( "white" ) t = turtle.Turtle() t.speed( 0 ) # Cores da bandeira de Portugal green = "#009e49" red = "#ff0000" yellow = "#ffcc00" ## Desenhar o retângulo verde à esquerda draw_rectangle(- 100 , 100 , - 200 , 400 , green) # Desenhar o retângulo vermelho à direita draw_rectangle( 100 , 100...

Viva a Liberdade

import turtle screen = turtle.Screen() screen.setup( width = 600 , height = 400 ) screen.bgcolor( "white" ) screen.title( "Viva a Liberdade!" ) # Alterar o título da janela t = turtle.Turtle() t.speed( 0 ) # Função para desenhar um retângulo colorido def draw_rectangle (x , y , width , height , color): t.penup() t.goto(x , y) t.pendown() t.color(color) t.begin_fill() for _ in range ( 2 ): t.forward(width) t.right( 90 ) t.forward(height) t.right( 90 ) t.end_fill() # Função para desenhar um círculo colorido def draw_circle (x , y , radius , color): t.penup() t.goto(x , y - radius) t.pendown() t.color(color) t.begin_fill() t.circle(radius) t.end_fill() # Cores da bandeira de Portugal green = "#009e49" red = "#ff0000" yellow = "#ffcc00" # Desenhar o retângulo verde à esquerda draw_rectangle(- 200 , 100 , 200 , 400 , green) # Desenhar o retângulo vermelh...

Distância do relâmpago

from tkinter import * root = Tk() root.geometry( "500x400" ) root.resizable( 0 , 0 ) root.config( bg = "#103030" ) root.title( "Distância do relâmpago " ) titulo = Label( text = "Distância do Relâmpago" , font =( "Arial" , "23" , "bold" ) , bg = "#103030" , fg = "#49e3e3" ) titulo.place( relx = 0.1 , rely = 0.05 ) sub1 = Label( text = "Tempo entre o flash e o som (em segundos)" , font =( "Arial" , "16" , "bold" ) , bg = "#103030" , fg = "#49e3e3" ) sub1.place( relx = 0.05 , rely = 0.25 ) tempo = StringVar() tempo_entrada = Entry( textvariable =tempo , font =( "Arial" , "13" , "bold" ) , bg = "white" , fg = "blue" , justify = 'center' ) tempo_entrada.place( relx = 0.35 , rely = 0.35 , relwidth = 0.35 ) tempo_entrada.focus() def limpar (): ...

Semáforo de Passadeira e de Perigo

from tkinter import * root = Tk() root.title( "Semáforo de Passadeira" ) root.resizable( False, False ) frame = Frame(root) frame.pack() canvas = Canvas(root , width = 150 , height = 250 , bg = "white" ) canvas.pack() canvas.create_rectangle( 3 , 5 , 150 , 400 , fill = "black" ) x = 1 def move (): global x if x == 3 : x = 1 canvas.delete( "all" ) # Limpa o canvas a cada atualização if x == 1 : canvas.create_oval( 10 , 10 , 140 , 110 , fill = "red" ) canvas.create_oval( 10 , 130 , 140 , 230 , fill = "black" ) elif x == 2 : canvas.create_oval( 10 , 10 , 140 , 110 , fill = "black" ) canvas.create_oval( 10 , 130 , 140 , 230 , fill = "green" ) x += 1 root.after( 2000 , move) move() root.mainloop() # Sinalização de Perigo from tkinter import * root = Tk() root.title( "Sinalização de Perigo" ) root.resizable( False, False ) frame = Fram...

Gestão Água

import time class GestãoAgua: def __init__ ( self ): self .quantidade_agua = 0 def adicionar_agua ( self , quantidade): if self .quantidade_agua + quantidade <= 100 : self .quantidade_agua += quantidade print ( f"Quantidade de água atualizada para { self .quantidade_agua } litros. \n " ) time.sleep( 3 ) else : print ( "Não é possível adicionar mais água. Limite máximo atingido. \n " ) time.sleep( 3 ) def remover_agua ( self , quantidade): if self .quantidade_agua - quantidade >= 0 : self .quantidade_agua -= quantidade print ( f"Quantidade de água atualizada para { self .quantidade_agua } litros. \n " ) time.sleep( 3 ) else : print ( "Não é possível remover mais água. A quantidade atual é zero. \n " ) time.sleep( 3 ) def mostrar_quantidade ( self ): print ( f...

Classificação de Pessoas (usando Tkinter)

from tkinter import * from datetime import datetime root = Tk() root.geometry( "400x400" ) root.resizable( 0 , 0 ) root.config( bg = "#103030" ) root.title( "Classificação de Pessoas" ) titulo = Label( text = "Classificação de Pessoas" , font =( "Arial" , "23" , "bold" ) , bg = "#103030" , fg = "#49e3e3" ) titulo.place( relx = 0.03 , rely = 0.05 ) validade = Label( text = "Data Nascimento (YYYY-MM-DD) " , font =( "Arial" , "15" , "bold" ) , bg = "#103030" , fg = "#49e3e3" ) validade.place( relx = 0.13 , rely = 0.25 ) data = StringVar() data_entrada = Entry( textvariable =data , font =( "Arial" , "12" , "bold" ) , bg = "white" , fg = "blue" , justify = 'center' ) data_entrada.place( relx = 0.3 , rely = 0.35 , relwidth = 0.45 ) data_entrada.focus() def limpar (): data_entrada.del...