Python For Kids (Part 14: I/O)

Python For Kids (Part 14: I/O)

For a complete table of contents of all the lessons please click below as it will give you a brief of each lesson in addition to the topics it will cover. https://github.com/mytechnotalent/Python-For-Kids

Now that we are comfortable with the Mu IDE we can work directly with the steps without the pictures as we will be building larger and larger apps. If you have any questions about any of the steps I would look at any of the prior 13 lessons and see exactly how the pictures match up with the steps to help you along or ask a question in the main repo on GitHub by clicking on issues. These steps are illustrated in lesson 11 so we are always here to help you on your journey!

Today we will work with console input and output. This is a simple way we can type information into a variable and do things with it. To keep it simple we will work with a simple name example.

STEP 1: Open Mu IDE

STEP 2: Type Code

name = input('Tell Me Your Name: ')
print(f'Hi {name}!') 

STEP 3: Click Save

STEP 4: Save File - main.py - Desktop

STEP 5: Click Run

STEP 6: Type Info In REPL

Tell Me Your Name: 


You will see the above prompt so now all we have to do is type our name inside the REPL and press enter.

Tell Me Your Name: Kevin
Hi Kevin!
>>>

STEP 7: WITNESS OUR NEW INPUT PROGRAM!

You will now see we taught the computer to ask a question and then we responded and then saw the computer do something with what we typed. Think of all of the FUN things we can do now with this new knowledge!

The area of code where we saw the word name represents a variable in our case a str or string variable meaning it holds letters or text.

To format the way our computer responds to us we use what we refer to as an f string or format string in Python. We start off with the f an then inside the f('text {variable}') we are able to mix our own messages or text with variables to make them very easy to deal with.

HOMEWORK:

I want you to go back to the program and type in something other than name and then click save and run enter some information in the REPL.

You can try things like having the computer ask for your age or favorite food or anything you like. What is important is that you try new things so we can really build your understand so please take some time and change the name variable to something else and change your question and click save then run and see the results!

In the next lesson we debug our program.

I like the open ended questions at the end.

回复

要查看或添加评论,请登录

Kevin Thomas的更多文章

社区洞察

其他会员也浏览了