How to use the
Learning Portal

Learning Portal

Our hands-on, comprehensive lesson plans span a range of levels. Browse our free STEM and coding learning resources.

Marty Image

3.7 Validating user input

45 Minutes

Lesson Overview

After incorporating if statements into their chatbots, students now have programs that are more responsive based on what the user has typed in. We can use this input to decide what actions Marty should do but also to set the parameters for these moves. It’s important that we check that the values that have been entered are sensible and we need logical operators to do this.

Key vocabulary:
    Decision Making, Chatbot, If Statements, Logical Operators, Validation, User Input,

Content Sections

  • Learning Objectives
  • Extensions & Challenges
    • Additional Reading
    • 3.7 Validating user input

      45 Minutes

      Lesson Overview

      After incorporating if statements into their chatbots, students now have programs that are more responsive based on what the user has typed in. We can use this input to decide what actions Marty should do but also to set the parameters for these moves. It’s important that we check that the values that have been entered are sensible and we need logical operators to do this.

      Key vocabulary:
        Decision Making, Chatbot, If Statements, Logical Operators, Validation, User Input,
      • 3.1-3.6
      • Laptop or PC
      • Technologies/Literacy/Numeracy
        • Marty the Robot
        • Student workbooks (Lesson 3)
        • Devices with a Python editor and martypy installed

      Learning Objectives

      • Describe when you might use logical operators
      • Use sequence, variables, if statements and logical operators to create a chatbot that is responsive to and validates the user input
      • Explore what real-world systems might incorporate validating user input and why

      1.Recap on what the students were working on last time and reflect on their chatbots

      a. What did you add to your chatbot last lesson?

      b. What is your favourite part about your chatbot?

      c. Do you allow the user to set any values for Marty movements? (number of steps or circle dance timing)

      2. Discussion of why we need to validate user input on different systems - can students think of any examples?

      3. Demonstration of how we can do this using logical operators

      4. Students should explore logical operators by considering when each should be used in workbook examples

      5. Extend the chatbot to ask the user for values to use for Marty movements that get validated using a combination of if statements and logical operators

      Extensions & Support

      • When the user enters a value that doesn’t pass the validation check, let the user know why it has failed and give them another chance to re-enter (Technologies/Literacy/Numeracy)
      • At the start, could the user type in the name of the Marty they would like to speak to and, using this information along with the discover method, connect to that Marty? (Technologies/Literacy/Numeracy)

      Additional Reading

      • Marty the Robot Educator Guide
      • Educator FAQ
      • Getting Started with Python
      • MartyPy Documentation