All language subtitles for 033 [Interactive Coding Exercise] Pizza Order Practice.en

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
tl Filipino
fi Finnish
fr French Download
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,180 --> 00:00:04,740 All right, guys, are you ready for another challenge? In this challenge, 2 00:00:04,770 --> 00:00:07,980 you are going to be building a Pizza Order program. 3 00:00:08,430 --> 00:00:12,690 So we're going to ask the user what size pizza they want, small, medium, 4 00:00:12,690 --> 00:00:16,770 or large, whether if they want to add pepperoni to it and whether 5 00:00:16,770 --> 00:00:18,120 if they want extra cheese. 6 00:00:18,660 --> 00:00:23,660 So based on the user's input for each of these variables, and the inputs going to 7 00:00:24,990 --> 00:00:29,400 come in the form of a single capital letter, S, M, or L, Y or N. 8 00:00:30,240 --> 00:00:31,350 Based on their input, 9 00:00:31,380 --> 00:00:34,710 we're going to try and figure out what the final bill is going to come to. 10 00:00:35,400 --> 00:00:37,920 And you can take a look at the prices over here. 11 00:00:38,430 --> 00:00:42,600 So, if you want to add pepperoni for a small pizza, it's a $2, medium, 12 00:00:42,600 --> 00:00:47,340 or large pizza is $3, and an extra cheese is $1 for any size. 13 00:00:47,820 --> 00:00:51,690 So you're going to use what you've learned about multiple if statements, 14 00:00:51,780 --> 00:00:56,250 as well as everything from previously in order to be able to create this so that 15 00:00:56,280 --> 00:00:59,490 if the user types in, for example, this input, 16 00:00:59,880 --> 00:01:04,880 large, pepperoni with no extra cheese, then it should print out 17 00:01:05,070 --> 00:01:10,020 Your final bill is $28. Have a look at the examples and the hints 18 00:01:10,350 --> 00:01:13,530 and go ahead and solve this coding challenge. 19 00:01:16,650 --> 00:01:16,950 All right, 20 00:01:16,950 --> 00:01:21,390 so this one shouldn't be too hard and we're going to start off by creating our 21 00:01:21,390 --> 00:01:25,560 first if statement where we're going to check out what is the size of the pizza 22 00:01:25,560 --> 00:01:29,190 that they chose so we can assign the price to that pizza. 23 00:01:29,940 --> 00:01:34,940 If the size is equal to S, that means they ordered a small pizza, 24 00:01:36,780 --> 00:01:41,460 well in this case, the price should be $15, right? Now, 25 00:01:41,490 --> 00:01:45,990 we're going to create a variable up here before the if statement so that we can 26 00:01:45,990 --> 00:01:47,580 keep track of the bill. 27 00:01:48,150 --> 00:01:53,150 So size S, the bill is going to be increased by $15. 28 00:01:54,450 --> 00:01:58,650 Now you can, of course, simply just set the bill to $15 in this case, 29 00:01:59,070 --> 00:02:01,740 but because we've got a lot of things that can change the bill, 30 00:02:02,040 --> 00:02:07,040 it's easier to simply just add 15 to what it is currently using the plus equal 31 00:02:07,230 --> 00:02:08,310 sign that you learned about. 32 00:02:09,150 --> 00:02:12,240 Then we're going to check with an elif. Elif 33 00:02:12,240 --> 00:02:16,410 the size is equal to M, so if they chose a medium pizza instead, 34 00:02:16,830 --> 00:02:20,400 then the bill is going to increase by $20 instead. 35 00:02:20,940 --> 00:02:24,660 And finally, for all other cases, namely, 36 00:02:24,660 --> 00:02:26,340 if they'd got a large size pizza, 37 00:02:26,760 --> 00:02:30,810 then we're going to increase the bill by, um, 38 00:02:30,840 --> 00:02:33,360 $25. Now, 39 00:02:33,390 --> 00:02:38,390 notice how here you could have also used an elif and said elif size equal 40 00:02:38,580 --> 00:02:41,220 to L, um, well, in that case, 41 00:02:41,220 --> 00:02:46,220 the bill increases by $25 and you don't actually need an else statement. 42 00:02:46,830 --> 00:02:48,420 It's not required. 43 00:02:48,600 --> 00:02:53,600 If you feel like it's easier to read like this, small, 44 00:02:53,670 --> 00:02:56,760 medium, large, and what should happen for each case, 45 00:02:57,090 --> 00:03:00,280 then you can just leave it like this. But of course, 46 00:03:00,280 --> 00:03:03,970 there is an argument to be made that the user might have typed something wrong, 47 00:03:03,970 --> 00:03:06,610 right? They might've typed a lowercase letter, 48 00:03:06,610 --> 00:03:10,540 they might've typed a completely different letter. So in future lessons, 49 00:03:10,600 --> 00:03:14,590 we're going to show you how you can catch these cases and how you can deal with 50 00:03:14,590 --> 00:03:18,550 it. But for now, let's just keep our program as simple as possible. 51 00:03:19,060 --> 00:03:22,330 If they type the wrong letter, instead of S, M, or L, 52 00:03:22,330 --> 00:03:24,040 then we're just going to overcharge them. 53 00:03:24,490 --> 00:03:28,240 So now that we've established what the basic price for their pizza is, 54 00:03:28,540 --> 00:03:30,640 we're going to look through the ad-ons. 55 00:03:30,670 --> 00:03:33,490 We're going to see if they said they wanted to add pepperoni. 56 00:03:33,520 --> 00:03:38,260 So if add pepperoni is equal to Y, well, 57 00:03:38,260 --> 00:03:39,310 in that case, 58 00:03:39,340 --> 00:03:43,060 we're going to need to check if they have a small pizza or a medium, 59 00:03:43,060 --> 00:03:46,390 or large pizza, 'cause the price is different. 60 00:03:46,660 --> 00:03:49,630 So we're going to have a nested, if function in here. 61 00:03:50,110 --> 00:03:53,170 We're going to say if add pepperoni is equal to Y, 62 00:03:54,910 --> 00:03:59,910 and then if the size is equal to S, well, 63 00:04:00,250 --> 00:04:04,180 in this case, we're only going to add, um, $2 to the bill. 64 00:04:05,050 --> 00:04:08,860 But if the size was any other size, basically medium or large, 65 00:04:09,100 --> 00:04:11,620 so we can catch that using just an L statement 66 00:04:11,680 --> 00:04:16,600 instead of creating three separate, if sizes S, if sizes M, et cetera. 67 00:04:17,230 --> 00:04:20,500 And in this case, we're going to add $3 to the bill. 68 00:04:21,790 --> 00:04:25,150 So now we've got this case covered. 69 00:04:25,270 --> 00:04:29,350 The final thing is whether if they said they wanted extra cheese or not. 70 00:04:29,920 --> 00:04:32,980 So if they did, in fact, want extra cheese, 71 00:04:35,110 --> 00:04:35,380 well, 72 00:04:35,380 --> 00:04:39,670 in that case, all we have to do is just add $1 to the bill. 73 00:04:40,480 --> 00:04:45,100 So these are three separate sets of if statements; 74 00:04:45,460 --> 00:04:47,530 this one, this one, and this one. 75 00:04:47,980 --> 00:04:51,400 And by the end of all of these if statements, 76 00:04:51,730 --> 00:04:54,160 as long as we're at the right indentation level 77 00:04:54,190 --> 00:04:56,230 namely right next to the gutter here, 78 00:04:56,530 --> 00:05:00,880 then we can go ahead and calculate their bill and print it out for them. 79 00:05:01,270 --> 00:05:02,740 So we can say print, 80 00:05:02,800 --> 00:05:06,700 and I'm going to use an f-string to insert the bill in here, print 81 00:05:06,880 --> 00:05:09,910 Your final bill is, 82 00:05:10,150 --> 00:05:14,350 and then I'm going to add a dollar sign, and then inside the curly braces, 83 00:05:14,410 --> 00:05:19,060 I'm going to put it in the current value of the bill after all of these 84 00:05:19,060 --> 00:05:22,060 calculations. So did you manage to get it right? 85 00:05:22,210 --> 00:05:27,210 Did you manage to use a combination of if statements and elif statements, 86 00:05:28,840 --> 00:05:32,470 um, nested if statements, or did you do it in a different way? 87 00:05:32,500 --> 00:05:36,250 And it's totally cool if you did. As long as it does what it's supposed to do, 88 00:05:36,640 --> 00:05:39,970 then it doesn't really matter whichever format of your code 89 00:05:40,000 --> 00:05:42,550 you decide to go for it. And as a matter of fact, 90 00:05:42,550 --> 00:05:46,030 there's loads of ways that you could have written this code to get this 91 00:05:46,030 --> 00:05:49,270 functionality. Some of them will be slightly more readable, 92 00:05:49,570 --> 00:05:51,430 some of them will be slightly less readable. 93 00:05:51,610 --> 00:05:56,470 So, it's a case of you making a good judgment on that and choosing the code that 94 00:05:56,470 --> 00:06:00,200 makes the most sense to you. Now in the next lesson, 95 00:06:00,590 --> 00:06:05,590 I want to talk a little bit about combining different conditions so that we can 96 00:06:05,960 --> 00:06:10,960 use something called a logical operator to check for multiple conditions in the 97 00:06:11,390 --> 00:06:16,280 same line of code. So, for all of that and more, I'll see you on the next lesson, 9493

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.