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.37
List Price:  €84.81
You save:  €25.44
£51.33
List Price:  £73.33
You save:  £22
CA$95.69
List Price:  CA$136.71
You save:  CA$41.01
A$96.51
List Price:  A$137.87
You save:  A$41.36
S$88.70
List Price:  S$126.72
You save:  S$38.02
HK$548.13
List Price:  HK$783.08
You save:  HK$234.94
CHF 54.37
List Price:  CHF 77.68
You save:  CHF 23.30
NOK kr644.55
List Price:  NOK kr920.83
You save:  NOK kr276.27
DKK kr443.76
List Price:  DKK kr633.97
You save:  DKK kr190.21
NZ$117.29
List Price:  NZ$167.57
You save:  NZ$50.27
د.إ257.03
List Price:  د.إ367.21
You save:  د.إ110.17
৳8,565.17
List Price:  ৳12,236.49
You save:  ৳3,671.31
₹6,608.84
List Price:  ₹9,441.60
You save:  ₹2,832.76
RM274.43
List Price:  RM392.06
You save:  RM117.63
₦94,920.06
List Price:  ₦135,605.90
You save:  ₦40,685.83
₨19,454.32
List Price:  ₨27,793.08
You save:  ₨8,338.75
฿2,254.95
List Price:  ฿3,221.49
You save:  ฿966.54
₺3,173.87
List Price:  ₺4,534.29
You save:  ₺1,360.42
B$343.94
List Price:  B$491.37
You save:  B$147.42
R1,146.48
List Price:  R1,637.90
You save:  R491.42
Лв116.15
List Price:  Лв165.94
You save:  Лв49.78
₩102,319.78
List Price:  ₩146,177.38
You save:  ₩43,857.60
₪203.04
List Price:  ₪290.07
You save:  ₪87.03
₱4,235.44
List Price:  ₱6,050.89
You save:  ₱1,815.45
¥10,964.98
List Price:  ¥15,664.93
You save:  ¥4,699.95
MX$1,202.26
List Price:  MX$1,717.58
You save:  MX$515.32
QR255.14
List Price:  QR364.50
You save:  QR109.36
P937.15
List Price:  P1,338.85
You save:  P401.69
KSh9,014.94
List Price:  KSh12,879.04
You save:  KSh3,864.10
E£3,691.60
List Price:  E£5,273.94
You save:  E£1,582.34
ብር10,899.30
List Price:  ብር15,571.10
You save:  ብር4,671.79
Kz64,250.82
List Price:  Kz91,790.82
You save:  Kz27,540
CLP$62,352.24
List Price:  CLP$89,078.45
You save:  CLP$26,726.20
CN¥475.98
List Price:  CN¥680.01
You save:  CN¥204.02
RD$4,151.15
List Price:  RD$5,930.48
You save:  RD$1,779.32
DA9,261.54
List Price:  DA13,231.34
You save:  DA3,969.80
FJ$152.78
List Price:  FJ$218.27
You save:  FJ$65.49
Q532.95
List Price:  Q761.40
You save:  Q228.44
GY$14,605
List Price:  GY$20,865.19
You save:  GY$6,260.18
ISK kr8,532.54
List Price:  ISK kr12,189.86
You save:  ISK kr3,657.32
DH638.40
List Price:  DH912.05
You save:  DH273.64
L1,193.66
List Price:  L1,705.31
You save:  L511.64
ден3,657.48
List Price:  ден5,225.19
You save:  ден1,567.71
MOP$562.82
List Price:  MOP$804.06
You save:  MOP$241.24
N$1,145.17
List Price:  N$1,636.02
You save:  N$490.85
C$2,568.66
List Price:  C$3,669.67
You save:  C$1,101.01
रु10,546.76
List Price:  रु15,067.45
You save:  रु4,520.68
S/241.34
List Price:  S/344.79
You save:  S/103.44
K308.25
List Price:  K440.37
You save:  K132.12
SAR263.68
List Price:  SAR376.71
You save:  SAR113.02
ZK1,328.95
List Price:  ZK1,898.58
You save:  ZK569.63
L309.79
List Price:  L442.58
You save:  L132.78
Kč1,444.36
List Price:  Kč2,063.46
You save:  Kč619.10
Ft20,883.37
List Price:  Ft29,834.67
You save:  Ft8,951.29
SEK kr645
List Price:  SEK kr921.47
You save:  SEK kr276.47
ARS$97,411.25
List Price:  ARS$139,164.89
You save:  ARS$41,753.64
Bs482.34
List Price:  Bs689.09
You save:  Bs206.74
COP$260,853.74
List Price:  COP$372,664.18
You save:  COP$111,810.43
₡32,088.99
List Price:  ₡45,843.39
You save:  ₡13,754.39
L1,855.67
List Price:  L2,651.08
You save:  L795.40
₲426,388.91
List Price:  ₲609,153.12
You save:  ₲182,764.21
$U2,785.95
List Price:  $U3,980.10
You save:  $U1,194.15
zł251.30
List Price:  zł359.02
You save:  zł107.71
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.