Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 SMALL BASIC TO PYTHON CPD TRAINING CAS CPD

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

3 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

4 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

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

6 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

7 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

8 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: http://www.jabberwacky.com/ http://www.jabberwacky.com/ 2.Cleverbot: http://www.cleverbot.com/http://www.cleverbot.com/ 3.Elbot: http://www.elbot.com/http://www.elbot.com/

9 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 ‘)

10 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

11 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

12 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:

13 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)

14 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

15 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

16 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

17 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

18 INTRO TO PYTHON PROGRAMMING CPD

19 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 >>>

20 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.

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

22 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.

23 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

24 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)

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

26 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

27 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

28 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….

29 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.

30 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.

31 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

32 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.

33 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

34 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.”)

35 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.”)

36 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")

37 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:

38 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”

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

40 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.

41 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

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

43 LIFE CALCULATOR PYTHON SOLUTION

44

45 LIFE CALCULATOR SMALL BASIC

46

47 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

48 RESOURCES Go on https://www.dropbox.comhttps://www.dropbox.com Login with the following detail Username: ahmad.jalloh@computingatschool.org.ukahmad.jalloh@computingatschool.org.uk Password: computing Survey https://www.surveymonkey.com/s/NOEFirstFeedback

49 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!


Download ppt "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."

Similar presentations


Ads by Google