当前位置:网站首页>Work of the first week

Work of the first week

2022-06-25 15:08:00 Mrho9527

First week homework

One 、 choice question

  1. In the following variable names illegal Yes. ?(C)

    A. abc

    B. Npc

    C. 1name

    D ab_cd

  2. In the following options Do not belong to The key word is ?(B)

    A. and

    B. print

    C. True

    D. in

  3. Which of the following options corresponds to the correct code writing ?(C)

    A.

    print('Python')
      print(' Novice Village ')
    

    B.

    print('Python') print(' Novice Village ')
    

    C.

    print('Python')
    print(' Novice Village ')
    

    D.

    print('Python'' Novice Village ')
    
  4. The following options can print 50 Yes. ?(B)

    A.

    print('100 - 50')
    

    B.

    print(100 - 50)
    
  5. About Quotes , The correct choice used in the following options is ?(D)

    A.

    print('hello)
    

    B.

    print("hello')
    

    C.

    print(“hello”)
    

    D.

    print("hello")
    

Two 、 Programming questions

  1. Write code and print on the console good good study, day day up!

    print('good good study, day day up!')
    
    
  2. Write code and print on the console 5 Time you see see, one day day!

    for x in range(5):
        print('you see see, one day day!')
    
  3. Write code, print numbers 11、12、13、… 21

    for x in range(11,22):
        print(x,end=' ')
    
  4. Write code, print numbers 11,13,15,17,…99

    for x in range(11,100,2):
        print(x,end=' ')
    
  5. Write code, print numbers :10、9、8、7、6、5

    for x in range(10,4,-1):
        print(x,end=' ')
    
  6. Write code calculation :1+2+3+4+…+20 And

    n=0
    for x in range(1,21):
        n+=x
    print(n)
    
  7. Write code calculation 100 The sum of all even numbers within

    num=0
    for x in range(2,102,2):
        num+=x
    print(num)
    
  8. Write code statistics 100~200 The median is 3 The number of

    num=0
    for x in range(103,194,10):
        num+=1
    print(num)
    
  9. Write code calculation 2*3*4*5*...*9 Result

    num=1
    for x in range(2,10):
        num*=x
    print(num)
    
  10. Enter a number , If the number entered is even, print even numbers Otherwise print Odd number

    num=abs(int(input(' please enter an integer ')))
    if num%2:
        print(' Odd number ')
    else:
        print(' even numbers ')
    
  11. Statistics 1000 Endogenic quilt 3 Divisible but not by 5 The number of integers .

    n=0
    for x in range(3,1000,3):
        if x%5!=0:
            n+=1
    print(n)
    

3、 ... and 、 Advanced work

  1. Judge 101-200 How many primes are there between , And output all prime numbers .

    n=0
    for x in range(101,201):
        for y in range(2,x):
            if x % y == 0:
                break
        else:
            print(x)
            n+=1
    print(' common %d Prime number '%n)
    
  2. For integer 1~100 The cumulative value of , But it is required to skip all bits 3 Number of numbers .

    # Method 1 
    acount=0
    for num in range(1,101):
        acount+=num if num%10!=3 else 0
    print(acount)
    
    # Method 2 
    acount1=0
    acount2=0
    for num1 in range(1,101):
        acount1+=num1
    for num2 in range(3,94,10):
        acount2+=num2
    print(acount1-acount2)
    
  3. Yes ⼀ The fractional sequence :2/1,3/2,5/3,8/5,13/8,21/13… Find the... Of this sequence 20 A score

    x=y=1
    num=int(input(' Please enter the number of items :'))
    for p in range(num):
        x,y=x+y,x
    print(x,'/',y)
    
  4. Write a program to calculate n The factorial n! Result

    num=1
    n=int(input(" Please enter a positive integer "))
    for x in range(1,n+1):
        num*=x
    print(num)
    
  5. seek 1+2!+3!+…+20! And

    num2=1
    for n in range(1,21):
        num = 1
        for x in range(1,n+1):
            num*=x
        num2+=num
    print(num2)
    
  6. Write a program to find an expression a + aa + aaa + aaaa+ … Result , among a yes 1~9 The number of , The number of items to be summed is in n To control .(a and n You can use variables to represent )

    for example :a by 3, n by 5 When : 3 + 33 + 333 + 3333 + 33333

    # Method 1 : General formula 
    a=int(input(" Please enter a number (1-9):"))
    n=int(input(" Please enter the number of items ( Positive integer ):"))
    acount=0
    for x in range(1,n+1):
        num=a*(10**(n-x))*(x)
        acount+=num
    print(acount)
    
    # Method 2 : Character conversion 
    a=(input(" Please enter a positive integer "))
    n=int(input(" Please enter a positive integer "))
    acount=0
    for x in range(1,n+1):
        num=a*x
        num2=int(num)
        acount+=num2
    print(acount)
    
  7. Console output triangle

    a. according to n Different values of , Output the corresponding shape 
    n = 5 when              n = 4
    *****               ****
    ****                ***
    ***                 **
    **                  *
    *
    
    #a
    n=5
    for x in range(1,n+1):
        b=str('*') * (n - x+1)
        print(b)
        
        
    b. according to n Different values of , Output the corresponding shape (n It's odd )
    n = 5               n = 7
      *                    *
     ***                  ***
    *****                *****
                        *******
    
    #b
    n=int(input(' Please enter an odd number '))
    x=int((n+1)/2)
    for y in range(x):
        print(' '*(x-y-1)+'*'*(2*y+1))
        
        
    c.  according to n Different values of , Output the corresponding shape 
    n = 4
       1
      121
     12321
    1234321
    
    n = 5
        1
       121
      12321
     1234321
    123454321
    
    #c
    n=int(input(' Please enter :'))
    for y in range(n+1):
        for x in range(n-y):
            print(' ',end='')
        for z in range(1,y+1):
            print(z,end='')
        for t in range(y-1,0,-1):
            print(t,end='')
        print('')
    
  8. Xiaoming unit sent 100 Yuan shopping card , Xiao Ming goes to the supermarket to buy three kinds of washing and chemical products , The shampoo (15 element ), Soap (2 element ), toothbrush (5 element ). To put 100 Yuan is just spent , What can be purchased in combination with ?

    for a in range(1,51):
        for b in range(1,21):
            for c in range(1,7):
                if c*15==100-2*a-5*b:
                    print(f' Soap {
            a} block   toothbrush {
            b} root   The shampoo {
            c} bottle ')
    
  9. The thickness of a piece of paper is about 0.08mm, How many times can you reach the height of Mount Everest (8848.13 rice )?

    n=0.08
    x=1
    while True:
        if n*2**(x)>=8848130:
            break
        x += 1
    print(x)
    
  10. Classical questions : There is a pair of rabbits , From the day after birth 3 A couple of rabbits are born every month from , Every month after the third month, a couple of rabbits will be born , If the rabbits don't die , Ask the total number of rabbits per month ?

    month=int(input(' Please enter the month :'))
    var=a=0
    b=0
    c=1
    amount=0
    
    if month<3:
        print(' Rabbits are 1 Yes ')
    else:
        for x in range(3,month+1):
            c += b
            a = c
            b=var
            var=a
        amount=(a+b+c)
        print(' Rabbits are %d Yes ' % amount)
    
  11. Divide a positive integer into prime factors . for example : Input 90, Print out 90=2x3x3x5.

    num1=num = int(input(' Please enter a positive integer '))
    print('%d='%num,end='')
    while num>1:
        for x in range(2, num1+1):
            if num % x == 0:
                num/=x
                num=int(num)
                if num>1:
                    print('%d*'%x,end='')
                    break
                else:
                    print(x)
    
  12. A company uses a public telephone to transmit data , The data is a four digit integer , It's encrypted during delivery , The encryption rules are as follows : Add... To every number 5, Then divide the sum by 10 The remainder of replace the number , Then exchange the first and the fourth , The second and the third exchange . Find the encrypted value of the input four bit integer

    x=int(input(' Please enter a number :'))
    result=0
    n=1
    while n<=4:
        num=x%(10**n)//10**(n-1)
        num+=5
        var=num%10
        a=var*10**(4-n)
        result+=a
        n+=1
    print(result)
    
  13. The principal 10000 Yuan is deposited in the bank , The annual interest rate is three thousandths . every 1 year , Add up the principal and interest as the new principal . Calculation 5 After year , What is the principal amount obtained .

    money1=money2=float(input(' Please enter the principal ( element ):'))
    years=int(input(' Please enter the period ( year ):'))
    rate1=float(input(' Please enter interest rate (‰):'))
    rate=1+rate1*0.001
    for x in range(1,years+1):
        money2*=rate
    print(' The account balance is :%.2f'%money2)
    print(' The interest earned is :%.2f'%(money2-money1))
    
  14. Enter an integer , Calculate the sum of the numbers on it .( Be careful : The input integer can be any bit )

    x=abs(int(input(' please enter an integer :')))
    sum=0
    num=0
    n=1
    while True:
        num=x%(10**n)//10**(n-1)
        sum += num
        if x//10**n==0:
            break
        n+=1
    print(sum)
    
  15. Find the greatest common divisor and the least common multiple of two numbers .( Tips : The common divisor must be less than or equal to the smaller of the two numbers , And can be divided by two numbers at the same time ; The common multiple must be greater than or equal to the greater of the two numbers , It is a multiple of a large number and can be divided by decimals in the two numbers )

    x=abs(int(input(' please enter an integer 1:')))
    y=abs(int(input(' please enter an integer 2:')))
    num1=min(x,y)
    num2=max(x,y)
    n1=cd=cm=0
    n2=num2-1
    # greatest common divisor 
    while True:
        if n1<=num1:
            n1+= 1
            if num1 % n1 == 0:
                if num2 % n1 == 0:
                    cd = n1
        else:
            break
    print(' The greatest common divisor is ',cd)
    # Minimum common multiple 
    while True:
        n2+=1
        if n2%num1 == 0:
            if n2%num2== 0:
                cm = n2
                break
    print(' The least common multiple is ',cm)
    
原网站

版权声明
本文为[Mrho9527]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202200511059308.html