와 부문 별 0 오류가 나는 다음과 같은 코드가 있습니다Python3 : 소수
from tkinter import *
################### Variables
Screenx = "640"
Screeny = "480"
screenSize = str(Screenx + "x" + Screeny)
global BTC
BTC = 0.00
global processor
processor = 5
global USD
USD = 150000
global Auto_Miners
Auto_Miners = 1
global Computers
Computers = 3
global MinePower
MinePower = Computers * (0.0001 * processor)
global entryText
entryText = ('empty')
global entryPurpose
entryPurpose = "Nothing"
global BTCPrice
BTCPrice = 0.5
################## Function Definitions
def Mine_BTC():
global MinePower
global BTC
BTC = BTC + MinePower
print("Mining " + str(MinePower) + " BitCoins...")
BitCoinLabel2.config(text=str(BTC))
def Buy_AM():
global Auto_Miners
global USD
if USD >= 100:
Auto_Miners = Auto_Miners + 1
print("Bought 1 autominer...")
AutominersLabel1.config(text=Auto_Miners)
USD = USD - 100
else:
print("Damn you are poor...")
def Buy_Computers():
global Computers
global USD
if USD >= 300:
Computers = Computers + 1
print("Bought 1 Computer...")
ComputerLabel1.config(text=Computers)
USD = USD - 300
else:
print("Damn you are poor...")
def Buy_Processor():
global USD
global processor
if USD >= 450:
processor = processor + 1
print("PP + 1")
ProLabel.config(text=processor)
USD = USD - 450
else:
print("What a poor man...")
def EnterButton():
global entryText
global entryPurpose
global BTC
global USD
text_E = EntryA.get()
print(text_E)
if entryPurpose == ("How many USD to BTC?"):
BTC = BTC + (int(text_E) % int(BTCPrice))
print(BTC)
USD = USD - text_E
print(USD)
elif entryPurpose == ("How many BTC to USD?"):
USD = text_E * BTCPrice
print(USD)
BTC = BTC - int(text_E)
print(BTC)
def BuyBTC():
global entryPurpose
print(entryPurpose)
entryPurpose = ("How many USD to BTC?")
print(entryPurpose)
entryP.config(text=entryPurpose)
def SellBTC():
entryPurpose = "How many BTC to USD?"
entryP.config(text=entryPurpose)
################# Screen Mainloop
screen = Tk()
screen.title("BitCoin Simulator")
screen.geometry(screenSize)
canvas = Canvas()
canvas.pack()
canvas.create_line(10, 0, 10, 600)
canvas.create_rectangle(200, 30, 350, 200)
EntryA = Entry(screen, textvariable=entryText)
EntryA.place(x=150, y=300)
EntryB = Button(screen, text="Enter", bg="blue")
EntryB.config(command=EnterButton)
EntryB.place(x=170, y=350)
BitCoinLabel1 = Label(screen, text="BitCoins: ").place(x=150, y=10)
BitCoinLabel2 = Label(screen, text=str(BTC)) ###
BitCoinLabel2.place(x=220, y=10)
MineButton = Button(screen, text="Mine")
MineButton.config(command=Mine_BTC)
MineButton.place(x=150, y=30)
AutominersButton = Button(screen, text="Auto-Miners:")
AutominersButton.config(command=Buy_AM)
AutominersButton.place(x=150, y=80)
AutominersLabel1 = Label(screen, text=Auto_Miners)
AutominersLabel1.place(x=270, y=85)
ComputersButton = Button(screen, text="Computers:")
ComputersButton.config(command=Buy_Computers)
ComputersButton.place(x=150, y=120)
ComputerLabel1 = Label(screen, text=Computers)
ComputerLabel1.place(x=270, y=120)
ProButton = Button(screen, text="Processors:")
ProButton.config(command=Buy_Processor)
ProButton.place(x=150, y=180)
ProLabel = Label(screen, text=processor)
ProLabel.place(x=285, y=180)
BuyButton = Button(screen, text="BUY")
BuyButton.config(command=BuyBTC)
BuyButton.place(x=340, y=170)
SellButton = Button(screen, text="SELL")
SellButton.config(command=SellBTC)
SellButton.place(x=410, y=170)
entryP = Label(screen, text=str(entryPurpose))
entryP.place(x=150, y=270)
screen.mainloop()
위의 코드는 비트 코인에 대한 작업 작은 프로그램 메신저입니다, 그것은 완성 된 밤은. 라인 88
이 코드가 있습니다
나는 0 오류에 의해 부서를 얻을 수 BTC = BTC + (INT (text_E) %의 INT (BTCPrice를)) ... text_E는 BTCPrice가 설정 0은 결코 ~ 0.01. 9 또는 6578과 같은 것으로 변경하면 오류가 발생하지 않습니다. 그래서 나는 10 진수 (그리고 단지 0.01; 0.88과 0.02828도 아님)를 0으로 추측합니다. 나는 /와 %를 사용하여 나누려고했지만 같은 결과를 얻습니다. 누군가가이 문제를 해결할 수있는 방법을 말해 줄 수 있습니까? 감사합니다.
'int '가 무엇을 의미하는지 알고 있습니까? – user2357112
당신은'double'을'int'로 변환하고 있으므로 모든 십진수는 int (반올림)로 변환됩니다. 따라서 모든 값은 '0'으로 시작하여 '0'으로 변환됩니다. '(text_E % BTCPrice) '와 같은 문장을 사용하십시오. –
그것은 우리가 이해하기에는 너무 많은 코드입니다. 그것을 응축시켜 [mcve] –