Programming Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

asking the user to input into a variable

A

age=input (how old are you?”)
print(“You are”,age)
age is the variabe

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

using IF to test a variable

A
if age < 18:
     print("You are a child.")
else:
      print("You are an adult>")
if - is the number in age less than 18
else - otherwise
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

sub-routines

A

the collective term for both procedures and functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

procedure

A

a piece of programming code which has a name and can be used/ called as often as needed. it should perform only ONE task.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

function

A

similar but always returns an answer to the program. (procedures do not return an answer)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

procedure example:

A
def hello():
       print("Hello world")

hello()
def - all procedures start with ‘def’…
hello - followed by the name of the procedure followed by ():
all code inside the procedure must be indented
hello() - type the procedures name to run it. make sure to include brackets

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

when might functions be used?

A

if there is some sort of calculation is to be carried out, or some other piece of information is needed by the main program (e.g. a persons name, age, answer to a question)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

function example

A
def getname():
       name= ....................
        return name

name= getname()
…………….
return name - the function has a return statement which sends information back to the main program
name=getname () - when the function is called in the main program, you must save the information being returned into a variable otherwise it will be lost

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what is a list?

A

a collection of data items grouped under the same variable.

the items in a list are numbered from zero

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

how to create a list

A

lessons = [“maths”,”PE”,”history”,”RE”]

use square brackets to create a list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

how to print a list

A

print(lessons)
prints the whole list
print (lessons[3])
prints the fourth item(because it starts counting from 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

how to add to the list

A

lessons.append(“computer science”)

adds computer science to the end of the list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what is a while loop?

A

it can be used to repeat a section of code until something changes. this is useful if you don’t know how long you need the code to repeat for

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

while loop example

A

carryon=”Y”
while carryon ==”Y”:
print (“keep going”)
carryon=input(“Do you want to carry on (Y/N)
create a variable and put the letter Y in it
while carryon is equal to Y, keep priting”keep going”
you have to cose an oppurtunity for the code to change otherwise it will go forever

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

variable

A

a named location within the computers memory to store a single value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

sequence

A

running code in the order it was written

17
Q

selection

A

choosing which lines of code to run based on a condition