Generator Complex Example

2 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
€60.93
List Price:  €87.05
You save:  €26.11
£52.77
List Price:  £75.39
You save:  £22.61
CA$96.25
List Price:  CA$137.51
You save:  CA$41.25
A$101.09
List Price:  A$144.42
You save:  A$43.33
S$90.03
List Price:  S$128.62
You save:  S$38.59
HK$548
List Price:  HK$782.89
You save:  HK$234.89
CHF 55.55
List Price:  CHF 79.37
You save:  CHF 23.81
NOK kr684.16
List Price:  NOK kr977.42
You save:  NOK kr293.25
DKK kr455.29
List Price:  DKK kr650.45
You save:  DKK kr195.15
NZ$121.35
List Price:  NZ$173.37
You save:  NZ$52.01
د.إ257.03
List Price:  د.إ367.21
You save:  د.إ110.17
৳8,601.02
List Price:  ৳12,287.70
You save:  ৳3,686.67
₹6,582.43
List Price:  ₹9,403.88
You save:  ₹2,821.44
RM275.72
List Price:  RM393.91
You save:  RM118.18
₦95,753.31
List Price:  ₦136,796.31
You save:  ₦41,043
₨19,571.19
List Price:  ₨27,960.05
You save:  ₨8,388.85
฿2,311.48
List Price:  ฿3,302.26
You save:  ฿990.78
₺3,102.70
List Price:  ₺4,432.63
You save:  ₺1,329.92
B$375.01
List Price:  B$535.75
You save:  B$160.74
R1,202.98
List Price:  R1,718.62
You save:  R515.64
Лв119.15
List Price:  Лв170.23
You save:  Лв51.07
₩106,116.29
List Price:  ₩151,601.20
You save:  ₩45,484.90
₪220.49
List Price:  ₪315
You save:  ₪94.51
₱4,230.75
List Price:  ₱6,044.19
You save:  ₱1,813.43
¥11,172.27
List Price:  ¥15,961.07
You save:  ¥4,788.80
MX$1,265.31
List Price:  MX$1,807.67
You save:  MX$542.35
QR256.32
List Price:  QR366.19
You save:  QR109.86
P955.83
List Price:  P1,365.54
You save:  P409.70
KSh9,070.70
List Price:  KSh12,958.70
You save:  KSh3,888
E£3,656.83
List Price:  E£5,224.27
You save:  E£1,567.44
ብር11,046.94
List Price:  ብር15,782.03
You save:  ብር4,735.08
Kz63,840.04
List Price:  Kz91,203.97
You save:  Kz27,363.93
CLP$65,411.21
List Price:  CLP$93,448.59
You save:  CLP$28,037.38
CN¥483.73
List Price:  CN¥691.08
You save:  CN¥207.34
RD$4,160.88
List Price:  RD$5,944.37
You save:  RD$1,783.49
DA9,292.91
List Price:  DA13,276.16
You save:  DA3,983.24
FJ$156.37
List Price:  FJ$223.39
You save:  FJ$67.02
Q536.93
List Price:  Q767.08
You save:  Q230.14
GY$14,664.98
List Price:  GY$20,950.87
You save:  GY$6,285.89
ISK kr8,747.35
List Price:  ISK kr12,496.75
You save:  ISK kr3,749.40
DH654.99
List Price:  DH935.74
You save:  DH280.75
L1,224.57
List Price:  L1,749.46
You save:  L524.89
ден3,755.43
List Price:  ден5,365.14
You save:  ден1,609.70
MOP$565.79
List Price:  MOP$808.31
You save:  MOP$242.52
N$1,182.46
List Price:  N$1,689.30
You save:  N$506.84
C$2,579.27
List Price:  C$3,684.83
You save:  C$1,105.56
रु10,484.81
List Price:  रु14,978.94
You save:  रु4,494.13
S/242.34
List Price:  S/346.21
You save:  S/103.87
K302.57
List Price:  K432.26
You save:  K129.69
SAR262.82
List Price:  SAR375.47
You save:  SAR112.65
ZK1,368.62
List Price:  ZK1,955.26
You save:  ZK586.63
L310.66
List Price:  L443.82
You save:  L133.16
Kč1,494.21
List Price:  Kč2,134.68
You save:  Kč640.47
Ft24,015.94
List Price:  Ft34,309.96
You save:  Ft10,294.02
SEK kr664.43
List Price:  SEK kr949.24
You save:  SEK kr284.80
ARS$97,394.05
List Price:  ARS$139,140.33
You save:  ARS$41,746.27
Bs484.35
List Price:  Bs691.95
You save:  Bs207.60
COP$259,186.05
List Price:  COP$370,281.66
You save:  COP$111,095.60
₡32,740.71
List Price:  ₡46,774.45
You save:  ₡14,033.73
L1,855.37
List Price:  L2,650.65
You save:  L795.27
₲457,825.21
List Price:  ₲654,064.06
You save:  ₲196,238.84
$U2,851.34
List Price:  $U4,073.52
You save:  $U1,222.17
zł261.23
List Price:  zł373.20
You save:  zł111.97
Already have an account? Log In

Transcript

This is a more complex example, aren't ready for it. Okay, let's let's do this lottery number generator. So we're going to use a generator function to define to create a function of lottery number. Okay, let's first import the library random number and execute this code. Next is we can define a pin number function that reads a pin number one that I use the for loop in green six, and the yield statement that produces random dot random it. It's a method within the library random and the number that we're looking to producers between one and 52.

The first six number that we need is between one and 50 Seventh generating number is we are looking between one and 25. So let's execute this code and move to next code. We defined a variable then pause this function to a variable. And then we're going to produce. So what it is actually going to do it is going to produce when numbers to execute this line of code now, this line of code it printed nine, so the random number generator between one and 50 is nine. And I'm going to generate the rest of the numbers within this number by you The for loop.

So I defined this and let's produce the results. So all the seven numbers are now generated. If I go back above, you see I use the y variable, it generated nine. Now I'm not using this Y variable again the next time when I use the for loop, so it should be all seven numbers together. 1234567 so it is a treating offer the results that are being called one by one and it produces all the numbers together. If I wanted to generate one number at a time, I could have used next

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.