Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranî)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
0 Now you should have PyCharm up and running, 1
and we're finally ready to tackle today's project, 2
which we're going to write in PyCharm. You've just been hired. 3
Congratulations, but first there's the matter of coffee. 4
We all know that programmers can't work unless they're loaded up on coffee. 5
So your company has asked you to create the code for a coffee machine. 6
Now you, very cleverly, go online and look at the other coffee machines. 7
And you notice that it only costs $230 to buy a coffee machine, 8
but you're not going to cheat. You're going to create everything from scratch. 9
And luckily we don't actually have to build the hardware because we're programmers, 10
right? 11
But we're going to use this real-life coffee machine as the inspiration for our 12
virtual coffee machine, noting the features and the capabilities. 13
So what does it say? I found some wonderful graphics on here 14
which tells me that they're three hot flavors 15
which I'm guessing are these three buttons, it's coins operate 16
which I think they mean it's coin operated, and there's not much else that it can 17
do. 18
Let's take this example and we're going to make a digital version of it. 19
We're going to create our own coffee machine. 20
And the first step we need to replicate is the ability to make three hot 21
flavors. So the flavors we're going to make are 1. espresso, 22
2. latte, and 3. cappuccino. Here 23
are the recipes for these three types of drinks. 24
Each of them requires a different quantity of water, 25
a different quantity of coffee and a different quantity of milk. 26
And they also each half a different price. 27
We're going to be modeling all this data in our coffee machine program as well. 28
But luckily for you in the starting code, 29
I've already included all of this data inside a dictionary. 30
So you don't have to remember this, 31
although it might help if you're at home and you decided that you really wanted 32
a latte instead of your usual black coffee. Now, in addition, 33
the coffee machine has some resources that it has to manage. 34
So it starts out with 300ml of water in the tank, 35
200ml of milk and 100 grams of coffee. 36
The second feature of our coffee machine is that it's coin operated. 37
So we're going to be using American coins and they have four types of coins: 38
the penny, the nickel, the dime, and the quarter. 39
They used to also have the dollar as a coin 40
but a few years ago they stopped minting that. So we're not going to count it 41
and it probably means one less if statement for us. 42
Notice what each of these coins are worth. The penny is worth a cent, 43
the nickel worth 5 cents and the dime 10 cents, 44
and the quarter is a quarter of a dollar. 45
These represented in decimal values would look something like this. 46
Now here's the important part. Let's think about what our program requirements are 47
if we break it down one. 48
1. We need our coffee machine to be able to print a report. 49
It needs to be able to tell us what resources it has left, 50
how much water has left, how much milk, et cetera. 51
If you head over to the completed version of the coffee machine, 52
the link is in the course resources, 53
and you can go ahead and try out the final version of the coffee machine. 54
So let's say that we wanted a report on all the resources that the machine has. 55
All we have to do is type report, and we can see all the resources we have. 56
Now, in addition to being able to print a report, 57
we also want to be able to check that the resources are sufficient when the user 58
orders a drink. Now let's say that the user decided to order a latte. 59
It asks me to insert some coins and then it gives me the change and it gives me 60
the latte. But now if I check the report, 61
I can see that I've only got a hundred mils of water left. 62
And I know from the previous slide that a latte and a cappuccino is going to 63
need more than that amount of water. So let's see what happens 64
if I go ahead and order a cappuccino. It says, sorry, 65
there's not enough water. 66
So our program is able to look through all the resources that the machine has, 67
checks it against the recipe of the drink that we're trying to make, and tells the 68
user if there is insufficient water or if there's insufficient milk, 69
and as long as one of the resources is insufficient, 70
then it can't make the drink and it gives the feedback to the user. Now, 71
as you saw before, 72
our program also needs to be able to process coins because our machine is coin 73
operated. 74
So no fancy contactless payments or pay with your Apple watch, none of that. 75
We've only got coins. When we order something, 76
it should ask us to insert coins. 77
And it's going to ask for the quantity of each type of coin. 78
So let's say that I insert one of each, then in this case, 79
there's actually not enough money to cover my drink and it refunds the money and 80
doesn't give me a drink. But on the other hand, if I do insert enough money, 81
then it should be able to calculate how much money all of these coins are worth 82
and then calculate the amount of change based on the cost of my drink. 83
And then it should hand me my drink and tell me to enjoy. So, 84
in addition to being able to process the four types of coins, 85
calculating the actual monetary value based on the number of points, 86
it should also check that the transaction is successful. 87
That the user didn't try to hoodwink us by not giving enough coins and asking 88
for a drink. So if they haven't inserted enough coins, 89
then we're just going to refund them and tell them, sorry 90
that's not enough money, and not give them their drink. 91
But if the transaction was successful, 92
then we're going to make the coffee. And in the process of making the coffee, 93
we're going to have to deduct the resources. 94
Notice how every time we make a drink, 95
say in this time we made a latte and previous to the latte, 96
we have 300 mills of milk. But after the latte, 97
when we asked for the report, you can see that the water has been reduced, 98
the milk has been reduced, 99
the coffee has been reduced and the money has been put into the coffer. 100
This program, even though it seems simple, 101
just a simple digital version of a coffee machine, 102
it actually has quite a few requirements. 103
So I recommend that you look at the screen and try to see how each of the 104
requirements work by having a play around with the final version of the code. Now 105
I've created a detailed program specification for you as a PDF file 106
which you can download in the course resources. 107
And this goes into a lot more details on each of those points. For example, 108
what should the prompt print in the beginning of the program, 109
and then how to turn the machine off, 110
how to print the reports and how each of those points should work in detail. 111
Go ahead and download this and make sure you read each of the sections and test 112
it out in the final working version of the project. 113
Once you're ready, 114
you can go ahead and head over to the starting version of the code. And again, 115
I'm sharing this using Repl.it, 116
but I want you to copy everything that's in here, 117
there's only one file the main.py file, 118
and I want you to create a new project using PyCharm and call it coffee 119
machine, 120
Right? 121
And then create a new file inside your project called main.py, 122
and then paste all of the starting code into your main.py. 123
And now you are going to code inside this file. And once you're ready, 124
you're going to click run and you'll be able to run this main.py down here 125
and this will act as your console. Now, 126
one really handy feature of 127
PyCharm is something called to-do tracking. 128
Whereas previously in Repl.it I've been creating to-dos and you've been able to 129
view them. But if I have lots of to-dos in different places, 130
you can't actually see all of them at once. 131
You have to scroll through the file looking for them. 132
But in a professional tool, 133
we actually have something called to-do tracking and its a tab that's down here. 134
So if I go ahead and take some of these program requirements, 135
I can put them in as to-dos. To create a 136
to-do you have to follow the syntax. First is a pound sign 137
and then we write TODO in all caps, and notice how that's just changed color just 138
now, and now you can see in the todo tab, 139
it's found one todo item. 140
Now we can write todo number one 141
and this is to print a report of all the coffee machine resources. 142
Now let's say that I created a todo somewhere else, right? 143
Like all the way up here, 144
check that the resources are sufficient to make the drink order. And notice how 145
they're completely in different places in a different order. 146
But every time I create one of these todos using this format, 147
it will get picked up in the 148
todo tab. And you can go ahead and see where they live. 149
So it's found two items inside our main.py 150
and you can see that this one is todo one, this one is todo two. 151
And when you click on them, 152
they'll take you to the correct places in your code. 153
Use this to break down the problem into smaller problems that you can solve one 154
by one, 155
just as you've done before and try to see if you can complete this project. 156
Just the word of warning: this project is quite ambitious. 157
But you've now got professional tools to help you, 158
and you've got a lot more skill under your belt. 159
So give this problem at least an hour to work on it and make sure that you 160
satisfy all the criteria that's set out in the program requirements 161
and also that your program works exactly the same as the final version of the 162
coffee machine.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.