You must first complete Integrating With NeoPixel before viewing this Lesson

Taking User Inputs

Introduction

Now that we’ve learned how to work with sending outputs to the buzzer and the neopixel, we will now learn how to take inputs in order for us to control those outputs. We’ll begin with something simple: by taking the text a user types and adding a simple response!

Components Needed

  • Little Python Brain
  • A tablet/phone/laptop
Steps

1

The User_Input block

From the Inputs category, this is the User_Input block. It’s comprised of the variable and the prompt.

  • Variable – this is where we “store” the input from the user
  • Prompt  – this is the message that the user sees before he types his input.

This might be a bit complicated to take in at first but by putting it into practice, you will see that it’s way simpler than it sounds!

2

Jumping right into it

There’s no better way to understand this block than to go ahead and use it. Simply copy the blocks shown then save the code as coderslightswitch then run it!

Breaking it down

Let’s quickly sum up how that works

  1. The name that the user inputs is stored in the “name” variable.
  2. Printing this variable will simply print out what’s stored inside

However, it’s a bit weird to simply print out the user’s input without any context at all. Hence, let’s do just that!

3

Adding context to the print block

Now, we’ll combine the variable with some more text of our own to add more context to the statement. Simply add “Hello, ” + name to your print block and run it. Take note to include the apostrophes (indicates that an object is a string) and the plus sign (which combines two different strings).

Run the code!

The Complete Code

Back to: Beginner > Coder's Light Switch

CONTACT US

    Log in with your credentials

    or    

    Forgot your details?

    Create Account