Python rewrite C language program 100 example -- Part10

Source: Internet
Author: User

''' [Program 81] Question: 809 *?? = 800 *?? + 9 *?? + 1 where ?? Two digits, 8 *?? The result is two digits, 9 *?? The result is 3 digits. Please ?? Represents two digits, and 809 *?? . 1. program Analysis: 2. program source code this program is really strange 0 = 1 :( just write a program, do not pursue the '''a = 809for I in range (10,100 ): B = I * a + 1 if B> = 1000 and B <= 10000 and 8 * I <100 and 9 * I> = 100: print B, '/', I, '= 809 *', I, '+', B % I

''' [Program 82] Question: octal conversion to decimal 1. program Analysis: 2. program source code: ''' if _ name _ = '_ main _': n = 0 p = raw_input ('input a octal number: \ n ') for I in range (len (p): n = n * 8 + ord (p [I])-ord ('0') print n

''' [Program 83] Question: calculate the number of odd numbers that can be composed of 0 to 7. 1. program Analysis: 2. program source code: ''' if _ name _ = '_ main _': sum = 4 s = 4 for j in range ): print sum if j <= 2: s * = 7 else: s * = 8 sum + = s print 'sum = % d' % sum


''' [Program 84] Question: an even number can always represent the sum of two prime numbers. 1. program Analysis: 2. program source code: This code is faulty. You need to modify '''import matconditioned _ name _ = '_ main __': a = int (raw_input ('input an odd number: \ n') d = 0 c = 2 for B in range (3, a/2 + 1, 2 ): m = 0 for c in range (2, int (math. sqrt (B) + 1): if B % c = 0: m = c break if m> math. sqrt (B): d = a-B else: break for c in range (2, int (math. sqrt (d) + 1): if d % c = 0: m = c break if m> math. sqrt (d): print '% d = % d + % d' % (a, B, d)


''' [Program 85] Question: judge whether a prime number can be divided by 9. program Analysis: 2. program source code: ''' if _ name _ = '_ main _': zi = int (raw_input ('input a number: \ n ')) n1 = 1 c9 = 1 m9 = 9 sum = 9 while n1! = 0: if sum % zi = 0: n1 = 0 else: m9 * = 10 sum + = m9 c9 + = 1 print '% d can be divided by % d 9' % (sum, c9)


''' [Program 86] Question: Two string connection programs 1. program Analysis: 2. program source code: ''' if _ name _ = '_ main __': a = "acegikm" B = "bdfhjlnpq" # connection string c = a + B print c


''' [Program 87] Question: Answer result (transmitted by struct variables) 1. program Analysis: 2. program source code: '''if _ name _ = '_ main _': class student: x = 0 c = 0 def f (stu): stu. x = 20 stu. c = 'C' a = student (). x = 3. c = 'A' f (a) print. x,. c


''' [Program 88] Question: Read the integer of 7 Numbers (1-50). Each time a value is read, the program prints * of the number of values *. 1. program Analysis: 2. program source code: ''' if _ name _ = '_ main _': n = 1 while n <= 7: a = int (raw_input ('input a number: \ n') while a <1 or a> 50: a = int (raw_input ('input a number: \ n') print a * 'n + = 1


''' [Program 89] Subject: A company uses a public phone to transmit data. The data is a four-digit integer and encrypted during the transmission process. The encryption rules are as follows: add 5 to each number, and use the remainder of 10 to replace the number. Then, the first and fourth digits are exchanged, and the second and third digits are exchanged. 1. program Analysis: 2. program source code: ''' from sys import stdoutif _ name _ = '_ main _': a = int (raw_input ('input a number: \ n') aa = [] aa. append (a % 10) aa. append (a % 100/10) aa. append (a % 1000/100) aa. append (a/1000) for I in range (4): aa [I] + = 5 aa [I] % = 10 for I in range (2 ): aa [I], aa [3-I] = aa [3-I], aa [I] for I in range (3,-1,-1): stdout. write (aa [I])


''' [Program 90] Question: this is a professional promotion. Read the result. 1. program Analysis: 2. program source code: ''' if _ name _ = '_ main _': M = 5 a = [1, 2, 3, 4, 5] I = 0 j = M-1 while I <M: a [I], a [j] = a [j], a [I] print a I + = 1 j-= 1 for I in range (5): print a [I]



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.