SMALL BASIC TO PYTHON CPD TRAINING CAS CPD. SCHEDULE 15:15 Refreshments 15:30 - 15:45 Introduction 15:45 - 16:45 Small Basic 16:45 - 18:00 Python Workshop.

Slides:



Advertisements
Similar presentations
EasyGUI “Probably the Easiest GUI in the world”. Assumptions (Teachers’ Notes) This resources sets out an introduction to using easyGUI and Python
Advertisements

P1PMF Split1 QBASIC. P1PMF Split2QBasic Command Prompt Will launch the emulator DOS operating system? Press Alt + Enter to display the widescreen.
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Variables –recap-python
Introduction to a Programming Environment
Do Now Noticing skills What does input do?. Annotate your code to explain what happens name = input( “What is your name?\n” ) print(“Hello ”, name) Extension-Python.
Visual Basic Chapter 1 Mr. Wangler.
An Introduction to Textual Programming
Introduction to Python
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #002 (January 17, 2015)
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Input, Output, and Processing
By the end of this session you should be able to...
Agenda Review C++ Library Functions Review User Input Making your own functions Exam #1 Next Week Reading: Chapter 3.
Conditions. Objectives  Understanding what altering the flow of control does on programs and being able to apply thee to design code  Look at why indentation.
Fundamental Programming: Fundamental Programming Introduction to C++
30/10/ Iteration Loops Do While (condition is true) … Loop.
Lesson 4 Using Variables in Python – Creating a Simple ChatBot Program.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Fill the screen challenge! This is a starter activity and should take 3 minutes [ slide 1 ] 1.Log in to your computer 2.Open IDLE 3.In interactive mode,
Variables When programming it is often necessary to store a value for use later on in the program. A variable is a label given to a location in memory.
PROGRAMMING In Lesson 2. STARTER ACTIVITY Complete the starter activity in your python folder – lesson 2 Now we will see how you got on and update your.
Data Types and Variables. Data Type! Computers are all about Data! Data can be in the form of Text Dates Sounds Pictures.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #001 (January 17, 2015)
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
Introduction to Python Lesson 1 First Program. Learning Outcomes In this lesson the student will: 1.Learn some important facts about PC’s 2.Learn how.
1 CS105 Discussion 5 – Variables and If Announcements MP 1 due on Monday Midterm 1 on Tuesday If you need a conflict, request it NOW!!
Introduction Chapter 1 8/31 & 9/1 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
COIT29222 Structured Programming 1 COIT29222-Structured Programming Lecture Week 02  Reading: Textbook(4 th Ed.), Chapter 2 Textbook (6 th Ed.), Chapters.
Python Let’s get started!.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
Lesson 1. Security At the menu bar at the top you will see the word Tools. Click your mouse on Tools scroll down to Macro. Move the Mouse over and down.
Variables and Strings. Variables  When we are writing programs, we will frequently have to remember a value for later use  We will want to give this.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
Introduction Chapter 1 1/22/16. Check zyBooks Completion Click on the boxes for each section.
PHP Form Processing * referenced from
Algorithms and Pseudocode
GCSE Computing: Programming GCSE Programming Remembering Python.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #003 (February 14, 2015)
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Getting Started With Python Brendan Routledge
Introducing Python 3 Introduction to Python. Introduction to Python L1 Introducing Python 3 Learning Objectives Know what Python is and some of the applications.
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
GCSE COMPUTER SCIENCE Practical Programming using Python Lesson 4 - Selection.
GCSE COMPUTER SCIENCE Practical Programming using Python
Lesson 1 - Sequencing.
Week 4 Computer Programming Gray , Calibri 24
Variables, Expressions, and IO
Lesson 1 Learning Objectives
Learning to Program in Python
Fill the screen challenge!
Week 5 Computer Programming Gray , Calibri 24
Learning to Program in Python
Algorithms & Pseudocode
Week 2 Computer Programming Learning Objective:
Escape sequences: Practice using the escape sequences on the code below to see what happens. Try this next code to help you understand the last two sequences.
Week 5 Computer Programming Year 9 – Unit 9.04
Introduction to TouchDevelop
Hello World! Syntax.
Week 4 Computer Programming Year 9 – Unit 9.04
GCSE Computing Lesson 6.
Starter answer these questions in your book
Introduction to Python
Hardware is… Software is…
Presentation transcript:

SMALL BASIC TO PYTHON CPD TRAINING CAS CPD

SCHEDULE 15:15 Refreshments 15: :45 Introduction 15: :45 Small Basic 16: :00 Python Workshop 18: :15 Scheme of Work 18: :30 Networking

INTRODUCTION TO SMALL BASIC Why Small Basic for student One big reason is that it’s free from Microsoft It is specifically designed for programmers who would be described as beginners, but with the benefits of a real coding environment. It provide the gap between Scratch and Python It builds confidence from which you can move onto other, more complex language, big brother Visual Basic There are many built-in elements that make your work simpler and the language itself is very simple

Intelligent Support Another advantage of Small Basic is the fact that it gives you support as you are entering in your code. So as you type, a suggestion is made as to which command or variable you are wanting to use and will fill in for you. It will also give an explanation of what the command does. This means that many of the syntax errors which cause confusion and frustration are avoided. INTRODUCTION TO SMALL BASIC

How to Open Small Basic Start  All Program  Microsoft Small Basic Run the program Execution Mode Area Code Area INTRODUCTION TO SMALL BASIC

Your First Program (Printing) “Hello World”You will open Small Basic and create a program that print “Hello World” As you start typing in small basic will suggest the command for you TextWindow.WriteLine ("Hello World”) INTRODUCTION TO SMALL BASIC

INPUT IN SMALL BASIC Extending to Input We will now extend our program to as for user input The program will print the user input ReadWe use Read command to input TextWindow.WriteLine (“What is your name”) name = TextWindow.Read() TextWindow.Write("Hello " + name ) Try the example below

REVIEWIN ARTIFICIAL INTELLIGENCE FROM USING CHATBOTS To develop a better understanding of some current artificial intelligence technologies, look at some demonstrations below; Hold down Ctrl and click on the link to access the online Chatbot 1.Jabberwacky: Cleverbot: 3.Elbot:

CREATING A SIMPLE AI Creating a Simple Artificial Intelligent (AI) From the example below we can create a simple AI. TextWindow.WriteLine (“What is your name”) name = TextWindow.Read() TextWindow.WriteLine("Hello " + name ) TextWindow.WriteLine (“What is your favourite food?”) food= TextWindow.Read() TextWindow.WriteLine(“Oh " + food + “ is my favorite too" ) Extend the example below to create a simple AI “ or ‘At this stage you should start encouraging students to start commenting on their code by using single or double quotation mark (“ or ‘)

SMALL BASIC (IF FUNCTION) Creating a Simple a simple quiz From the example below we can create a simple quiz. TextWindow.WriteLine (“What is your name”) name = TextWindow.Read() TextWindow.WriteLine (“What is 2 + 2”) answer= TextWindow.Read() If Answer = "4" Then TextWindow.WriteLine ("Well done " + Name) Else TextWindow.WriteLine("That is the wrong answer" + Name + ", the answer was 4") EndIf

A variable is a space in the computer’s memory where we can store data such as a number or text. The value can be changed if required. The box represents the space reserved in the computer’s memory To create a variable and give it the value 45 we write: my_number=45 my_number variable name 45 The variable’s value WHAT IS A VARIABLE

ACTIVITY You can also perform calculations that use a variable numberOne = 3 numberTwo = 4 answer = numberOne + numberTwo TextWindow.WriteLine (answer) score = 112 score = score + 1 TextWindow.WriteLine(score)  You can use a variable in a calculation, and use the same variable to store the answer.  Predict the following code:

SMALL BASIC (ADDING SCORE VARIABLE) Creating a Simple a simple quiz From the example below add a score to your quiz. score = 0 TextWindow.WriteLine (“What is 2 + 2”) answer= TextWindow.Read() If Answer = "4" Then TextWindow.WriteLine ("Well done " + Name) score = score + 1 Else TextWindow.WriteLine("That is the wrong answer" + Name + ", the answer was 4") EndIf TextWindow.WriteLine (“Your score is ” + score)

EXTENDING THE QUIZ One thing that we may wish to do with the quiz would be to allow the user to take the quiz again depending on the feedback. goto To do this, we need to use a label and a goto statement which directs the program to the label. The syntax for the label is labelname: and is positioned at any point in the programme where you would it to restart from. TextWindow.WriteLine("do you want to run again?") answer = textwindow.read() If answer = "y" Then Goto startagain EndIf

GOTO ADDING GOTOActivity Add a “StartAgain” at the to top of your quiz Add the code below GotoGoto statement allow you to start executing at a particular point in your code This is the cheating way of doing loop Answer1 = TextWindow.Read() If Answer1 = "y" Then Goto StartAgain EndIf

ADDING RESPONSIVE FEEDBACKActivity Assuming that you have 5 questions in your quiz, Add a IF function that does the following IF the score is more than 4 THEN Display “Excellent work player name” ELSE IF score is less than 3 THEN Display “Good Work” Else: Display you need more practice and try again We are now going to add a responsive feedback to the quiz base on the score

ADDING RESPONSIVE FEEDBACK Solution If score = 5 Then TextWindow.WriteLine ("Excellent work " + Name + " Your score is: " + score) ElseIf score > 3 Then TextWindow.WriteLine ("Good work " + Name + " Your score is: " + score) Else TextWindow.WriteLine ("Try again " + Name + " Your score is: " + score) TextWindow.WriteLine ("Do you want to try again?") Answer1 = TextWindow.Read() If Answer1 = "y" Then Goto StartAgain EndIf

INTRO TO PYTHON PROGRAMMING CPD

USING THE INTERACTIVE MODE WITH PYTHON Type in the following, exactly as it shown here and then press the return key. print (“Hello World”) The phrase Hello World should appear immediately below the print as shown below >>> print (“Hello World”) Hello World >>>

UNDERSTANDING WHAT SYNTAX ERRORS ARE AND HOW TO AVOID THEM Syntax is used to describe the rules that determine the way that instructions and commands must be written. Python IDE has syntax highlighting which automatically assigns colours to different elements Example the “Hello World” phrase should be green. This should help spot some simple errors when typing in commands.

UNDERSTANDING WHAT SYNTAX ERRORS ARE AND HOW TO AVOID THEM Print in Purple Comment in Red Text in Green

ACTIVITY Predict what will happen with some of the following codes; 1.>>> print"Hello World" 2.>>> print("Hello World"); 3.>>> Print("Hello World") 4.>>> print("Hel World") 5.>>> prin(Hello World) Write your prediction on a sheet of paper Now try them to see what if the response you get matches up with what you predicted.

A variable is a space in the computer’s memory where we can store data such as a number or text. The value can be changed if required. The box represents the space reserved in the computer’s memory To create a variable and give it the value 45 we write: my_number=45 my_number variable name 45 The variable’s value WHAT IS A VARIABLE

CREATING A VARIABLE When we create a variable we call it ‘declaring’ a variable. When we give the variable its first value we call it ‘initialising’ a variable. If we want to tell the computer to ‘Create a variable called “age” and give it the number 12’, we say: age = 12 print (age)

ACTIVITY You can also perform calculations that use a variable numberOne = 3 numberTwo = 4 answer = numberOne + numberTwo print (answer)

INPUT Input allow you to ask the user to input text (String), whole number (Integer ) and decimal (Floating) Examples 1 of Input print (“What your name?” ) name = input () print (“Nice to mee you” + name) Example 2 of Input print (“What your first name?” ) first_name = input () print (“What your surname?” ) surname = input () print (first_name + surname ) # this code ask user to enter their name # Allow the user to enter their name # Output the name entered by the user. # this code ask user to enter first name # Allow the user to enter their first name # this code ask user to enter surname # Allow the user to enter their surname # Output first name and surname entered

BUILDING FIRST PART OF ARTIFICIAL INTELLIGENCE PROGRAM IN PYTHON In this activity, you will create the first part of Artificial Intelligent and save its as AI.py. print(“What is your name?") name = input () print("Nice to meet you " + name)  This three line phrase can be developed into a very simple Artificial Intelligence.  Consider the kinds of questions and information that people ask about each other when they first meet

EXTENDING ARTIFICIAL INTELLIGENCE Notice in the 4th line above it is necessary to have two + signs, one either side of the variable name. Common errors to watch for are Not having a complete pair of double quotation marks Not adding + signs between variables and strings. print("Please type your name in") name = input () print("Nice to meet you " + name) print("So, " + name + ", what is your favourite food?") favourite_food = input () print("Ah, your favourite food is " + favourite_food) Task: Task: Expand on the above code to create your own artificial Intelligence Add a summary at the end e.g. “So, John, I know a lot about you now I know that your favourite food is chicken….

DATA TYPE AND CASTING Casting is the technical term for changing the type of data you are working with. Example casting by saying int() = Integer float() = floating point or decimal str() = String or text to Casting is used to change the data type.

INTEGER We can force Python to make something a whole number by saying int(number). Predict what the following code will do: number = 3.7number = 3.7 newNumber = int(number)newNumber = int(number) print(newNumber)print(newNumber) Now copy the code in python and compare the answer with your prediction Note that this won’t round the number up, it just takes the whole number part.

FLOAT The second main type is a floating point, or just “float” for short (a decimal). We can force Python to make something a float by saying float(number). In group of two, predict what the following code will do: number = 3 print(number) newNumber = float(number) print(newNumber) Now copy the code in python and compare the answer with your prediction

INTEGER CASTING ACTIVITY Python will automatically change the data type for you a lot of the time: In group of two, predict what the following code will do: x = int(22)x = int(22) y = int(7)y = int(7) z = x/yz = x/y print(z)print(z) Now copy the code in python and compare the answer with your prediction Here, the two integers have provided a floating point answer and Python has changed the data type of z for you.

STRING A string is a block of text. “str”In Python we use the term “str” to mean a string. In group of two, predict what the following code will do: number = str(2) print("2 + 2 = ", number + number) Now copy the code in python and compare the answer with your prediction This makes the value “2” into a string - so it is a word rather than a number

IF FUNCTION (SELECTION) Selection means selecting (or choosing) what to do next. Should I cycle to school, or ask for a lift? If it’s a sunny day I might cycle. If it’s raining, I’ll ask for a lift. Answer print (“What is the weather like today?”) answer = input () answer = str(answer) if answer == “sunny”: print(“I might Cycle to school”) else: print(“I’ll ask for a lift.”)

IF....ELIF....ELSE Sometimes there are more than two options. I could walk OR cycle OR get the bus OR get a lift. As well as IF and ELSE, we can stick an ‘ELSE IF’ (or ELIF) in the middle: Write a pseudocode for the following code then try it. print (“What is the weather like today?”) answer = input () answer = str(answer) if answer == “sunny”: print(“I might Cycle to school”) elif answer == “raining”: print(“I get the bus”) else: print(“I’ll ask for a lift.”)

QUIZ Create a new file and type in the following code: print("What is 2 + 2?") answer = input () answer = int(answer) if answer == 4: print("Well done") else: print("Sorry the answer was 4")

ACTIVITY score = 112 score = score + 1 print(score)  You can use a variable in a calculation, and use the same variable to store the answer.  Predict the following code:

ACTIVITY Modify the your game by adding the scores and comments score = 0 print("What is 2 + 2?") answer = input () answer = int(answer) if answer == 4: print("Well done") score = score + 1 else: print("Sorry the answer was 4") #this increases score by one #this defines variable score, and sets it as zero  In group, discuss what the score does and the concept of “score now equals itself plus one”

LIFE CALCULATOR Read the Life Calculator analysis Identify all input, output and process Make a flowchart using the symbols below Arrow

LIFE CALCULATOR The system should enable the user to create a system which will calculate their expected life based on the answer they give. The system needs to ask the user for their age, gender and name. If they are male, their life expectancy will be 78; if they are female they will be 82. If they are a smoker, then they lose 7 years from their lifespan. If they exercise, they gain 6 years, but lose 12 if they don’t. Supporting Manchester United can also have an impact. If they do, the stress can take 5 years off their lives. It would be nice if the there was a validation check to see if age was too high or low when entered. You need to identify the input and output of this system as you design it and think about the question that you will ask.

LIFE CALCULATOR Start INPUT name INPUT age INPUT gender Male or Female? Life EXPT= 78 Life EXPT= 82 M F Smoke? Life EXPT - 7 Y Exercise ? Life EXPT + 6 Life EXPT-6 N Y Man U? Y Life EXPT-5 N INPUT Life EXP End

LIFE CALCULATOR AGE VALIDATION Start Age < 5? Y Age > 100? Y Too Old Too Young N N End INPUT age

LIFE CALCULATOR PYTHON SOLUTION

LIFE CALCULATOR SMALL BASIC

SABOTAGE Open your program Swap seat with a partner Look through your partner program Think of two thing you can do to the program to make it stop working Change or edit your partner code so that the whole program does not work

RESOURCES Go on Login with the following detail Username: Password: computing Survey

CONCLUSION Start simple Always design it on paper first Can just do top level design – no details first Iterate Do it in small basic or Scratch first Recreate it in Python If you get stuck ask: CAS has a Forum – No question too simple, small or stupid Allow students explore different solution and share with their peers and yourself Enjoy!