Mundo em Python

Estatística

from tkinter import *

root = Tk()
root.geometry("400x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Estatística")
titulo = Label(text="Estatística", font=("Arial", "28", "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.25, rely=0.05) texto_sub1 = Label(text="Total de Tentativas:", font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.05, rely=0.3)
texto_sub2 = Label(text="Ganhados:", font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub2.place(relx=0.3, rely=0.5)
Total_Tentativas = StringVar()
Total_Tentativas_entrada = Entry(textvariable=Total_Tentativas, font=("Arial", "12", "bold"), bg="white", fg="blue",
justify='center')
Total_Tentativas_entrada.place(relx=0.65, rely=0.31, relwidth=0.25) Ganhados = StringVar()
Ganhados_entrada = Entry(textvariable=Ganhados, font=("Arial", "12", "bold"), bg="white", fg="blue", justify='center')
Ganhados_entrada.place(relx=0.65, rely=0.51, relwidth=0.25) def limpar():
Total_Tentativas_entrada.delete(0, END)
Ganhados_entrada.delete(0, END)
resultado_texto.config(text="")
def app():
try:
tentativas = int(Total_Tentativas.get())
sucesso = int(Ganhados.get()) if sucesso > tentativas:
mensagem = "As jogadas ganhas não podem \nser maiores que as tentativas."
else:
taxa_sucesso = (sucesso / tentativas) * 100
mensagem = f"Taxa de Sucesso: {round(taxa_sucesso, 2)}%"

resultado_texto.config(text=mensagem)
except ValueError:
resultado_texto.config(text="Valor digitado inválido.") but1 = Button(text="Calcular", bd=2, bg='#107db2', fg='white', font=('verdana', 12, 'bold'), command=app)
but1.place(relx=0.1, rely=0.65, relwidth=0.25, relheight=0.1) but_limpar = Button(text="Limpar", bd=2, bg='#107db2', fg='white', font=('verdana', 12, 'bold'), command=limpar)
but_limpar.place(relx=0.4, rely=0.65, relwidth=0.25, relheight=0.1) but_sair = Button(text="Sair", bd=2, bg='#107db2', fg='white', font=('verdana', 12, 'bold'), command=root.destroy)
but_sair.place(relx=0.7, rely=0.65, relwidth=0.25, relheight=0.1) resultado_texto = Label(text="", font=("Arial", 12, "bold"), bg="#cfe2f3")
resultado_texto.place(relx=0.05, rely=0.8, relwidth=0.9, relheight=0.15) root.mainloop()

# Calcular os ganhos


from tkinter import *

root = Tk()
root.geometry("400x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Estatística")
titulo = Label(text="Estatística", font=("Arial", "28", "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.25, rely=0.05) texto_sub1 = Label(text="Total de Tentativas:", font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.05, rely=0.3)
texto_sub2 = Label(text="Taxa de Sucesso(em %):", font=("Arial", "15", "bold"), bg="#103030", fg="#49e3e3")
texto_sub2.place(relx=0.05, rely=0.5)
Total_Tentativas = StringVar()
Total_Tentativas_entrada = Entry(textvariable=Total_Tentativas, font=("Arial", "12", "bold"), bg="white", fg="blue",
justify='center')
Total_Tentativas_entrada.place(relx=0.65, rely=0.31, relwidth=0.25) Taxa_Sucesso = StringVar()
Taxa_Sucesso_entrada = Entry(textvariable=Taxa_Sucesso, font=("Arial", "12", "bold"), bg="white", fg="blue", justify='center')
Taxa_Sucesso_entrada.place(relx=0.65, rely=0.51, relwidth=0.25) def limpar():
Total_Tentativas_entrada.delete(0, END)
Taxa_Sucesso_entrada.delete(0, END)
resultado_texto.config(text="")
def app():
try:
tentativas = int(Total_Tentativas.get())
taxa = int(Taxa_Sucesso.get())/100
ganhos =tentativas*taxa
mensagem = f"Ganhos: {round(ganhos)}"

resultado_texto.config(text=mensagem)
except ValueError:
resultado_texto.config(text="Valor digitado inválido.") but1 = Button(text="Calcular", bd=2, bg='#107db2', fg='white', font=('verdana', 12, 'bold'), command=app)
but1.place(relx=0.1, rely=0.65, relwidth=0.25, relheight=0.1) but_limpar = Button(text="Limpar", bd=2, bg='#107db2', fg='white', font=('verdana', 12, 'bold'), command=limpar)
but_limpar.place(relx=0.4, rely=0.65, relwidth=0.25, relheight=0.1) but_sair = Button(text="Sair", bd=2, bg='#107db2', fg='white', font=('verdana', 12, 'bold'), command=root.destroy)
but_sair.place(relx=0.7, rely=0.65, relwidth=0.25, relheight=0.1) resultado_texto = Label(text="", font=("Arial", 12, "bold"), bg="#cfe2f3")
resultado_texto.place(relx=0.05, rely=0.8, relwidth=0.9, relheight=0.15) root.mainloop()
0