I know this could be a stupid question but I can’t seem to actually do it.
I’m trying to do this:
f = open("txtfiles/c.txt", "r")
c = f.read()
int(c)
ca = float(input("Enter Cash to Add: "))
int(ca)
cn= c+ca
print (cn)
I have tried to say they are both floats so that they can be added properly because I need the user to be able to add decimals but when ever I do it I get
TypeError: Can’t convert ‘float’ object to str implicitly
I have searched on the internet and I have seen this error come up loads but nothing has actually seemed to help.
Sorry for the noob question but any suggestion would be appreciated.
When you do
int(c)this will generate a integer from the stringcbut you don’t assign it to anything. In your casecwill still be a string. Change that line to:Even better, since you want to get decimals added too why not just use floats and skip the integer conversion?