Sep-03-2017, 07:18 PM
Hi, I am trying to program an ATM but I got a problem because I want to save and read out the available money but I need to calculate the number that is in the .txt file I experimented a bit but I can't figure it out. Sorry that my variables and everything else is in German but you should understand what I am trying to do, if not I will explain it. So what I am trying to do is read out the file "kontostand.txt" in which the amount of money is in and calculate -50 for -50€ but I can't calculate the output or a string but I am not able to convert it to a string it gives this error: rechnung_kontostand = int(zwischenschritt)
ValueError: invalid literal for int() with base 10: "<_io.TextIOWrapper name='kontostand.txt' mode='r' encoding='UTF-8'>". Another problem is that what is saved to my .txt is "-50".
thanks
ValueError: invalid literal for int() with base 10: "<_io.TextIOWrapper name='kontostand.txt' mode='r' encoding='UTF-8'>". Another problem is that what is saved to my .txt is "-50".
thanks
main = 1 behebung = 0 rechnung_kontostand = 0 ergebniss_kontostand = 0 ergebniss_kontostand2 = "" while main == 1: main = 0 print("Möchten Sie \n 1) Beheben \n 2) Einzahlen \n 3) Kontostand \n 4) Bewegungen \n 5) beenden") auswahl = input() if auswahl == "1": behebung = 1 while behebung == 1: behebung = 0 behebung_auswahl = input("Wieviel möchten Sie beheben?\n 1)50€ \t \t \t \t 2)100€ \n 3)200€ \t \t \t \t 4)500€ \n 5)800€ \t \t \t \t 6)1000€ \n") auslesen_kontostand = open("kontostand.txt", "r") zwischenschritt = str(auslesen_kontostand) auslesen_kontostand.close() rechnung_kontostand = int(zwischenschritt) if auslesen_kontostand == "": print("Sie haben kein Konto!") behebung = 0 main = 1 if auslesen_kontostand != "": if behebung_auswahl == "1" and rechnung_kontostand >= -2250: ergebniss_kontostand = rechnung_kontostand - 50 ergebniss_kontostand2 = str(ergebniss_kontostand) print("Entnehmen Sie Ihre 50€") auslesen_kontostand = open("kontostand.txt", "w") auslesen_kontostand.write(ergebniss_kontostand2) auslesen_kontostand.close() auswahl = "" main = 1 if auswahl == "5": main = 0 print("Bis zum nächsten mal!") if auswahl != "1" and auswahl != "2" and auswahl != "3" and auswahl != "4" and auswahl != "5": print("Bitte geben Sie eine gültige Operation ein!") main = 1