Python Fundamentals Flashcards

1
Q

What is a function? And how can you recognise it?

A

A reusable piece of code that completes a specific task.

By spotting a word followed by round brackets and quotation marks inside (either “” or ‘’)

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

What is the print function used for?

A

To output a message to the programmer

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

What are the three fundamental concepts (building blocks) of programming?

A
  1. Variables & data types
  2. Conditional statements
  3. Loops
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a variable?

A

Assigned data, it can store any data type that you need.

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

Label components of the following:

int age = 32

A
int = data type
age = reference (variable name)
32 = value stored in memory
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the different types of data? Give examples.

A

String - basic, plain text, used to display information e.g. name = ‘Steve’
Boolean - Yes or no, true or false e.g. discount = false
Integer - A whole number (non-fractional) e.g. age = 32
Float - A decimal number (fractional) e.g. wallet = 293.32

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

What is the following an example of?

if day = “Saturday”:
print (“Yes, day off!”)
else:
print (“Back to work!”)

A

A conditional statement (IF statement)

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

Why is Python a useful programming language?

A

Beginner friendly language, fastest-growing major programming language, lots of useful libraries & features

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

How do you print a greeting to the user i.e. hello insert users name and last name?

A

first_name = input (“what is your name?”)
last_name = input (“what is your last name?”)
print (“hello”,first_name,last_name)

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

What is the input function used for?

A

Interacting with the user e.g. Enter your name:

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

Is output a function?

A

No

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

How are mathematical operations ordered in Python?

A

BODMAS - brackets, orders e.g. x^2, division, multiplication, addition, subtraction

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

How would you get this as an answer in the console:

please enter first number: 2
please enter second number: 2
2.0 + 2.0 = 4.0

A

number1=float(input(“please enter first number: “))
number2=float(input(“please enter second number: “))
answer = number1 + number2
print(number1,”+”,number2,”=”,answer)

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

Why would we need to sometimes label different data types?

A

Data types define the operations that can be done on the data, the meaning of the data, and the
way values of that type can be stored. A data type is an attribute of data that tells us how a programmer intends to use the data.

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

How would you print this using separate string variables:

carrot beans

A

veg1 = “carrot”
veg2 = “beans”
print(veg1+ ‘ ‘+ veg2)

You combine strings using + and numbers and strings with ,

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

What does the computer default the input value to (data type)?

A

string

17
Q

What is \n?

A

line break e.g. “This string is broken up \nover multiple lines” will output

This string is broken up
over multiple lines

18
Q

How do you convert a number to an integer, what should you take extra care in and how do you combat this?

A

int(2.6)

the output is 2 not 3 as it takes the whole part of the number rather than rounding it up, use round(2.6) to combat this

19
Q

when do you need to make sure you use :?

A

after boolean statements (if/else/elif)

20
Q

What is important when using the true/false statements?

A

Capitalise these functions e.g. True/False

21
Q

Write a code to check which number is bigger than the other (and print answer).

A

number1 = float(input(“enter first number:”))
number2 = float(input(“enter second number:”))
if number1 > number2:
number1bigger = True
else:
number1bigger = False
print(“number1bigger:”, number1bigger)

22
Q

How do you add a comment (non coding text)?

A

use #