All language subtitles for 006 Getting Input From The User_en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
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
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian Download
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,870 --> 00:00:03,170 Now what we've done so far is pretty good. 2 00:00:03,180 --> 00:00:10,260 We can use variables now to change the MAC address to any MAC address we want easily and to any interface. 3 00:00:11,010 --> 00:00:17,280 But every time the user wants to change these variables, they have to open the code, they have to 4 00:00:17,280 --> 00:00:23,130 open the program and modify its code manually, which is not very good. 5 00:00:23,610 --> 00:00:30,210 It will be nicer if we can get the user to input the variables that they want through the terminal. 6 00:00:30,930 --> 00:00:33,480 So there are a number of ways to do that. 7 00:00:33,870 --> 00:00:38,820 And in this lecture we're going to talk about the input function. 8 00:00:39,210 --> 00:00:42,300 So all we have to do is just use the input function like. 9 00:00:42,300 --> 00:00:45,870 So I put a string that will be displayed to the user. 10 00:00:45,870 --> 00:00:52,710 So for example, ask for your age and then initialize that to be stored in a variable called anything 11 00:00:52,710 --> 00:00:53,190 we want. 12 00:00:53,190 --> 00:00:55,680 And in this example we're calling it age. 13 00:00:55,950 --> 00:00:58,680 Then the user is going to see this What's your age? 14 00:00:58,860 --> 00:01:05,459 If they input, for example, ten, then ten will be stored in this variable and then we can print it 15 00:01:06,420 --> 00:01:06,900 again. 16 00:01:06,900 --> 00:01:08,160 This is very boring. 17 00:01:08,160 --> 00:01:15,750 So what we're going to do is we're going to use something within our cool code and ask the user to enter 18 00:01:15,750 --> 00:01:19,830 the interface and the new Mac and then use it in here. 19 00:01:20,370 --> 00:01:27,090 So we already have a variable called interface and all we have to do instead of initializing it like 20 00:01:27,090 --> 00:01:30,750 this, we want the user to put this value for us. 21 00:01:31,380 --> 00:01:37,620 So instead of initializing it and saying it had zero here, we're going to say the interface is going 22 00:01:37,620 --> 00:01:41,070 to equal to the input that the user will give me. 23 00:01:43,140 --> 00:01:49,230 And inside this we're going to put the text that the user will see. 24 00:01:49,230 --> 00:01:51,990 So we're going to ask for the interface. 25 00:01:54,870 --> 00:01:56,520 Same goes for the Mac. 26 00:01:56,550 --> 00:02:03,450 So instead of initializing the Mac within the code like this, we're going to say new Mac is going to 27 00:02:03,450 --> 00:02:08,160 equal to and I want that to be taken from the user input. 28 00:02:08,160 --> 00:02:14,990 So we're using the input function and I want the user to see a message asking for the new Mac. 29 00:02:15,000 --> 00:02:18,840 So in that message I'm going to say New Mac. 30 00:02:20,230 --> 00:02:20,870 And that's it. 31 00:02:20,890 --> 00:02:25,030 We're going to start this and let's run it and see what it's going to look like. 32 00:02:25,810 --> 00:02:28,840 So Python might change your dot pie. 33 00:02:28,930 --> 00:02:32,670 And as you can see, the program will not execute further code. 34 00:02:32,680 --> 00:02:36,940 It will stop and it will first ask me for the interface. 35 00:02:37,480 --> 00:02:45,610 So whenever I put Land Zero in here, this will automatically initialize interface to land zero because 36 00:02:45,610 --> 00:02:50,470 we said interface equals input and I'm given the input in here. 37 00:02:50,470 --> 00:02:54,280 So the user is given the input themselves through the terminal. 38 00:02:54,910 --> 00:02:56,470 Now if I enter. 39 00:02:57,550 --> 00:03:02,260 Now we got an error because this is actually a Python three function. 40 00:03:02,260 --> 00:03:09,520 So we have to say Python three in here because if you just type Python, it will run with Python 2.7. 41 00:03:10,090 --> 00:03:11,980 So we run this again. 42 00:03:12,010 --> 00:03:13,900 It's asking me for the interface. 43 00:03:13,900 --> 00:03:15,700 We set that to land zero. 44 00:03:16,420 --> 00:03:21,940 Now the code will stop again and it asks me for the new Mac. 45 00:03:22,090 --> 00:03:29,550 So we're going to set that to 0011, two, two, three, three, four, four. 46 00:03:29,560 --> 00:03:34,330 And I'm going to go for four four again to just use something different to make sure that this code 47 00:03:34,330 --> 00:03:35,230 is going to work. 48 00:03:35,680 --> 00:03:41,110 And now it's already the code has already initialized interface with land zero. 49 00:03:41,260 --> 00:03:46,840 Once I hit Enter, it's going to initialize new Mac with the value that I just inputted, which is the 50 00:03:46,840 --> 00:03:47,650 new Mac. 51 00:03:47,680 --> 00:03:52,660 Then it's going to use it in here and in here exactly the same way as before. 52 00:03:53,440 --> 00:03:55,780 So let's set enter and see what happens. 53 00:03:57,430 --> 00:04:02,320 It's printing the right print statement for also telling us that it's changing MAC address for line 54 00:04:02,320 --> 00:04:05,020 zero to this MAC address. 55 00:04:05,050 --> 00:04:12,010 So again, the print statement, it's a really good way of knowing that interface and New Mac actually 56 00:04:12,010 --> 00:04:13,510 hold the values that we want. 57 00:04:13,510 --> 00:04:19,839 So they hold the values that the user did actually input because when your code gets more complicated, 58 00:04:19,839 --> 00:04:25,570 you can make mistakes and maybe the variables will not hold the value that you expect them to hold. 59 00:04:26,110 --> 00:04:28,840 So let's do if config line zero. 60 00:04:30,220 --> 00:04:32,350 And see if the Mac changed. 61 00:04:32,350 --> 00:04:37,120 And as you can see, it actually did get changed to the Mac address that we want. 62 00:04:37,930 --> 00:04:40,160 Now, going back to this error. 63 00:04:40,180 --> 00:04:46,450 We got this because we were running the code using Python 2.7, not Python three. 64 00:04:46,750 --> 00:04:50,260 And like I said, these two versions are very, very similar. 65 00:04:50,350 --> 00:04:57,310 So if you want this code to run with Python 2.7, all you have to do is just type pro input instead 66 00:04:57,310 --> 00:04:58,030 of input. 67 00:04:58,030 --> 00:05:01,450 So it's just the function has a different name. 68 00:05:02,020 --> 00:05:06,160 So we change that to raw input and we change that to row input. 69 00:05:09,910 --> 00:05:11,170 Going down. 70 00:05:11,200 --> 00:05:15,460 And we're just going to run it this time with Python, not Python three. 71 00:05:15,940 --> 00:05:16,990 Hit enter. 72 00:05:17,020 --> 00:05:19,000 Ask me for the interface. 73 00:05:19,180 --> 00:05:30,160 Let's set it to zero this time and set the new mark to 0011223344, two, two. 74 00:05:30,490 --> 00:05:31,630 Hit enter. 75 00:05:31,720 --> 00:05:37,240 We get the right values in the print statement, the right interface and the right mac address. 76 00:05:37,240 --> 00:05:40,570 And if we do, if config at zero. 77 00:05:41,540 --> 00:05:45,260 You can see the Mac address changed to four, four, two, two. 78 00:05:45,260 --> 00:05:48,530 The same Mac address that we said in here. 79 00:05:49,240 --> 00:05:54,540 So this just goes to show you that Python 2.7 and three are very similar. 80 00:05:54,550 --> 00:05:57,460 Once you know one of them, you can use the other. 81 00:05:58,090 --> 00:05:59,790 So that's it for this lecture. 82 00:05:59,800 --> 00:06:07,270 I just wanted to introduce the input or the raw input function that allows the user to initialize variables 83 00:06:07,270 --> 00:06:10,150 or interact with the program through the terminal. 84 00:06:10,150 --> 00:06:16,000 So when they actually run the program, instead of having to manually modify the code every time they 85 00:06:16,000 --> 00:06:17,470 need to change a variable. 8274

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