How to Get User Inputs with Python! Beginner Lesson

LeMaster Tech
183 followers
534 Video Views·Apr 23, 2025
This is the best place to learn and practice python skills for beginners looking to get started with Python! Learn how to collect inputs from users, and use those inputs inside your program in just 8 minutes!!
This is episode 3 in an introduction to python series coming from LeMaster Tech.
Be sure to give us a like, drop a comment, or subscribe to the channel for more content like this!
The previous video:
https://www.youtube.com/watch?v=zTAw7zz5xaE
python download:
https://www.python.org/downloads/
pycharm download for windows:
https://www.jetbrains.com/pycharm/download/#section=windows
welcome back to the channel this will be
video three in our python tutorial
series so if you missed the first ones
on installing and setting up python and
pycharm and initial introductions to
variable types go ahead and check those
out you'll probably want that info
but if you're already at that point
then let's get right into it the goal of
this video will be
gathering input from users in your
programs as well as modifying integers
and strings within a program and
actually using them to do a few
different cool operations so this is the
code we started with and it's pretty
plain code from the last video
we have three variables clothing age and
whether or not they're elderly and the
setting of those variables
determines what gets output so we can
see when we run this it just tells us
what the variables are initially set to
and then they get changed inside the
code
and then we set the variables again but
let's say we don't want to just hard
code the variables we actually want the
user to determine what gets put in so
we're actually going to do
all you have to do to prompt a user for
feedback inside of python for input
is you use the input function
and you'll see when we run this that
this is actually going to prompt them to
enter data and inside of the
input is the
actual prompt that they're going to see
so if we say the clothing variable is
now going to be equal to an input of
enter
in article of clothing
and now if we run this
we're going to have enter an article of
clothing and let's say
shoes i don't know if that counts but
when you hit enter it runs the rest of
the code so now you can see right away
there was a man wearing shoes he was 63
and was he old
so we're going to do this for all three
of the variables because you can have
inputs in any format so you can say
input
enter
age
i'm sorry i actually made a mistake
there that actually is good to talk
about in python you can use a single
quotation or a double quotation just an
apostrophe this is the same to python
you can use
either single or double quotations for
string values and they work the same way
and then elderly we will say
input
oh do they and we'll tell them
we'll tell them
that it's going to be a true false
inside of the prompt so that they know
to enter true or false
okay
and as long as there's no errors here
when we run this we'll see our first
prompt which is the initial values
and then we're going to enter an article
of clothing so we're kind of making like
a mad libs type game with this so
article of clothing
we'll just say shirt
enter age he's 24 and is he elderly
no
and right away you can see there was a
man wearing a shirt he was 24 and was he
old no
so this is kind of cool right away you
can see we're prompting users to enter
data
inside of our function and we
immediately use that data to display
something in the code
so
one extra thing i'd like to talk about
real quick is a few individual
properties of strings and numbers so
when we enter an article of clothing
we could say rather than there was a man
wearing a whatever we can say
your
clothing
item
starts with
and we're actually going to reference
one piece of the string that we made
here so a cool thing about strings is
every
individual letter and character inside
of a string has what's called an index
and you can call that by using square
brackets
and defining what index number you want
to use so here you'll see when i say
index 0
and we say article of clothing
hat
age 24
sure he's old
then what you're gonna see
unless i've your clothing item starts
with h right there so
one thing to note about what we just did
we started from zero most people who
aren't unfamiliar with code and
programming would think you would start
from one and the first character in a
string would actually be one but to the
code the first item in something is zero
so if you want to reference the h at the
beginning of hat that's zero if we had
made that a one we would have gotten an
a and if we had made that a two we would
have gotten a t
so it's important to know the length of
a string is actually
technically the number of characters
inside of it minus one because you
always start counting from zero
so one thing we can do with the
number that's just a kind of cool quick
introduction to indexes on strings but
one thing we can do with the number
is we can rather than turning it into a
string we could add it to something and
we can say
so we will say
in 10
years you will be and what we're going
to do here
is we're actually going to perform math
we are going to say 10 plus the age
entered and we're doing it all
inside
of a string function so it'll still
display with our prompt but what you
actually see is inside this set of
brackets we're doing 10 plus age so
whatever age we enter when we run this
again we'll say
hat
and we will say 24 and we will say we
are not old
oh what have i done
okay
one thing i forgot to enter
was when you
need a variable and you haven't defined
what data type it's going to be but you
need it to be a specific type you need
to add this condition to your variable
statement so i was just calling for an
input and by default when we call the
user to enter something that's going to
come in as a string
what i've added is the int function
which will convert the input to an
integer and so now we can see when we
run this
enter article of clothing let's do a
suit this time
enter age let's say 33
and is this elderly yeah so your
clothing item starts with s we already
covered that's still true but now in 10
years you will be 43.
so what's kind of cool you're we're
already
asking the user for input we're
manipulating that data and we're
returning something different than what
they just put put in previously we were
just taking the information we were
giving and we were displaying it to show
why you might need variables but now
we're starting to do something
and this is going to come in handy for
our next video when we go ahead and
build a simple calculator so as always
thank you for watching and if you found
this useful feel free to like and
subscribe to the channel for more
tutorials
and we'll see you next time thanks bye
