Afrikaans
Akan
Albanian
Amharic
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
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
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.