Huitong Education-python advanced exercises second level (2)

(View description: Think carefully about its simple algorithm, and then try multiple times by yourself to master its programming principles. Copying and pasting the code forever does not make much progress for itself.)

900. Front number (course 7)

Title description

What if you know an integer a and want to output the N numbers before a?

Input format

 Two positive integers in a row: a and N, in the range [1,10000].

Output format

N integers in a row:……a-2 a-1

Input/output example 1

enter:

 10  5

Output:

 5 6 7 8 9

st = input()
a = st.split()[0]
N = st.split()[1]
a = int(a)
N = int(N)
list = []
for i in range(a-N,a):
    print(i,end=' ')

901. Odd Number (Lesson 7)

Title description

Given N, output an odd number between 1 and N.

Input format

 One positive integer per line: N, the range is [1,10000].

Output format

 Positive odd numbers within [1...N].

Input/output example 1

enter:

10

Output:

 1 3 5 7 9

N = input()
N = int(N)
for i in range(0,N+1):
    if(i%2==1):
        print(i, end=' ')

902.7 Multiples of 7 (Lesson 7)

Title description

Output the multiples of 7 among all 3 digits from small to large.

Output format

 A line of integers, separated by spaces.

Input/output example 1

enter:

Output:

 105  112……

for i in range(100, 1000):
    if i % 7 == 0:
        print(i, end=' ')

903. The Power of k (Lesson 7)

Title description

Input a positive integer k, output: k k*k k*k*k……, stop when it exceeds 8 digits.

Input format

 In the first line, an integer k is in the range [2,15].

Output format

 One line, multiple powers of k.

Input/output example 1

enter:

15

Output:

 15  225  3375  50625  759375  11390625

st = input()
k = st.split()[0]
k = int(k)
k in range(2, 15)
result = k
while result < 100000000:
    print(result, end=' ')
    result *= k

904. Arithmetic sequence (course 7)

Title description

A sequence of numbers, if the differences of two adjacent ones are equal, it is called an arithmetic sequence. For example: 2,5,8,11,14....
Now given the starting number a and the difference d, output the nth term.

Input format

 Three positive integers in a row: a, d, and n, in the range [-100,100].

Output format

 There are n integers in a row.

Input/output example 1

enter:

4 5 6

Output:

29

st = input()
a = st.split()[0]
d = st.split()[1]
n = st.split()[2]
a = int(a)
d = int(d)
n = int(n)
g = a + (n-1)*d
print(g)

905. Double arithmetic sequence (course 7)

Title description

Find the Nth term of the following double arithmetic sequence.
1 2 4 7 11 16 22...

Input format

 One positive integer per line: N, the range is [1,100].

Output format

 1 integer.

Input/output example 1

enter:

4

Output:

7

st = input()
N = st.split()[0]
N = int(N)
N in range(1, 100)
a = 1
d = 0
i = 0
for i in range(N):
    if i < N:
        i = i+1
        a += d
        d += 1
print(a, end=" ")

 

 

 

 

Guess you like

Origin blog.csdn.net/weixin_44940488/article/details/106678498