ALGORITHM HELP STEP ONE INPUT DEFINITION allow you

  • Slides: 1
Download presentation
ALGORITHM HELP STEP ONE - INPUT DEFINITION : allow you to compare values to

ALGORITHM HELP STEP ONE - INPUT DEFINITION : allow you to compare values to check if a condition is met/true. STEP TWO - PROCESS STEP THREE - OUTPUT INDENT IMPORTANT Note that when you are checking if something is equal to something, == is used during ASSIGNMENT Others COMPARISON OPERATORS include: != not equal < less than > Greater than >= greater than or equal to <= less than or equal to If statement structure: if a == 0 : print(“the number needs to be greater than 0”) else if a >= 0: else: STEP ONE: LOOK AT THE QUESTION. IT WILL HAVE MADE IT CLEAR WHAT YOUR INPUTS ARE. STRUCTURE YOUR INPUTS LIKE THIS OUTPUT (“What is your name? ”) INPUT name OR name = input(“What is your name”) (if it’s an integer (whole num) or float number (decimal num), make this clear. e. g. age = int(input(“What is your age? ”)) STEP TWO: Are there any variables/constants that need to be declared? WHAT DOES THE ALGORITHM ACTUALLY NEED TO DO WITH THE VALUES/VARIABLES? ARE THERE ANY CALCULATUIONS THAT NEED TO HAPPEN? Are there any decisions/selection (if statements) that need to occur? Is there any iteration / loop (for loop or a while loop) that needs to happen? When/What needs iteration? The variable needs to go first, this is called assignment. You are assigning a value to a variable. Keep your variable names consistent. Be careful with your use of capital letters. Declaring a variable means to set/initialise a variable that isn’t an input but needs to be used/potentially changed in the program. I. e. variables in a program that need to changed later on but are not inputs. E. g. score So at the beginning of the program you would do this by Score = 0 print(“this number is negative”) Does the question tell many how many times it wants you to loop? If so, use a for loop. Does the program want you to loop until a condition is met? Use a while loop. What is the INDENT condition? That would go after IMPORTANT the word while. What does it want you to loop? That would be indented underneath the while condition. WHILE LOOP STRUCTURE While a >0 OR name != “Ann”: do something! FOR LOOP STRUCURE For i in range (5): do something Concatenation – joining of variables and/or strings e. g. (“Well done, your final score is ” , score) This , is used for concatenation here STEP THREE: Read the question again. What variables need to be output? Does a string also need to be output with this. Remember concatenation if so. OUTPUT name Or print(name) VARIABLE – a value with an identifier in a program that COULD change when the program is running (not will, e. g. score could remain at 0) CONSTANT – a value in a program that is initialised and CANNOT be changed when the program is running.