Traceback (most recent call last):
File "C:/Users/simps/Desktop/tip calculator.py", line 30, in <module>
float (taxsum = check / 4)
TypeError: unsupported operand type(s) for /: 'str' and 'int'
对于我的生活,我无法弄清楚这意味着什么, 如果有帮助,这是我的代码
#A program that allows people to enter information and calculate how much a tip should be
from graphics import *
import math
#setting up the window
win = GraphWin("Tip Calculator", 400, 400)
win.setBackground("teal")
#setting up the input
checksub = Text(Point(150, 150,), "What is the subtotal of the check?:")
checksub.draw(win)
checksub2 = Entry(Point(300,152), 5)
checksub2.draw(win)
tiprate = Text(Point(150,190), "What is the tip rate?:")
tiprate.draw(win)
tiprate2 = Entry(Point(250,190), 3)
tiprate2.draw(win)
#button
Buttontext = Text(Point(150,210), "Compute")
Buttontext.draw(win)
Buttonbox = Rectangle(Point(100,230),Point(200,199))
Buttonbox.draw(win)
#Calculations
win.getMouse()
tip = tiprate2.getText()
check = checksub2.getText()
float (taxsum = check / 4)
float (checktax = taxsum + check)
float (tipsum = checktax / tip)
float (checksum = (tipsum + checktax))
#presenting the output
tipoutput = Text(Point(150,250), "The tip rate is: tipsum")
tipoutput.draw(win)
checkoutput = Text(Point(150,260), "The Check total is: checksum")
checkoutput.draw(win)
答案 0 :(得分:1)
你需要将变量检查从字符串转换为float或int,你可以这样做
int:taxsum = int(check) / 4
浮动:taxsum = float(check) / 4
答案 1 :(得分:0)
将check
转换为int或float然后除。它应该开始工作了。