2 - Inputs and Outputs
The concept of inputs and outputs is a big one. But at the basic level we can think of input as taking information from the user of your program and output as the computer returning information to the user.
You need to tell your program when it should give information back to the user. What does it look like when the program gives information back to the user? This could be something simple like just writing a message like “Hello User” on the screen. It could also be things like showing your WeChat avatar photo on your profile page or making your video game character move across the screen. For our first programs we will output text onto the screen.
How do you tell your program to write (or output) a message to the user?
print("Smiley face party ;) :-) :-D")
It is important that you follow the same syntax as is shown above. You need to have the message that you want to write on the screen wrapped in “quotation marks” and (brackets).
2.1 - You try!
Does it give you an error message? Does the message contain any useful
information for helping you find the problem? Fix it!
There are all kinds of information that we might want to get from the user. For example, maybe you want to ask the user what their name is or what their favourite ice cream flavour is. But the same applies to more complicated cases, like when you are playing a video game and you want to tell the computer to make your character jump. These are all examples of inputs.
So how do we get these inputs from the user?
input("What is your name?")
input("What is your favourite ice cream flavour?")
Try running the code above. What happens? You should have noticed that the program will sit and wait until the user (that is you!) enters their name. Then it will ask them for their favourite ice cream flavour and it will again wait until they have entered this. It is not until the program has received both of these inputs from the user that the program will finish.
2.2 - You try!
Does it give you an error message? What do you think the problem is with my
code? Fix it!
*Note: In this section I’ve asked you to enter code that gives you an error message. We call mistakes or errors in our code bugs. The process of trying to find errors or mistakes in code is called debugging. So far all the bugs that we have found are from typos or syntax errors (not following Python’s rules properly). As we learn more we will see that there are other types of bugs.