All language subtitles for 012 [Interactive Coding Exercise] Input Function_en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic Download
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
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

Original subtitles

All right. So again,

it's time to put theory into practice and get some hands-on action.

You should be able to find the day 1.3 assignment which is inputs.

Click on it and you will see the instructions for this particular challenge.

And the idea is that you're going to write a program

that's going to print the number of characters in a user's name. For example,

if I input my name, which is Angela,

it should output the number six because there are six characters in the word,

Angela. But remember you can't just print out the number six,

because when I'm checking for this code,

I'm going to try a whole bunch of different names as the input.

And you're going to have to use a little bit of thinking,

a little bit of Googling and also a little bit of messing around with the code

in order to get it to work. If you need any help,

there's a few hints down here for you. And if you really get stuck,

then you can take a look at the solution,

but not until you've really given it a go. And I really,

really want to know that you've tried hard.

And the whole point of these exercises is you sit there and scratch your head a

little bit and actually give it a good go.

So I'm going to stop talking now and I'm going to let you pause the video and

try to complete this challenge. All right, good luck.

Okay. So how did that go? If you get stuck, I want to tell you

the programmers secret to getting unstuck

which is go and grab yourself a cup of tea, have a quick break,

look at something else for a little moment,

think about something else and then come back to it. Well,

the tea part is optional. Well, at least if you're outside of England,

it's optional. So let's get started solving this challenge.

So the idea is that we're going to create a program that counts the number of

characters in any user's name.

And that name is obviously going to come through an input function,

and then we're going to use a function that calculates the length of a string

and we're going to send that out as the output.

The first thing we'll probably need is some form of input function right?

And the prompt that we're going to give the user is what is your name or

something similar that asks them for their name.

And I like to add a space at the end of the prompt. This way, when you run it,

you don't actually have that cursor straight next to the, um, the question mark

which looks a bit weird. But either way, once we've entered an input,

then this part gets replaced by that input

and we're going to do something with it.

We're going to calculate the length of that string.

Now using our eyes, we can obviously see that it's six characters long.

But what if you have a really a long name?

So let's go ahead and take a look at how we might figure out,

um, how to you get a function that calculates the length of a string.

I've actually included the Google search that you might need to use.

And so let's just paste that URL in here,

and you can see that we're searching for how to get the length of the string in

Python and we're trying to get results from Stack Overflow.

The first result is a question that seems to pretty match match exactly what we

want. And the answer from user 225312

tells us that you need to use the Len function. And the way that you use it

is by passing the string inside the parentheses.

Now this part might look a little bit different from what you're used to with the

equal sign and everything.

But I have confidence that if you mess around with this code,

you'll be able to figure it out.

Just like what we did with print or input,

the Len function also has a set of parentheses and it will work its magic on

whatever it is that we put inside the parentheses. If I just put my name,

Angela here,

let's just comment out the previous line, and I go ahead and print the result of

this and then I hit run, you can see that it prints 6. Now,

if I change that to Jack, then you'll see it prints 4.

So it will print whatever it is

the length of the string that I've put inside the Len function.

So we're getting close now, right?

Because instead of printing out a string that I've hard coded here,

what I want is to take the input that the user has given me.

So something like this. Now, if you want to,

you can actually add some spaces inside here just to make it a little bit

clearer to yourself as to what's actually going on because there's three

functions here. They are all nested inside each other.

So this is the first one,

this is the one that is going to get the input from the user and replace this

part with whatever it is that they type down here.

Then that string gets calculated using the Len function to get the length of

that string. And then that number will get printed by the print function.

Now let's go ahead and hit run and let's give it a go.

So let's try Jack, hit enter.

And it tells us that it's 4.

But using the same line of code,

if we try a different name Angela, then it prints out six.

How did you get on with this? If you got stuck,

then have a look at the solution Repl.it um,

where you will be able to find the code that I've written here and a little bit

of explanation as well.

The important thing is that you really play around with this code.

Try things and make it break and make it work and just get it to do what you

want it to do.

And remember that if you ever want to visualize these things and the order of

execution, then you can always use Thonny to see that.

So let's go ahead and step in.

You'll see that it goes through Len, input, and then it's going to carry out this

functionality input. I gave it my name, hit enter.

Then it puts that inside the Len function like so,

so now the next step is this part.

We're going to calculate the length of this string.

And as I continue stepping into it, you can see that become six.

And finally we're gonna carry out the final instruction,

which is just to print six down here. Again,

this can be quite useful just to visualize all the steps that are happening

if you want to.

Once you're done, head over to the next lesson and I'm going to talk to you

all about Python variables and how we'll be able to identify pieces of data in

our code. So for all of that, and more, I'll see you there.

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