π’π’π’π£π£π£
π»π»π» Hello, everyone. My name is Dream. I'm an interesting Python blogger. I have a small white one. Please take care of it πππ
π
π
π
CSDN is a new star creator in Python field and is a sophomore. Welcome to find me for cooperative learning (VX wants to enter the learning exchange group or learning materials at the end of the article. Welcome + + +)
π Introduction note: this paradise is never short of genius, and hard work is your final admission ticket! πππ
π Finally, may we all shine where we can't see and make progress together πΊπΊπΊ
πππ "Ten thousand times sad, there will still be Dream, I have been waiting for you in the warmest place", singing is me! Ha ha ha~ πππ
πππβ¨β¨β¨
Here is a record of my mental process of brushing 100 questions. I send an article every 10 questions. I hope you can learn from it and stick to it! Welcome to supervise and study together!
Question 41
1. Title
41. Imitate the usage of static variables.
2. Code
# -*-coding:utf-8 -*- # @Author: it's time. I love brother Xu # Ollie, do it!!! # 41. Imitate the usage of static variables. def varfunc(): var = 0 print ('var = %d' % var) var += 1 if __name__ == '__main__': for i in range(3): varfunc() # Properties of class # As an attribute of the class class Static: StaticVar = 5 def varfunc(self): self.StaticVar += 1 print (self.StaticVar) print(Static.StaticVar) a = Static() for i in range(3): a.varfunc()
3. Ideas
Static method call and implementation!
Question 42
1. Title
42. Learn how to use auto to define variables.
2. Code
# 42. Learn how to use auto to define variables. num = 2 def autofunc(): num = 1 print ('internal block num = %d' % num) num += 1 for i in range(3): print ('The num = %d' % num) num += 1 autofunc()
3. Ideas
Question 43
1. Title
43. Imitate another case of static.
2. Code
# -*-coding:utf-8 -*- # @Author: it's time. I love brother Xu # Ollie, do it!!! class NUM: num=1 def inc(self): self.num+=1 print('num=%d'%self.num) if __name__ =='__main__': num = 2 inst = NUM() for i in range(3): num += 1 print('The num = %d'%num) inst.inc()
3. Ideas
Question 44
1. Title
43. Two matrices with three rows and three columns, add the data at their corresponding positions, and return a new matrix:
2. Code
X = [[12, 7, 3], [4, 5, 6], [7, 8, 9]] Y = [[5, 8, 1], [6, 7, 3], [4, 5,9]] R = [[0,0,0], [0,0,0], [0,0,0]] for i in range(len(X)): for j in range(len(Y)): R[i][j] = X[i][j]+Y[i][j] print(R)
3. Ideas
Give two known matrices and add the elements in turn according to the position! πππ
Question 45
1. Title
45. Statistics are the sum of 1 to 100.
2. Code
# -*-coding:utf-8 -*- # @Author: it's time. I love brother Xu # Ollie, do it!!! a=0 for i in range(101): a+=i print('The sum is %d'%a)
3. Ideas
That's it πππ
Question 46
1. Title
46. Find the square of the input number. If the square is less than 50, exit.
2. Code
# -*-coding:utf-8 -*- # @Author: it's time. I love brother Xu # Ollie, do it!!! a = int(input('Please enter an integer:')) aa = a**2 if aa >= 50: print('{}The square of is{}'.format(a,aa)) else: pass
3. Ideas
βοΈβοΈβοΈ if determines the structure. if it is greater than, it will be output. if it is less than, it will end the process! βοΈβοΈβοΈ
Question 47
1. Title
47. The two variable values are interchanged.
2. Code
# -*-coding:utf-8 -*- # @Author: it's time. I love brother Xu # Ollie, do it!!! a = int(input("Please enter a Value of variable: ")) b = int(input("Please enter b Value of variable: ")) print ('x = %d,y = %d' % (a,b)) print ('x = %d,y = %d' % (b,a))
3. Ideas
Exchange is ok!
Question 48
1. Title
48. Comparison
2. Code
if __name__ == '__main__': i = 10 j = 20 if i > j: print ('%d greater than %d' % (i,j)) elif i == j: print ('%d be equal to %d' % (i,j)) elif i < j: print ('%d less than %d' % (i,j)) else: print ('unknown')
3. Ideas
The comparison is over
Question 49
1. Title
48. Use lambda to create anonymous functions.
2. Code
S = lambda x,y:x+y print(S(2,8))
3. Ideas
lambda means anonymous function! lambda x, Y: a basic form of X + y
Question 50
1. Title
50. Output a random number.
2. Code
# -*-coding:utf-8 -*- # @Author: it's time. I love brother Xu # Ollie, do it!!! import random # Generate a random number between 10 and 20 print(random.uniform(10, 20))
3. Ideas
Random takes a random number.
print random.random() #Enter a random number between 0 and 1 print random.uniform(10,20) #Output random numbers between 10-20 print random.randint(10,20) #Output random integers between 10-20
[wonderful article] π [recommended in previous periods]
Python 100 questions from "None" to "yes", daily supervision and clock in learning phase I: 1-10 questions, idea sharing + mental journey
Python 100 questions from "None" to "yes", daily supervision and clock in learning phase II: 11-20 questions, idea sharing + mental journey
Python 100 questions from "None" to "yes", daily supervision and clock in learning phase III: 21-30 questions, thinking sharing + mental journey
Python 100 questions from "None" to "yes", daily supervision and clock in learning phase IV: 31-40 questions, thinking sharing + mental journey
Conclusion: the fifth issue is completed successfully. See you in the sixth issue!!! Come on, stick to it!!!
π²π²π² Well, that's all I want to share with you today
β€οΈβ€οΈβ€οΈ If you like, don't save your one button three connections~