Presentation is loading. Please wait.

Presentation is loading. Please wait.

PROGRAMMING INFORMATION. PROCEDURES IN PYTHON Procedures can make code shorter, simpler, and easier to write. If you wanted, for example, to use a certain.

Similar presentations


Presentation on theme: "PROGRAMMING INFORMATION. PROCEDURES IN PYTHON Procedures can make code shorter, simpler, and easier to write. If you wanted, for example, to use a certain."— Presentation transcript:

1 PROGRAMMING INFORMATION

2 PROCEDURES IN PYTHON Procedures can make code shorter, simpler, and easier to write. If you wanted, for example, to use a certain part of the code numerous times, it is a quick and efficient way of repeating the codes functionality. A procedure needs a name and the program that needs to be completed. For example: def update_display(): print(“Your score:” + str(score)) time.sleep(1) print("High score: " + str(high_score)) time.sleep(1) print("Lives remaining: " + str(lives)) time.sleep(1)

3 FUNCTIONS IN PYTHON Writing a function is simple. Each function needs a name, values for its calculation, the program for its task, and a value to return. For example, in a dice throwing game you would need: import random def roll_dice(sides): number = random.randint(1,sides) return(number) sides = int(input("How many sides does the dice have?")) throw = roll_dice(sides) print(throw)

4 QUESTIONS What is the difference between a Function and a Procedure? The difference between a function and a procedure is that a function returns a value and a procedure completes a set task with no returning value. What is a constant and why use it instead of a variable? A constant is a item with a set value, that cannot be changed or manipulated but can instead be referenced. This is better in some cases over a variable as it cannot be accidentally changed. What is the purpose of integer division and modulus? Integer division is used to divide one number by another, but always rounds the answer down to the nearest whole number if it has a remainder. Modulus however, returns the remainder left by a division.

5 QUESTIONS CONTINUED When should you use a counter controlled loop or a condition controlled loop? A counter controlled loop is a loop that repeats itself for a certain amount of times. It will, for example, loop when the counter is between 1 and 5, and then stop. However, a condition controlled loop loops when a condition is met, for example when a variable is false. Somewhere in the loop it could change to false, thus breaking the loop. What is the difference between Do…While and While…Do? The difference between these is the minimum number of iterations. Where Do…While has to iterate once before it checks the condition for the while, the While…Do checks for a condition before it iterates, thus making its minimum iterations zero.

6 MORE QUESTIONS….. What is the difference between Declaring and Assigning a Variable? Declaring a Variable is when a certain datatype is declared for the variable, such as a string, Boolean, or an integer. Assigning a Variable is when a value is actually given to the Declared Variable. What is incrementing a variable? Incrementing a variable is when you change a variable by adding something to itself. For example: Age = Age + 1 What is a flag? A Flag is a value that is Boolean, with only two possible values. For example, True or False. The value will have a chance to change during the code, possibly if a condition is met.


Download ppt "PROGRAMMING INFORMATION. PROCEDURES IN PYTHON Procedures can make code shorter, simpler, and easier to write. If you wanted, for example, to use a certain."

Similar presentations


Ads by Google