Mensagens

A mostrar mensagens de dezembro, 2021

Data actual

# O mês foi usado de maneira através do dicionário, neste exemplo from datetime import date data_hoje = date.today() d1 = data_hoje.strftime( "%d/%m/%Y" ) print ( f'A data de hoje é de { d1 } ' ) ano_actual = data_hoje.year print ( f'Ano Actual: { ano_actual } ' ) mes_actual = data_hoje.month mes = { 1 : "Janeiro" , 2 : "Fevereiro" , 3 : "Março" , 4 : "Abril" , 5 : "Junho" , 6 : "Julho" , 7 : "Julho" , 8 : "Agosto" , 9 : "Setembro" , 10 : "Outubro" , 11 : "Novembro" , 12 : "Dezembro" } print ( f'Mês Actual: { mes[mes_actual] } ' ) dia_actual = data_hoje.day print ( f'Dia Actual: { dia_actual } ' ) # O mês foi usado de maneira bruta, neste exemplo from datetime import date data_hoje = date.today() d1 = data_hoje.strftime( "%d/%m/%Y" ) print ( f'A data de hoje é de { d1 } ' ) an...

Contador

print ( "Contador" ) inicio = int ( input ( "Início: " )) fim= int ( input ( "Fim: " )) passo= int ( input ( "Passo: " )) print ( f'Contagem de { inicio } até { fim } ' ) if passo == 0 : passo == 1 if passo < 0 : passo ==passo* (- 1 ) if inicio<fim: contador = 1 while contador <=fim: print ( f' { contador } ' , end = '' ) contador = contador + passo elif inicio==fim: print ( f' { inicio } ' , end = '' ) else : contador = inicio while contador >= fim: print ( f' { contador } ' , end = '' ) contador = contador - passo

Remover todos os valores de uma lista presente em outra lista

import random # Lista Completa clubes = [ "Porto" , "Leça" , "Sporting" , "Rio Ave" , "Tondela" , "Portimonense" , "Mafra" , "Vizela" ] # Criar uma lista de 4 elementos listaA= random.sample(clubes , 4 ) print ( "Lista de Todos os Clubes : " + str (clubes)) # Imprimir O Grupo A print ( " \n Grupo A: " + str (listaA)) # Grupo A: Escolher os pares # random.sample escolha aleatória de elementos de uma lista sem repetição jogo1=random.sample(listaA , 2 ) jogo2=[i for i in listaA if i not in jogo1] print ( f"Primeiro Par de Equipas: { jogo1 } " ) print ( f"Segundo Par de Equipas: { jogo2 } " ) ## Grupo B Escolher os pares listaB = [i for i in clubes if i not in listaA] # Grupo B: Escolher os pares jogo3=random.sample(listaB , 2 ) jogo4=[i for i in listaB if i not in jogo3] print ( " \n Grupo B : " + str (listaB)) print ( f"Terceiro Par de Equipas: { jogo3 } ...

Equação do 2º Grau usandoTkinter

from tkinter import * import math root = Tk() class equacaosegundograu(): def __init__ ( self ): self .root = root self .janela() self .dados() # criando o Loop root.mainloop() def janela ( self ): self .root.title( "Equação de Segundo Grau)" ) self .root.configure( background = '#B0C4DE' ) self .root.geometry( "350x150" ) self .root.resizable( False, False ) def dados ( self ): self .a_entrada = IntVar() self .lb_a = Label( text = 'A:' , font =( 'Verdana' , '8' , 'bold' ) , bg = '#D3D3D3' , fg = '#000000' ) self .lb_a.place( relx = 0.3 , rely = 0.05 , relwidth = 0.1 , relheight = 0.1 ) self .input_a = Entry( textvariable = self .a_entrada) self .input_a.place( relx = 0.45 , r...

Calculadora usando Tkinter

Imagem
from tkinter import * root = Tk() root.title( "Calculadora" ) root.resizable( False,False ) root.geometry( "400x400" ) expressao = "" operacao = StringVar() def press (num): global expressao expressao = expressao + str (num) operacao.set(expressao) def limpar (): global expressao expressao = "" operacao.set( "" ) def teclaigual (): try : global expressao total = str ( eval (expressao)) operacao.set(total) expressao = "" except : operacao.set( " error " ) expressao = "" entrada = Entry( textvariable =operacao , font =( "Verdana" , 15 , ) , bd = 12 ) entrada.place( relx = 0.05 , rely = 0.05 , relwidth = 0.9 , relheight = 0.15 ) butao7 = Button( text = ' 7 ' , fg = 'black' , bg = 'gainsboro' , bd = 3 , command = lambda : press( 7 )) butao7.place( relx = 0.1 , rely = 0.2 , relhe...

Ordenar os Arranjos

import numpy as np import statistics arr = [ 20 , 2 , 7 , 1 , 34 , 100 , 125 , 74 , 84 , 52 , 45 , 95 , 100 ] numeros_ordenados = sorted (arr) # Mediana mediana = np.nanmedian(arr) print ( f"A mediana : { mediana } " ) # Moda moda = statistics.mode(arr) print ( f"A Moda : { moda } " ) # Minimo minimo = np.min(arr) print ( f"Mímino do array: { minimo } " ) # Máximo maximo = np.max(arr) print ( f"Máximo do array: { maximo } " ) print ( f"Array ordenado { numeros_ordenados } " ) print ( "arr : " , arr) print ( f"25 th percentile of arr : { np.percentile(arr , 25 ) } " ) print ( f"50 th percentile of arr : { np.percentile(arr , 50 ) } " ) print ( f"75th percentile of arr : { np.percentile(arr , 75 ) } " )

Arranjos e Combinações matemáticas usando Tkinter

from tkinter import * from tkinter import ttk root=Tk() class app(): def __init__ ( self ): self .root = root self .janela() self .frames_da_janela() self .widgets_frame1() self .Menus() self .root.mainloop() def janela ( self ): self .root.title( "Arranjos e Combinações" ) self .root.configure( background = '#1e3743' ) self .root.geometry( "450x200" ) self .root.resizable( False, False ) def frames_da_janela ( self ): self .frame_1 = Frame( self .root , bd = 4 , bg = '#dfe3ee' , highlightbackground = '#759fe6' , highlightthickness = 2 ) self .frame_1.place( relx = 0.02 , rely = 0.02 , relwidth = 0.96 , relheight = 0.96 ) def widgets_frame1 ( self ): self .abas = ttk.Notebook( self .frame_1) self .arr = Frame( self .abas) self .cob = Frame( self .abas) ...

Contagem decrescente simples (Contagem para o ano novo)

# Contagem decrescente Tkinter from tkinter import * root=Tk() root.title( "Contagem Decrescente" ) root.geometry( "300x150" ) root.resizable( False,False ) def start (t= 10 ): global i i = 1 if i == 1 : cont.config( text = str (t) , font =( 'Impact' , 18 )) if t > 0 : root.after( 1000 , start , t - 1 ) else : a = 'Feliz Ano Novo' cont.config( text = str (a) , font =( 'Impact' , 18 )) cont = Label( text = '' , fg = '#000000' , bg = '#C0C0C0' , font =( 'Times' , 18 )) cont.place( relx = 0.15 , rely = 0.2 , relwidth = 0.65 , relheight = 0.2 ) butao = Button( text = 'START' , fg = '#000000' , bg = '#87CEFA' , font =( 'arial' , 12 ) , command =start) butao.place( relx = 0.3 , rely = 0.6 , relwidth = 0.35 , relheight = 0.2 ) root.mainloop()   # Contagem decrescente simples from time import sleep print ( 'CO...

Transformar para letras maiúscula (usando Tkinter)

from tkinter import * root = Tk() root.title( 'Letra maiúscula' ) root.geometry( "350x150" ) root.resizable( False,False ) def maius (): input= text1.get( "1.0" , END) text1.delete( "1.0" , END) out=input.upper() text1.insert( "1.0" , out) text1=Text() text1.place( relx = 0.05 , rely = 0.05 , relheight = 0.35 , relwidth = 0.9 ) button1 =Button(root , text = "MAIÚSCULA" , font = ( 'arial' , 12 , 'bold' ) , command = maius) button1.place( relx = 0.4 , rely = 0.5 ) root.mainloop()  

Impressora de padrões

ind_numero = int ( input ( "Indica número de linhas: " )) ind_numero = ind_numero+ 1 for num in range (ind_numero): print ( " \n " ) for i in range (num): print (num , end = " " )

Relógio Digital usando tkinter

from time import strftime from tkinter import * root = Tk() root.title( 'Relógio' ) root.geometry( "205x90" ) root.resizable( False,False ) def time (): string = strftime( '%H:%M:%S %p' ) lbl.config( text = string) lbl.after( 1000 , time) lbl = Label(root , font =( 'calibri' , 40 , 'bold' ) , bg = '#ccffcc' , fg = '#31736e' ) lbl.place( relx = 0.05 , rely = 0.05 ) time() mainloop()

Converter Temperatura (usando tkinter)

from tkinter import * root = Tk() root.title( "Converter Temperatura" ) root.geometry( "300x150" ) root.resizable( False,False ) def fahrenheit_para_celsius (): fahrenheit = ent_temperaturaf.get() celsius = ( 5 / 9 ) * ( float (fahrenheit) - 32 ) lbl_result[ "text" ] = f" { round (celsius , 2 ) } \N{DEGREE CELSIUS} " # Fahrenheit para CELSIUS lab_temperaturaf = Label(root , text = "Fahrenheit" , font =( "Arial" , "10" , "bold" )) lab_temperaturaf.place( relx = 0.05 , rely = 0.05 ) lab_temperaturaf = Label(root , text = "Celsius" , font =( "Arial" , "10" , "bold" )) lab_temperaturaf.place( relx = 0.45 , rely = 0.05 ) ent_temperaturaf=DoubleVar() ent_temperaturaf = Entry( textvariable =ent_temperaturaf) ent_temperaturaf.place( relx = 0.05 , rely = 0.2 , relwidth = 0.25 ) btn_convert =Button( text = " \N{RIGHTWARDS BLACK ARROW} " , command =fahr...

Feliz Natal!

n= 0 while n< 4 : print ( "Ho " , end = "" ) n += 1 print ( " \n Feliz Natal!" ) # Àrvore de Natal import random height = 11 for i in range (height): print ( ' ' * (height - i) , end = '' ) for j in range (( 2 * i) + 1 ): if random.random() < 0.1 : color = random.choice([ ' \033 [1;31m' , ' \033 [33m' , ' \033 [1;34m' ]) print (color , end = '' ) else : print ( ' \033 [32m' , end = '' ) print ( '*' , end = '' ) print () for n in range ( 0 , 2 ): print ( " || " ) print ( "_________||__________ \n " )