Python learning examples
This article includes the Fibonacci series written in Python, the three-digit daffodils, and the basic code for buying hundreds of chickens for hundreds of dollars.
Fibonacci series:
'''
Def hanshu (n ):
N_1 = 1
N_2 = 1
M = n
Sumn = 0
For a in range (1, m + 1 ):
If m = 1:
Return n_1
If m = 2:
Return n_2
Sumn = n_1 + n_2
N_2 = n_1
N_1 = sumn
Print (sumn, end = "")
Hanshu (20)
'''
For the above Code running result:
Find out the daffodils within 1:
Def hanshu (n ):
Sumn = 0
M = n
For dix in range (1, 4 ):
M = m % 10
Sumn = sumn + m ** 3
M = n // 10
If sumn = n:
Print (n, end = "")
Def hanshu1 ():
For B in range (1,1000 ):
Hanshu (B)
Hanshu1 ()
For the above Code running result:
Buy a chicken for 0.5 RMB: a rooster is 5 yuan, a hen is 3 yuan, a chicken is 100 yuan, and a chicken is 100 yuan.
Q: How many rooster hens and chicks should I buy?
Set rooster to x, hen to y, and chicken to z
X = 0
While x <= 100:
Y = 0
While y <= 100:
Z = 0
While z <= 100:
If x + y + z = 100 and 5 * x + 3 x + 0.5 * z = 100:
Print (x, y, z)
Z + = 1
Y + = 1
X + = 1
For the above Code running result: