# 14-2.18 circular lifting questions

Posted by flashicon on Sat, 19 Feb 2022 12:40:31 +0100

1. Judge how many primes there are between 101-200 and output all primes.

```x = 0
for m in range(101, 201):
for n in range(2, int(m ** 0.5) + 1):
if m % n == 0:
break
elif n == int(m ** 0.5):
print('Prime number:',m)
x+=1
print(x)
```
2. Find the cumulative value of integers 1 ~ 100, but it is required to skip all numbers with 3 bits.

```sum=0
for i in range(101):
if i%10==3:
i=0
sum+=i
print(sum)
```
3. There is a sequence of fractions: 2 / 1, 3 / 2, 5 / 3, 8 / 5, 13 / 8, 21 / 13... Find the 20th fraction of this sequence

```a=2
b=1
# x=int(input('Fraction: ')
x=20
for i in range(x-1):
a+=b
b=a-b
print(a,'/',b)
```
4. Write a program to calculate the factorial n of n! Results

```sum=1
n=int(input('positive integer n For:'))
for i in range(1,n+1):
sum*=i
print(sum)
```
5. Ask for 1 + 2+ 3!+…+ 20! And

```sum=0
for n in range(1,21):
sum1=1
for i in range(1,n+1):
sum1*=i
sum+=sum1
print(sum)
```
6. Write a program to find the result of the expression a + aa + aaa + aaaa +... Where a is a number from 1 to 9, and the number of summation items is controlled by n. (A and N can be expressed as variables)

For example: when a is 3 and n is 5: 3 + 33 + 333 + 3333 + 33333

```a=int(input("a For:"))
n=int(input("n For:"))
sum=sum1=0
for i in range(n):
sum1+=a*10**i
sum+=sum1
print(sum)
```
7. Console output triangle

```a.according to n The corresponding shape is output according to the different values of
n = 5 Time             n = 4
*****               ****
****                ***
***                 **
**                  *
*

b.according to n The corresponding shape is output according to the different values of(n Odd number)
n = 5               n = 7
*                    *
***                  ***
*****                *****
*******

c. according to n The corresponding shape is output according to the different values of
n = 4
1
121
12321
1234321

n = 5
1
121
12321
1234321
123454321
```
```a.

n=int(input("n For:"))
for a in range(n):
for b in range(n-a):
print('*',end='')
print()

b.

n=int(input("Odd number n For:"))
for a in range(int((n+1)/2)):
for b in range(n-a):
print(' ',end='')
for c in range(2*a+1):
print('*',end='')
print()

c.

n=int(input("n For:"))
for a in range(n):
for b in range(n-a-1):
print(' ',end='')
for c in range(1,a+2):
print(c,end='')
if c==a+1:
for d in range(a+1,1,-1):
print(d-1,end='')
print()

```
8. Xiaoming's unit issued a 100 yuan shopping card. Xiaoming went to the supermarket to buy three kinds of washing and chemical products, shampoo (15 yuan), soap (2 yuan) and toothbrush (5 yuan). If you want to spend 100 yuan exactly, what combination of purchase can you have?

```for a in range(1 ,7):
for b in range(1 ,51):
for c in range(1 ,21):
if 15*a+2*b+5*c == 100:
print('shampoo:',a,',','Soap:',b,',','toothbrush:',c)
```
9. The thickness of a piece of paper is about 0.08mm. How many times can it be folded in half to reach the height of Mount Everest (8848.13m)?

```x = 8e-5
times = 0
while x < 8848.13:
x *= 2
times += 1
print(times)
```
10. Classical question: a pair of rabbits give birth to a pair of rabbits every month from the third month after birth. The little rabbit grows to another pair of rabbits every month after the third month. If the rabbits don't die, what is the total number of rabbits every month?

```x = 0
a = 1
b = 1
n = int(input('Total number of months required:'))
if 0< n< 3:
print('The total for this month is:' ,2)
else:
for i in range(3, n+1):
a += b
b = a-b
x = a*2
print(x)
```
11. Decompose a positive integer into prime factors. For example: enter 90 and print out 90=2x3x3x5.

```x=int(input('Please enter a positive integer:'))
y=x
print(x,'= ',end='')
while y%2==0:
if y/2!=1:
print(2, end='x')
else:
print(2)
y=int(y/2)
for a in range(1,y+1):
if y%a==0 :
for b in range(2, a):
if a%b==0:
break
elif b==a-1:
while y%a==0:
if y/a!=1:
print(a,end='x')
else:
print(a)
y=int(y/a)
```
12. A company uses a public telephone to transmit data. The data is a four digit integer and is encrypted in the transmission process. The encryption rules are as follows: add 5 to each number, then replace the number with the remainder of sum divided by 10, and then exchange the first and fourth bits, and the second and third bits. Find the encrypted value of the input four digit integer

```x=input('Please enter a 4-digit integer:')
num=0
a=b=c=d=0
for i in x:
num+=1
m=(int(i)+5)%10
if num==1:
a=m
elif num==2:
b=m*10
elif num==3:
c=m*100
else:
d=m*1000
print(a+b+c+d)
```
13. The principal of 10000 yuan is deposited in the bank with an annual interest rate of 3%. Every one year, add the principal and interest as the new principal. Calculate the principal obtained after 5 years.

```RMB=10000
for i in range(5):
RMB*=1.003
RMB=float(int(RMB*100)/100)
print(RMB)
```
14. Enter an integer and calculate the sum of its digits. (Note: the input integer can be any bit)

```num=0
x=input('Enter an integer:')
for i in x:
num+=int(i)
print(num)
```
15. Find the maximum common divisor and minimum common multiple of two numbers. (hint: the common divisor must be less than or equal to the smaller of the two numbers, and can be divided by the two numbers at the same time; the common multiple must be greater than or equal to the larger of the two numbers, and the multiple of the larger number can be divided by the decimal of the two numbers)

```x=int(input('Please enter X:'))
m=n=0
if x>=y:
for m in range(y,0,-1):
if y%m ==0 and x%m ==0:
print('The maximum common divisor is:',m)
break
for n in range(x,x*y+1):
if n%x==0 and n%y==0:
print('The minimum common multiple is:',n)
break
else:
for m in range(x,0,-1):
if y%m ==0 and x%m ==0:
print('The maximum common divisor is:',m)
break
for n in range(y,x*y+1):
if n%x==0 and n%y==0:
print('The minimum common multiple is:',n)
break
```

Topics: Python