#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    100
    Rep Power
    2

    What's wrong with this code?


    I was browsing the forums and came across this thread:
    http://forums.devshed.com/python-programming-11/help-to-finish-my-code-945856.html

    And then, for the first problem, I wrote this code but it's not working. What am I doing wrong?

    Code:
    tobi1 = 4
    tobi2 = 4
    appa = 'Anything you want.'
    appb = 'Anything you like.'
    
    if tobi1 == tobi2:
        fileName = 'app1.py'
        fileName2 = 'app2.py'
        count = 0
        fileCount = 3
        fileCount2 = 4
        while count <= 29:
            file = open(fileName, 'w')
            file2 = open(fileName2, 'w')
            file.write(appa)
            file.close()
            file2.write(appb)
            file2.close()
            fileName = list(fileName)
            fileName[3] = str(fileCount)
            fileName = ''.join(fileName)
            fileName2 = list(fileName2)
            fileName2[3] = str(fileCount2)
            fileName2 = ''.join(fileName2)
            fileCount += 2
            fileCount2 += 2
            count += 1
        print('Stop!')
    Last edited by Akshat1; May 27th, 2013 at 01:34 PM.
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,709
    Rep Power
    480
    Your program wrote a whole lot of files. Not millions, but 30 or 60 of them.

    I didn't comprehend the question in help-to-finish-my-code-945856.html , therefore I don't understand what problems you've think your program has.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    100
    Rep Power
    2
    Originally Posted by b49P23TIvg
    Your program wrote a whole lot of files. Not millions, but 30 or 60 of them.

    I didn't comprehend the question in help-to-finish-my-code-945856.html , therefore I don't understand what problems you've think your program has.
    This was the problem:

    tobi1 and tobi2 are calculations and the values of them are changing everytime.
    In this example they have the same values.
    Only if they have the same values it must print appa to file app1.py and appb to file app2.py
    If they don't have the same value nothing must be done.
    I want to do this 30 times.
    The second time it must print appa to file app3.py and appb to file app4.py
    The third time it must print appa to file app5.py and appb to file app6.py etc....
    After 30 times I must have 60 files and the code must print stop.
    The only problem is that I am not getting the correct file name for all. :/
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    451
    Rep Power
    32
    tobi1 and tobi2 are calculations and the values of them are changing everytime.
    The first problem is that they are not changing every time. How do they change and how can we simulate it? This program asks for the numbers and responds accordingly if they are equal or not.
    Code:
    ## Python 2.X
    
    name_counter=1
    for ctr in range(5):     ## 5 times is enough for a test
        print "-"*50
        print "Enter two numbers"
        tobi1 = int(raw_input("First Number "))
        tobi2 = int(raw_input("Second Number "))
        print("     Filenames = app%d.py,  app%d.py" %
              (name_counter, name_counter+1))
        if tobi1 == tobi2:
            print "Numbers are equal"
        else:
            print "Not equal"
        name_counter += 2
    Last edited by dwblas; May 28th, 2013 at 01:28 PM.
  8. #5
  9. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,709
    Rep Power
    480
    I didn't think this thread was worth more time. Akshat1 didn't even ask the original question.


    I completely agree with dwblas that the values of tobi 1 and 2 are constant---because they are.


    Reposting the problem doesn't help me understand it. I'm lost on the first sentence.

    "tobi1 and tobi2 are calculations..." No, they're not. They're variables, storing the result of calculations. It's as if Akshat1 and Filip.V communicate in a private language known only to themselves.

    Comments on this post

    • dwblas agrees : +1 Because of the effort of converting to a list etc. to get the filename, I thought I would help out there a little.
    [code]Code tags[/code] are essential for python code and Makefiles!
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    100
    Rep Power
    2
    Originally Posted by b49P23TIvg
    I didn't think this thread was worth more time. Akshat1 didn't even ask the original question.
    "The only problem is that I am not getting the correct file name for all. :/"

    Reposting the problem doesn't help me understand it. I'm lost on the first sentence.
    That was actually my fault, when you said 'comprehend,' I took that meaning that you didn't read it carefully enough (stupid, I know; I was doing some other stuff).

    "tobi1 and tobi2 are calculations..." No, they're not. They're variables, storing the result of calculations.
    It's as if Akshat1 and Filip.V communicate in a private language known only to themselves.
    I didn't read the problem that critically to even bother about an error like that, I was just concentrated in solving the problem. Yes, I know that it was a mistake, but I was smart enough to figure out what that meant (just like you), but I never bothered to criticize it; I was too busy working on the original problem asked.

IMN logo majestic logo threadwatch logo seochat tools logo