Hello, everyone. =2001 using Python to calculate

Source: Internet
Author: User

There's a third grade question:
Big
Everyone
Hello everyone
Hello, everyone.
2 0 0 1

Everybody good + everybody good + everybody + big =2001 beg big =? Home =? Good =? Ah =?

Here's the code:

#!/usr/bin/env python

#coding: Utf-8

Import Os,sys

"""

Big

Everyone

Hello everyone

Hello, everyone.

2 0 0 1

"""

def sum (num):

#with Open Num.txt as F:

If Os.path.exists (' Num.txt '): # To determine if a file exists

If Os.path.getsize (' Num.txt '): # Determines if the file is empty

F=open (' Num.txt ', ' A + ') # Open file in Append mode

F.truncate () # Empty file contents

Else

Os.mknod (' Num.txt ')

F=open (' Num.txt ', ' A + ')


For d in range (10):

For j in Range (10):

For h in range (10):

For a in range (10):

Sum=d*1000+d*100+d*10+d+j*100+j*10+j+h*10+h+a

F.write ('%s,%s,%s,%s =%s \ n '% (d,j,h,a,sum))

if sum = = Int (num):

Print D,j,h,a

if d==j==h==a = = 9:

Print "%s is a last num"% sum

Print "Please input the num must less than%s"% sum

F.close ()


If __name__== ' __main__ ':

If Len (sys.argv) = = 1:

SUM (2001)

Elif len (sys.argv) = = 2:

Sum ("%s"% sys.argv[1])

Else

Print "Use:python%s%s"% (sys.argv[0], ' num ')


Hello, everyone. =2001 using Python to calculate

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.