Python Tutorial 3: Getting User Input from Keyboard
ฝัง
- เผยแพร่เมื่อ 12 ธ.ค. 2024
- You guys can help me out over at Patreon, and that will help me keep my gear updated, and help me keep this quality content coming:
/ paulmcwhorter
In this video we show step-by-step instructions on how to get input from a user on the keyboard using python. We do not assume you are an expert, so these lessons are designed for complete beginners.
#Python
#Lessons
#Programming
Paul Mcwhorter is the reason why I can code!
Same here Dillon! I've played around with other programming languages before but never really mastered them. Is there anyone that can master Swift?
Same here to!!!
Same heeeeere
Brand new to python here : and I can’t say how grateful I am for your videos ! Truly thank you! Keep em’ coming!
I tried to learn Python but i got bored, Once I've seen Paul's videos I've got excited to learn it with his easy explanations, I feel i could keep up watching these pure videos forever, Thanks a lot.
I will try to keep up adding chapters/timestamps. The primary use for this is create them so I can put them on my Notion course notes for future reference but someone here might find them useful so.....
0:00 Intro
1:03 Past Lessons Recap
2:02 Create a python file
6:06 Get input from the user
9:42 String input example
12:32 Homework
That's a great idea!
Python automatically adds a space between each of the elements separated by commas in the print() statement. To get it to print correctly you can concatenate (glue together two strings) name + the string ',' and that will put the comma in the second string immediately one character position to the right of the name variable which is the first string making a new combined string that then gets output to the screen in the print statement. The full statement to print correctly will be: print('Hello',name+',','Welcome to Python Land')
A fellow woodworker!
Thanks for the content. I've written my first python program and I'm very excited for the upcoming lectures. I made an average calculator for 2 inputs today.
So basically I combined lesson 2 and 3 for this homework. Gotta say it was pretty satisfying. Here's the code :
x=[ ]
y=input('Please enter your first number: ')
z=input('Please enter your second number: ')
x.append(y)
x.append(z)
Ans=int(x[0])+int(x[1])
print('The sum of the entered numbers is = ',Ans)
God Bless you Paul McWhorter. These videos you do are life changing for me. I appreciate everything you do.
I enjoyed the twist in the lesson definitely a great way to make it stick int o my memory.
cannot be anywhere of the world such a teacher like you. thanks for every step of your teaching.
So nice of you
Ok, I have to admit I had a beginning Python course a million years ago and the rust started to slowly chip away from the memory files....remembered there was a trick on changing strings to integers--seriously had to look it up, though! I'm going through your Arduino class, too, and thoroughly enjoy both! Planning on the Raspberry Pi class, afterwards. Wish I would have had someone like you teaching me back in the 80's, but, at least I'm plugging away at it now--never too late, right?
I almost got stuck on the same thing! After each input request I changed the string input to an integer by modifying it with "x_as_integer = int(x)" for example.
Same here, almost forgot how to do it!
I love your videos Paul! As a newbie programmer, your approach and your style is very beginner friendly and VERY enjoyable to watch. I wouldn’t mind listening to you for hours! Thanks for the great content!
Awesome, thank you!
Thank you Paul... I’m still learning at 72. My Arduino robot car is running fine, but this Python programming is much easier! Boom!
Great to hear!
Glad I'm not the only old fart trying to learn something new. Gotta keep that brain active!
the fact is you're a great professor, I'm realy proud of you, thanks for everything and everythink
Great Lesson and yes, I did the homework for the next lesson, I am so glad you enforce good punctuation because not doing so makes things look unprofessional when it comes to print statements. If my students go on to create programs and then try to market those programs, no one will take them seriously if their work looks sloppy. Not using good punctuation also leads to the development of bad habits. As I tell my students, "it is much easier to develop a good habit than it is to break a bad habit." Thanks for another great lesson that will be passed on to my students!
7:54 You can disable the annoying prompt under Options -> Configure IDLE -> Shell/Ed
Outstanding lesson, as expected Paul. I did the homework and, I have to admit, I had to think back to your Arduino lessons and consider variable types to complete this assignment. It took a little trial and error but I figured it out. Thanks again!
Thanks Paul, I did the Homework and it took me a while to figure out how to add the numbers instead of concatenating them but it all works fine now.
Homework done. Got slipped up there for a bit until I understood how “input” works. Now it’s perfect!
Which was sort of the whole point of the lesson. Little surprise in there, huh?
@@paulmcwhorter I was surprised as well when I first ran the code. :)
Ok, I'm a little proud of figuring out how to add operators to the question to get it to prompt and then use if else statements. Thanks Paul!
You are the best! Boom! did the homework by myself, I'm so happy :) Thank you, Paul!!
In reference to 12:00, I was able to remove the extra space after the comma after by formatting properly.
n=input('Please enter your desired username: ')
w='welcome to the Kingdom'
print('Hello, {0}, {1}!'.format(n,w))
Really appreciate the effort you put into these videos. So resourceful and digestible. Much appreciated.
Glad you like them!
Thanks!
Wow, appreciate that!
The best teacher ever
A great lesson as always Paul
Your teaching is amazing. Love you a lot.
Great Job Sir! I was always a hardware engineer. I am learning this programming for my model railroad hobby using the arduino for the interface.
My idle shell took the input as strings so it put the two numbers back to back when I added them so I changed input to int(input(------------------)). Found this today, really enjoy lessons so far.
You are awesome. I am learning Arduino from You.. I am 52..
Youngster
@@paulmcwhorter Definitely. You and me both...
I just finished the Arduino series and I am pushing 60.
Thank you for the outstanding lessons! Your lessons have been so helpful and I greatly appreciate your time in making these videos and sharing with everyone.
Glad you like them!
Thanks Mr Paul for such great lessons!
Glad you like them!
Mr. Paul you are a great professor and a great person. Im so glad meeting you through these lessons. Please come to my University(University of West Attica,Athens) and give us an excellent lecture with your great teaching method.
I got the homework done Paul, Kuddos ! 👍👍
Your videos have been great help in helping me with this project this is just something that I'm trying to overcome I want to move 180 on the X axis but I don't want it to return when I put the joystick to center
Hello, Paul! Doing the homework, I wasn't getting the desired result but I went to search for the way to get the inputs as integer or float numbers and then I got the desired result. :D Cheers!
First_umber = int(input( 'please input your first number '))
Second_number = int(input( ' please input your second number '))
Number = first_number + second_number
Hello Sir, you was wondering on 08:30 what happened there. Here what happened: as you printed Hello World before, you was very excited, and you made a selection in the Shell - you selected ello World. Well, when you select something in the shell, and then you press on Enter, the selection will be repeated - so after you typed the number 7, you pressed the enter button, and as the selection above was still there, after the 7 there was ello World pasted...
You are doing a great job, and I follow your videos. Greetings from Germany
Thank you very much for an amazing lesson. Struggled with the assignment, but completed it nevertheless!
Excellent!
When you add values it may be better to declarer them as the type "INT"
thank you. you are a very good teacher
if the 'ok' button annoy you after press 'run module'. Than go to 'option' > 'configure IDLE' > 'General' > in the middle of the page 'At start of Run (F5)' section press 'No prompt'. than press 'apply' than 'ok' to solve the annoy thing
Hi Paul, I just jumped in at lesson 3, and I really enjoyed it... I think I'm going to learn python, so I am going to go back to lesson 1. Thanks for sharing your knowledge with us 😊
Have fun!
Thanks a lot Paul. Good teaching!
My pleasure!
Thanks for the lesson, I am requesting if you have PDF link on each lesson so we can download. It really helps a lot.
I love PythonLand, I love it uuuuh lot!
Thank you so much for sharing your knowledge!
My pleasure!
Home work done! And discovered two ways to accomplish the 'trick' without all the giveaways I now see were posted earlier.
Shame on you folks for giving up the secret! :-)
Amazing 🤩, thank you again Paul
Seemed a short lesson, However very good, I see what you was up to. Got the work done eventually lol nice one
Yep, you see now the main point of the lesson. Little surprise in there
Thank you for your efforts sir!
I'm learning a lot about python. Thank you very much.
Glad to hear that!
Thanks for the exceptional tutorial!
You're very welcome!
Great lesson Paul.
Is there a place where we can see what outputs command prompts give? I was about pulling my hair out before I found out that 'input' always returns a string. Finding the 'int' command was another rabbit hole.😂
Enter your first number: 29
Enter your second number: 28
The total for the 1st number which is 29 and the 2nd number which is 28 is 57
Great class!
I don't mean to be picky, but you seem to ignore formatting here. There is a double space between 'Hello' and 'Paul' and a double space between 'Paul' and the comma. Love your lessons!!
Try deleting the space after the Hello and instead of a comma after name, use a + and a comma “Hello”,name+’ ,’ , ‘Welcome to Python Land!’
after some searching :
please input your first number: 5
please enter your second number: 6
your numbers add up to 5 + 6 = 11
OK, so when I typed in the below, it seems as though python is treating my inputs like strings instead of numbers. In the video examples, the only items that were added together were statically set prior to adding them and printing the result. Pretty sure there's a way to tell python how to treat things, but I don't think Paul has gone over them yet.
x=input('Please input your first number:')
y=input('Please input your second number:')
z=x+y
print('The result of', x, '+', y, 'is: ',z)
I figured it out, more tricky then I thought.
Ha! I do things for a reason. I think a very important lesson was learned on assuming you will get a certain type of variable.
Great lesson.
Thanks! 😃
Thank you Paul..
10:33 love it
Great lesson ... Thank you!
Just curious ... Why does it add a space before and after a string?
For example, you typed (I'll type an underscore to represent spaces) "print('Hello_',_name,_'_Welcome to Python Land!')
And it returned "Hello__Paul_,_Welcome to Python Land!" Is there a way to make those extra spaces go away? Is there something besides a comma that could be used, perhaps a semi-colon that wouldn't leave those extra spaces before and after the variable?
Thanks again! As always ... Have a better day!
just dont type in the spaces, python automatically adds a space where it sees a comma.
thank you:) i wish you were my python teacher in clg
Black decaf with sweetner ;-) But all jokes aside thank you for all your great tuts.
Python controlling machines 🤩
Did exactly like you said and....:) Thanks Paul for another great lesson with homework, I just have to figure out why 4+5=45.....
Houston, we have a problem!
@@paulmcwhorter Got it :) Have a great week.
Same, did you find the problem?
@@joe-ed6gs Yes, after the input lines I added, x=int(x), the keyboard must be inputting a string value, we'll see next Wednesday.
I've missed the homework. Thanks, Paul
I am in outing 2 numbers, x and y. Then coding z=x+y. If x=55 and y=66, z prints as 5566. Looks like a variable issue. Since I’m going through the AI lessons as well, I am running ver. 3.9.6. If that matters.
And you are not the first one to find this. Watch the next lesson my friend.
Oh, i found a problem - input got string instead of number
so i had to cover int(input()) and it worked fine.
Cool .... Thanks
This is very lovely.
So I'm hoping there is a line that I can put somewhere in my program to stop it from doing that I am using the program that you wrote out in series 33
Nasty, I tried this and found that it just printed out my numbers as a strin so 4+8 came back as =48
I looked and input Always returns a string, so i converted them to an int using
x = int(input("Please enter your first number "))
this gave me the result i needed.
I love you sir.. Python rock.
Thank you!
Paul can we expect any more videos for the AI on the Jetson Nano series??? It was great, btw.
I probably need to redo that series. The lessons were made on jetpack 4.2 and we are up to 4.5 now
@@paulmcwhorter Hey Paul, you have made great series of Arduino, Arduino with Python too. Can you please make a series on MicroPython? It will be great.
Yes MicroPython!!!!
Actually that is why I'm taking the Python Course.
I feel the MicroPython guys are assuming you already know how the syntax works.
Even the documentation seams to think that too.
I wasn't getting very far other than just copying the examples.
MicroPython will be very useful for the small processors for a tinkerer like me.
I grew up on interpreters like Basic and forth, both of which allow direct pin manipulation on small pieces of code. Just like Python does.
redrok
Thank you sir 🙏
All the best
Hi Paul how are you doing I am trying to program servo motors for a robot arm I'm using a spring loaded joystick an a arduino I would like to know if there is something that I can put in my program to stop the robot from returning to zero when I move the joystick back to center even if there is a time delay I can put in there so if I wanna open up my grippers I would like my grippers to stay open even when the joystick is returned to center
Sir u didn't talk out list in lacture 3
Please brief about list
Hey Paul, I noticed your adds are getting more frequent. I don't have a problem with that but just wondering if you get paid from the add if I click skip? I've been thinking of getting a TH-cam subscription to avoid the adds anyway. If I'm not mistaken, I will not see any adds then.
TH-cam places the ads. I sometimes wonder if they are trying to make them more obnoxious so people will subscribe. Perhaps they would rather have a subscription business model, and not have to deal with advertisers. Just my speculation.
In the Python 3.9.1 Shell I downloaded, there is not an area near the top of the window that contains the "File", "Edit", "Options", "Window", "Help" sections. My shell contains only a window, which means I can't save any of the code. Do you have any ideas for troubleshooting? I have a Windows 10 OS, Asus Vivobook. I went on the Python site and downloaded multiple versions but I am somehow still having the same problem even though I currently have the latest version downloaded. Swift help would be greatly appreciated my friend!
EDIT: Nevermind, I decided to just use Pycharm for the time being
I had to convert the input to numbers before doing any maths , like x = float(input("Please enter first number: "))
Python run code 1 time only from 1st.line to last line of code? can you set it to run repeatlly in loop like Arduino sketch?
you are really fun!
BOOM 7 + 2 = 9 LETS GO
Добрый день. Скажите пожалуйста,а есть исходные тексты к урокам? Спасибо
Sir, should I start watching your aurdino series first or python series ?
The arduino series will make you think in a way that helps when doing the python training but learning them simultaneously is definitely possible too.
I like easy lessons .. LOL .. and easy homework assignments...
Thank you for another great lesson, Sir! Your lessons are not wasted time (#NWT) for me and that is exactly what I want! 👍
Glad to hear that!
Hi Paul, got the homework done eventually thanks to genius giraffe's hint 😜
Excellent!
Love it 😀
I'm glad!
Buum. You are the best!
Finished my homework! See you all next week!
Did it work?
@@paulmcwhorter yes sir!
I just love you ❤
I click "run module" then "ok to save" but nothing happens in the shell
Coming from a C background I feel like I'm skipping lots of steps programming in python. So this is what a high level lang. feels like : )
Yes, Python gives you just enough rope to hang yourself. Things like not declaring variables sets you up for unanticipated problems that can be very difficult to solve. Thinking you are working with an int and learning python has made it a string . . . well, not good. I really like more formal languages.
Looks like Python already adds in spaces for the print function.
Which I actually hate. Better way is to build a sting using '+' concatination function, like this.
myString = 'Hello '+name+', Welcome to Python'
That way, you control the string, then print the string.
I did my homework without seeing comments !
Does Pycharm have this? I can’t find the “new file” tab and when I put “new” and then “file” it doesn’t have that I’m so confused
Okay, I think I figured it out
Your life would be so much easier in this class if you would use the same IDE as me. As we get into the different versions and virtual environments, if you are not familiar with these things you could be in for a struggle.