














Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!















integer division remainder division
Topic: PROGRAMMING Title: Programming Fundamentals – 1c Challenge Date: 27 June 2025 Objectives : (^) Understand and use data types: integer, real, Boolean, character and string (^) Declare and use constants and variables (^) Use input, output and assignment statements (^) Use arithmetic operators including MOD and DIV (^) Use string handling and conversion functions
Good programming habits : (^) Document your data! (#) (^) Use naming conventions for variables (e.g. camel case, meaningful etc.)* Constants in capitals (^) Indenting*
Constant const PI = 3. Inputs firstName = input("What is your name? ") Integer division weeks = 31 DIV 7 Remainder division daysLeft = 31 MOD 7
String handling functions Function Example Result str.length word = "Algorithm" print(word.length) 9 str.substring(start, end) print(word.substring(3,6)) "orit" str.left(n) Print(word.left(3)) "Alg" str.right(n) Print(word.right(4)) "ithm" Remember : strings and arrays start their index at 0
Sequence The statements are executed one by one in the order they are written: mark1 = 78 mark2 = 67 total = mark1 + mark average = total / 2 print(average)
greater than < less than
Boolean expressions evaluate to being either true or false. A single = is used for assignment - e.g. age = 14 Comparison operators Meaning Pseudocode example Result Notes == Equal to 5 == 5 True Some languages use a single = != Not equal to 5 != 5 False Visual Basic uses <>
Greater than 5 > 5 False = Greater than or equal to 5 >= 5 True < Less than 5 < 5 False <= Less than or equal to 5 <= 5 True
Nested if statements
Mark1 Mark2 Condition True or False? 80 67 (mark1 >= 80) AND (mark2 >= 80) False 82 80 (mark1 >= 80) OR (mark2 >= 80) True 35 (mark1 > 30) OR (mark1 < 50) True 65 (mark1 < 30) OR (mark1 > 80) False 0 75 NOT(mark1 > 50) AND (mark2 > 50) True 65 85 NOT(mark1 < 60) AND NOT (mark2 <
True
The switch/case statement This statement may be used when a selection is to be made from several alternatives, for example when choosing from a menu switch menuChoice: case "1": print("You selected 1") case "2": print("You selected 2") case "3": print("You selected 3") default: print("This is not a valid choice") endswitch
Random numbers How could you simulate the throw of a die?