Computing Science Department Douglas Academy Software Design and Development Computational Thinking Learning Outcome 1 Name: Version 4 Task 1: The PRINT command 1. Explain the purpose of the PRINT command in a True Basic program. Example Question Explain the purpose of the following code. Line 1 PRINT “Douglas Academy” Line 2 PRINT “Craigton Road” Line 3 PRINT “Milngavie” Line 4 PRINT “Glasgow” Line 5 PRINT “G62 7HS” Line 6 END Answer This program will display the following text on the screen. Douglas Academy Craigton Road Milngavie Glasgow G62 7HS Douglas Academy Computing Science Dept Computational Thinking Booklet V4 2 SDD Unit 2. Explain the purpose of the following code. Line 1 PRINT “Hello world” Line 2 PRINT “This is my first computer program!” Line 3 PRINT “I think I am going to love programming” Line 4 END Answer Douglas Academy Computing Science Dept Computational Thinking Booklet V4 3 SDD Unit Task 2: The INPUT command 1. Explain the purpose of the INPUT command in a True Basic program. Example Question Explain the purpose of the following code. Line 1 PRINT “Please enter your name” Line 2 INPUT name$ Line 3 PRINT “Hello”;name$ Line 4 PRINT “Welcome to Computing Science” Line 5 END Answer This program will ask the user for their name and then display their name in a welcome message. Douglas Academy Computing Science Dept Computational Thinking Booklet V4 4 SDD Unit 2. Explain the purpose of the following code. Line 1 PRINT “Please enter your favourite country” Line 2 INPUT country$ Line 3 PRINT “I know” Line 4 PRINT country$ Line 5 PRINT “It is a beautiful place to visit” Line 5 END Answer Douglas Academy Computing Science Dept Computational Thinking Booklet V4 5 SDD Unit Task 3: Variables In True Basic data is stored in variables. Data can be numbers or text. If numbers are being stored these are known as either Integer variables, if it a whole number e.g. 1, 2, 3, or Real variables, if the number has a decimal point e.g. 1.1, 2.2, 3.3. If text is being stored it is known as a String variable. If text is being stored then the String variable name ends with a dollar ($) sign. Look at the following code Line 1 PRINT “Please enter your name.” Line 2 INPUT name$ Line 3 Print “Please enter your age.” Line 4 Input age Line 5 END Choose from the following options the type of data that will be stored in the variable name$ in line 2. A. Integer, B. Real, C. String Choose from the following options the type of data that will be stored in the variable age in line 4? Douglas Academy Computing Science Dept Computational Thinking Booklet V4 6 SDD Unit A. Real, B. Integer, C. String Task 4: String variables and the LET command 1. Explain the purpose of the LET command in a True Basic program. 2. Read the following lines of True Basic and describe what each line does. The first one has been completed for you. LET day$ = “Tuesday” Answer This will assign the value Tuesday to the string variable day$ LET team$ = “Partick Thistle” Answer LET month$ = “December” Answer Douglas Academy Computing Science Dept Computational Thinking Booklet V4 7 SDD Unit Task 5: Numeric Variables 1 Read the following lines of True Basic and describe what each line does. 1) LET wage = hours_worked * rate_of_pay Answer This will multiply the value of hours_worked by the value of rate_of_pay and assign the result to the numeric variable wage. 2) LET sum = first_num + second_num Answer 3) LET years = months / 12 Answer Douglas Academy Computing Science Dept Computational Thinking Booklet V4 8 SDD Unit Task 6: The FOR ....NEXT construct 1. Explain the purpose of the FOR... NEXT construct. Example Question Look at the lines of code below and describe the purpose of the FOR ... NEXT construct on lines 1 and 7. Line 1 FOR counter = 1 to 5 Line 2 PRINT “Please enter the pupil’s name” Line 3 INPUT pupil$ Line 4 PRINT “Please enter the pupil’s mark” Line 5 INPUT mark Line 6 PRINT pupil$; “ “;mark Line 7 NEXT counter Answer The FOR ..NEXT construct repeats 5 times. This means the code between lines 2 and 6 will be repeated 5 times. Douglas Academy Computing Science Dept Computational Thinking Booklet V4 9 SDD Unit 2. Look at the lines of code below and describe the purpose of the FOR ... NEXT construct in lines 1 and 6. Line 1 FOR counter = 1 TO 10 Line 2 PRINT “Enter name of the item” Line 3 INPUT item$ Line 4 PRINT “Enter the cost of the item.” Line 5 INPUT item_cost Line 6 NEXT counter Answer 3. Choose from the following options the type of data that will be stored in the variable item_cost in line 5? A. Real, B. Integer, C. String Douglas Academy Computing Science Dept Computational Thinking Booklet V4 10 SDD Unit 3. The code is extended to add another two lines. Explain what the new two lines will do. Line 1 FOR counter = 1 TO 10 Line 2 PRINT “Enter name of the item” Line 3 INPUT item$ Line 4 PRINT “Enter the cost of the item” Line 5 INPUT item_cost Line 6 LET total = total + item_cost Line 7 NEXT counter Line 8 PRINT “Your total cost is “ ; total Line 6: Line 8: Douglas Academy Computing Science Dept Computational Thinking Booklet V4 11 SDD Unit Task 7: The IF…. THEN … END IF statement 1. Explain the purpose of the IF ... THEN .... END IF construct. Example Question Look at the lines of code below and describe the purpose of the IF .. THEN...END IF construct. Line 1 Line 2 Line 3 IF points_scored > 1000 THEN PRINT “Congratulations you are on the leader board” END IF Answer If the value of the numeric variable ‘points_scored’ is greater than 1000 then the message in line 2 will be displayed Douglas Academy Computing Science Dept Computational Thinking Booklet V4 12 SDD Unit 2. Look at the lines of code below and describe the purpose of the IF .. THEN...END IF construct. Line 1 IF mark>= 50 THEN Line 2 Line 3 PRINT “Well done, you’ve passed” END IF Answer 3. Look at the lines of code below and describe the purpose of the IF .. THEN... ELSE construct. Line 1 IF password$=correct_password$ THEN Line 2 Line 3 PRINT “Login successful” ELSE Line 4 PRINT “Incorrect password.” Line 5 PRINT ”Please try logging in again” Line 6 END IF Answer Douglas Academy Computing Science Dept Computational Thinking Booklet V4 13 SDD Unit Task 8: The DO.. LOOP UNTIL construct 1. Explain the purpose of the DO.. LOOP UNTIL construct. Example Question Look at the lines of code below and describe the purpose of the DO ... LOOP UNTIL construct. Line Line Line Line 1 2 3 4 DO PRINT “What is the capital of Scotland?” INPUT answer$ LOOP UNTIL answer$= “Edinburgh” Answer The DO .. LOOP UNTIL will keep repeating the instructions on lines 2 and 3 until the user enters “Edinburgh” as the value for the string variable ‘answer$’. Douglas Academy Computing Science Dept Computational Thinking Booklet V4 14 SDD Unit 2. Look at the lines of code below and describe the purpose of the DO ... LOOP UNTIL construct. Please note that <> means not equal to. Line Line Line Line Line Line Line 1 2 3 4 5 6 7 DO PRINT “Enter your password” INPUT password$ IF password$ <> “top secret” THEN PRINT “Incorrect password. Please try again” END IF LOOP UNTIL password$=”top secret” Answer Douglas Academy Computing Science Dept Computational Thinking Booklet V4 15 SDD Unit Task 9: Bringing it all together 1. Look at the code below Line 1 PRINT “Please enter the number of tickets you require” Line 2 INPUT number_of_tickets Line 3 FOR counter = 1 TO number_of_tickets Line 4 PRINT “Enter name of band” Line 5 INPUT band_name$ Line 6 PRINT “Enter the ticket cost in pounds and pence” Line 7 INPUT ticket_cost Line 8 LET total_cost = total_cost + ticket_cost Line 9 NEXT counter Line 10 PRINT “The cost of your tickets is “; total_cost Line 11 END Douglas Academy Computing Science Dept Computational Thinking Booklet V4 16 SDD Unit Questions 1. Explain the purpose of the code. 2. Choose from the following options the type of data that will be stored in the variable band_name$ in line 5. A. Integer, B. Real, C. String 3. Choose from the following options the type of data that will be stored in the variable ticket_cost in line 7. A. Integer, B. Real, C. String 4. Describe the purpose of the FOR ... NEXT construct in lines 3 – 9. 5. Describe how the value of the numeric variable ‘total_cost’ is calculated in line 8. Douglas Academy Computing Science Dept Computational Thinking Booklet V4 17 SDD Unit 2 Look at the code below Line 1 LET correct$=“douglas” Line 2 DO Line 3 PRINT “Please enter your password” Line 4 INPUT password$ Line 5 IF password$ <> correct$ THEN Line 6 PRINT “Sorry wrong password.” Line 7 END IF Line 8 LOOP UNTIL password$ = correct$ Line 9 PRINT “Access granted” Line 10 END Douglas Academy Computing Science Dept Computational Thinking Booklet V4 18 SDD Unit Questions 1. Explain what happens when you run the code. 2. Describe the purpose of the expression in Line 1. 3. Describe the purpose of the IF... THEN...END IF construct in lines 5 to 7. 4. Describe the purpose of the DO.. LOOP UNTIL in lines 2 to 8. Douglas Academy Computing Science Dept Computational Thinking Booklet V4 19 SDD Unit
© Copyright 2024 Paperzz