phython දන්න අය කවුද?

broker

Member
Jul 29, 2011
68
4
0
Write a phython Programme which prints the odd numbers between 1 and 1000 in tha following order..

1. 999,997,995,993................5,3,1
2. 1,999,3,997,5,995,7,993,.........

වැඩකාරයෝ ඉන්නවනම් මේක කියල දීල මගේ assignment එක කරගන්න උදවුකරන්න..ගොඩක් පිං
 

nlasasatha

Well-known member
  • Sep 2, 2009
    3,799
    1,581
    113
    Tsukuba
    Code:
    def main():
        program()
        
        
    def program():
        a=999
        b=1
        while (a>0 and a>b):
            print(b)
            print(a)
            b=b+2
            a=a-2
           
    
    if __name__ == "__main__": main()
     

    119©

    Well-known member
  • Sep 29, 2012
    2,413
    2,163
    113
    ~ගෙදර~
    Code:
    def main():
        program()
        
        
    def program():
        a=999
        while (a>0):
            print(a)
            a=a-2
           
    
    if __name__ == "__main__": main()

    phython mara wenas ne ban a kiyana ekata type ekakuth naha..ela ela...phython walata integer strings okkotama ekama data type ekada ban pawichchi karanne.
     

    broker

    Member
    Jul 29, 2011
    68
    4
    0
    python 3 use karanna, ekai errors enne

    eath hari giye nehe ban meka tama ena error eka

    http://imageshack.us/f/90/koka.png/
    koka.png

    koka.png
     
    Last edited:

    KeBa

    Well-known member
  • Mar 8, 2008
    3,313
    73
    48
    1234
    Write a phython Programme which prints the odd numbers between 1 and 1000 in tha following order..

    1. 999,997,995,993................5,3,1
    2. 1,999,3,997,5,995,7,993,.........

    වැඩකාරයෝ ඉන්නවනම් මේක කියල දීල මගේ assignment එක කරගන්න උදවුකරන්න..ගොඩක් පිං


    ok

    1. do not copy and past this code into python interpreter instead of that open a new python file ****.py and open it with python idle and press F5 (or Run)

    2. I'm using python 2.7 so this code may or may not work with the latest python 3 coz they are not backward compatible.


    Code:
    [COLOR="Red"]def odder1():
        for value in range(1000,0,-1):
            if value%2:
                print str(value)+",",
    
    def odder2():
        count = 0
        for value in range(1000,0,-1):
            if value%2:
                print str(value)+",",
            if count%2:
                print str(count)+",",
            count +=1
    [/COLOR]


    for python 3 you should use parentheses for print function


    adoo machan uba monawa karana kenekda ??
    python karanne mokatada ??


    Code:
    http://www.mediafire.com/?d0lgkswlycy9f0n

    download and run work only in python 2.7
     
    Last edited:
    Feb 3, 2009
    2
    0
    0
    Write a phython Programme which prints the odd numbers between 1 and 1000 in tha following order..

    1. 999,997,995,993................5,3,1
    2. 1,999,3,997,5,995,7,993,.........

    වැඩකාරයෝ ඉන්නවනම් මේක කියල දීල මගේ assignment එක කරගන්න උදවුකරන්න..ගොඩක් පිං
    1)a=999
    >>> while(a>0):
    print a
    a=a-2

    2)a=1
    >>> b=999
    >>> while(a<1000 and b>0):
    print a
    print b
    a=a+2
    b=b-2