Generators Coding Exercise

1 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€59.54
List Price:  €85.06
You save:  €25.52
£51.54
List Price:  £73.64
You save:  £22.09
CA$96.65
List Price:  CA$138.08
You save:  CA$41.43
A$105.80
List Price:  A$151.16
You save:  A$45.35
S$89.62
List Price:  S$128.03
You save:  S$38.41
HK$544.98
List Price:  HK$778.57
You save:  HK$233.59
CHF 55.54
List Price:  CHF 79.35
You save:  CHF 23.80
NOK kr697.69
List Price:  NOK kr996.74
You save:  NOK kr299.05
DKK kr444.63
List Price:  DKK kr635.21
You save:  DKK kr190.58
NZ$117.53
List Price:  NZ$167.90
You save:  NZ$50.37
د.إ257.03
List Price:  د.إ367.21
You save:  د.إ110.17
৳8,514.86
List Price:  ৳12,164.60
You save:  ৳3,649.74
₹6,169.76
List Price:  ₹8,814.33
You save:  ₹2,644.56
RM294.37
List Price:  RM420.55
You save:  RM126.18
₦105,470.73
List Price:  ₦150,678.93
You save:  ₦45,208.20
₨19,797.45
List Price:  ₨28,283.28
You save:  ₨8,485.83
฿2,216.23
List Price:  ฿3,166.18
You save:  ฿949.95
₺2,887.85
List Price:  ₺4,125.67
You save:  ₺1,237.82
B$379.45
List Price:  B$542.09
You save:  B$162.64
R1,222.17
List Price:  R1,746.03
You save:  R523.86
Лв116.29
List Price:  Лв166.14
You save:  Лв49.84
₩96,979.27
List Price:  ₩138,547.76
You save:  ₩41,568.48
₪233.41
List Price:  ₪333.46
You save:  ₪100.04
₱3,980.99
List Price:  ₱5,687.38
You save:  ₱1,706.38
¥10,251.45
List Price:  ¥14,645.56
You save:  ¥4,394.10
MX$1,301.27
List Price:  MX$1,859.03
You save:  MX$557.76
QR254.86
List Price:  QR364.10
You save:  QR109.24
P934.22
List Price:  P1,334.66
You save:  P400.43
KSh9,042.70
List Price:  KSh12,918.70
You save:  KSh3,876
E£3,357.51
List Price:  E£4,796.65
You save:  E£1,439.13
ብር9,956.05
List Price:  ብር14,223.55
You save:  ብር4,267.49
Kz63,827.73
List Price:  Kz91,186.39
You save:  Kz27,358.65
CLP$67,824.50
List Price:  CLP$96,896.30
You save:  CLP$29,071.80
CN¥498.43
List Price:  CN¥712.07
You save:  CN¥213.64
RD$4,414.27
List Price:  RD$6,306.37
You save:  RD$1,892.10
DA9,074.62
List Price:  DA12,964.30
You save:  DA3,889.68
FJ$156.86
List Price:  FJ$224.10
You save:  FJ$67.23
Q536.45
List Price:  Q766.39
You save:  Q229.94
GY$14,637.29
List Price:  GY$20,911.31
You save:  GY$6,274.02
ISK kr8,539.47
List Price:  ISK kr12,199.77
You save:  ISK kr3,660.30
DH631.91
List Price:  DH902.78
You save:  DH270.86
L1,160.02
List Price:  L1,657.25
You save:  L497.22
ден3,661.35
List Price:  ден5,230.73
You save:  ден1,569.37
MOP$560.11
List Price:  MOP$800.20
You save:  MOP$240.08
N$1,226.11
List Price:  N$1,751.66
You save:  N$525.55
C$2,566.99
List Price:  C$3,667.29
You save:  C$1,100.29
रु9,821.33
List Price:  रु14,031.07
You save:  रु4,209.74
S/246.08
List Price:  S/351.57
You save:  S/105.48
K294.16
List Price:  K420.25
You save:  K126.08
SAR262.55
List Price:  SAR375.09
You save:  SAR112.54
ZK1,672.74
List Price:  ZK2,389.74
You save:  ZK716.99
L302.11
List Price:  L431.60
You save:  L129.49
Kč1,447.94
List Price:  Kč2,068.58
You save:  Kč620.63
Ft23,415.87
List Price:  Ft33,452.68
You save:  Ft10,036.80
SEK kr655.18
List Price:  SEK kr936.02
You save:  SEK kr280.83
ARS$99,596.21
List Price:  ARS$142,286.39
You save:  ARS$42,690.18
Bs485.18
List Price:  Bs693.15
You save:  Bs207.96
COP$278,399.60
List Price:  COP$397,730.76
You save:  COP$119,331.16
₡35,284.01
List Price:  ₡50,407.89
You save:  ₡15,123.87
L1,831.26
List Price:  L2,616.20
You save:  L784.93
₲502,902.28
List Price:  ₲718,462.62
You save:  ₲215,560.34
$U2,797.24
List Price:  $U3,996.23
You save:  $U1,198.99
zł253.28
List Price:  zł361.85
You save:  zł108.56
Already have an account? Log In

Transcript

Now a simple exercise for you. I hope now all things related to generator are very clear. The exercise is also not going to be very complex, it's rather simple. What you're required to do, you're required to actually test about what you have learned and how you're required to write a generator function which returns the key series. They are calculated using the following formula, the first two numbers of the series is always equal to one, and each consecutive number returned is the sum of the last two numbers. So the first two numbers are one, the first number is one, the second number is one.

The third number is the sum of the first two numbers that is one plus one, two, then the fourth number is two plus one, three, and so on. And you can easily do it the hint is, can you use two variables in the generator function? Yes, you can do it easily. And the second hint is the assignment of variables can be done simultaneously. So at a time you can assign two values to two different variables together. And this is the hint.

It's something very easy to do within three to four lines of code, you can easily do it

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.