I can't write my data to the data file , Why?


#1

I want to write the data into the text file I want to use data for the next code, but I entered the data file does not write anything.How can I solve this problem Can you help me about that problem ? As I mentioned the title , when I entered the data , It didn’t write anything on data text

the problem started when I changed this place

def appendline(n):
n.append(line.split(","))

menu = 0
while menu != 7:
try:
    cevap = str(menu)

    menu = int(input("giris yapmak icin 1e \n toplam saati hesaplamak icin 2ye,\n butun calısanların toplam maasını hesaplamak icin 3 e,\n izin günleri için 4 e\n 45 saat cezasını hesaplamak icin 5 e tıklayınız\n bitirmek için7ya"))
except(SyntaxError,NameError):
    print "1 den 7 ye kadar giriniz"
if menu == 1:
    fin = "data.txt"
    fout = open(fin,'a')
    info = ""
    no = 0
    while info != "no":
        info = raw_input("Veri girmek istiyor musunuz? (yes/no)")
        if info != "no" and info == "yes":
            try:
                no = no + 1
                weekdays1 =int(input("09:00-17:00-pazartesi"))
                weekdays1_2=int (input("17:00-09:00-pazartesi"))
                weekdays2 = int(input("09:00-17:00-sali"))
                weekdays2_2=int (input("17:00-09:00-sali"))

                weekdays3 = int(input("09:00-17:00-carsamba"))
                weekdays3_2=int (input("17:00-09:00-carsamba"))
                weekdays4 = int(input("09:00-17:00-persembe"))
                weekdays4_2=int (input("17:00-09:00-persembe"))
                weekdays5 = int(input("09:00-17:00-cuma"))
                weekdays5_2=int (input("17:00-09:00-cuma"))
                weekend6 = int(input("09:00-17:00-cumartesi"))
                weekend6_2=int (input("17:00-09:00-cumartesi"))
                weekend7 = int(input("09:00-17:00-pazar"))
                weekend7_2=int (input("17:00-09:00-pazar"))



                totalweekdayshour = (weekdays1 + weekdays2 + weekdays3 + weekdays4 + weekdays5+ weekdays1_2+weekdays2_2+weekdays3_2+weekdays4_2+weekdays5_2)
                totalweekendhour = (weekend6 + weekend7+weekend6_2+weekend7_2)

                totalhour = totalweekdayshour + totalweekendhour
                # hafta i?i sabah normal maas, hafta i?i ak?am 1.5 kat? haftasonu 2 ,haftasonu aksam 2.5 kat? maas al?n?r.
                n = int(input("saatlik kazanc"))


                m1 = (weekdays1) * n
                m1_2 = (weekdays1_2) * n* 1.5

                m2 = (weekdays2) * n
                m2_2 = (weekdays2_2) * n* 1.5

                m3 = (weekdays3 ) * n
                m3_2 = (weekdays3_2) * n*1.5
                m4 = (weekdays4 ) * n
                m4_2 = (weekdays4_2) * n *1.5
                m5 = (weekdays5 ) * n
                m5_2 = (weekdays5_2) * n* 1.5

                m6 = (weekend6)* 2 * n
                m6_2 = (weekend6_2) *2.5*n
                m7 = (weekend7) (2 n)
                m7_2 = (weekend7_2)* 2.5*n

                totalsalary = m1+m1_2+m2+m2_2+m3+m3_2+m4+m4_2+m5+m5_2+m6+m6_2+m7+m7_2

                if weekdays1 >= 9 :
                    if weekdays1_2 >= 9 :
                       if weekdays2 >= 9 :
                          if weekdays2_2 >= 9 :
                             if weekdays3 >= 9 :
                                if weekdays3_2 >= 9 :
                                    if weekdays3 >= 9 :
                                        if weekdays3_2 >= 9 :
                                            if weekdays4 >= 9 :
                                                if weekdays4_2 >= 9 :
                                                     if weekdays5 >= 9 :
                                                        if weekdays5_2 >= 9 :


                                                             print ("Hatali calisma saati girisi degerlerınız kaydedılmedı")
            except(SyntaxError,NameError,IndexError):
                print("Oops! Enter a number.")

                break
                fout.write("%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s \n" % ( no, weekdays1,weekdays1_2,weekdays2,weekdays2_2,weekdays3,weekdays3_2,weekdays4,weekdays4_2,weekdays5,weekdays5_2,weekend6,weekend6_2,weekend7,weekend7_2,totalweekdayshour, totalweekendhour, totalhour, totalsalary))
                fout.close()

#2

Hmm, that is going to be tough to fix. So first problem is your code is not formatted right at all. Can you edit your post and fix that? Next, those if weekdays lines are a big problem. Can you explain why you’re doing that? But, don’t say:

“I’m trying to make sure every weekday is greater than 9.”

Tell me why you are trying to do that. There is probably just some simple thing you don’t know yet that does it in one line.

Now, another idea: Throw this code out. Then, start over writing it from scratch but this time try to figure out how to do it so you don’t have the big if-statement there. There’s got to be a way, so try again and see if you can do it. You probably can if you start fresh and think about it in a new way.