当前位置:网站首页>Work of the first week
Work of the first week
2022-06-25 15:08:00 【Mrho9527】
First week homework
One 、 choice question
In the following variable names illegal Yes. ?(C)
A. abc
B. Npc
C. 1name
D ab_cd
In the following options Do not belong to The key word is ?(B)
A. and
B. print
C. True
D. in
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 ')The following options can print 50 Yes. ?(B)
A.
print('100 - 50')B.
print(100 - 50)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
Write code and print on the console
good good study, day day up!print('good good study, day day up!')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!')Write code, print numbers 11、12、13、… 21
for x in range(11,22): print(x,end=' ')Write code, print numbers 11,13,15,17,…99
for x in range(11,100,2): print(x,end=' ')Write code, print numbers :10、9、8、7、6、5
for x in range(10,4,-1): print(x,end=' ')Write code calculation :1+2+3+4+…+20 And
n=0 for x in range(1,21): n+=x print(n)Write code calculation 100 The sum of all even numbers within
num=0 for x in range(2,102,2): num+=x print(num)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)Write code calculation
2*3*4*5*...*9Resultnum=1 for x in range(2,10): num*=x print(num)Enter a number , If the number entered is even, print
even numbersOtherwise printOdd numbernum=abs(int(input(' please enter an integer '))) if num%2: print(' Odd number ') else: print(' even numbers ')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
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)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)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)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)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)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)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('')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 ')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)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)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)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)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))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)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)
边栏推荐
猜你喜欢

有哪个瞬间让你觉得这个世界出bug了?

Learning notes on February 18, 2022 (C language)

Using Sphinx to automatically generate API documents from py source files

Sequential programming 1

定位position(5种方式)

Judging the number of leap years from 1 to N years

Position (5 ways)
![[Ocean University of China] Data Sharing for retest of initial Examination](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[Ocean University of China] Data Sharing for retest of initial Examination

Stack and queue

How to combine multiple motion graphs into a GIF? Generate GIF animation pictures in three steps
随机推荐
About?: Notes for
One question per day, punch in
Review of arrays and pointers triggered by a topic
semget No space left on device
C language escape character and its meaning
A deformation problem of Hanoi Tower
Clipboard tutorial
Ubuntu 20.04 installing mysql8.0 and modifying the MySQL password
Study notes of cmake
Remove interval (greedy)
QT set process startup and self startup
Function of getinstance() method
If multiple signals point to the same slot function, you want to know which signal is triggered.
In 2022, the score line of Guangdong college entrance examination was released, and several families were happy and several worried
Common operations in VIM
Bessie's weight problem [01 backpack]
dmsetup命令
2. operator and expression multiple choice questions
Biscuit distribution
电源自动测试系统NSAT-8000,精准高速可靠的电源测试设备