Python Fundamentals Flashcards
What is a function? And how can you recognise it?
A reusable piece of code that completes a specific task.
By spotting a word followed by round brackets and quotation marks inside (either “” or ‘’)
What is the print function used for?
To output a message to the programmer
What are the three fundamental concepts (building blocks) of programming?
- Variables & data types
- Conditional statements
- Loops
What is a variable?
Assigned data, it can store any data type that you need.
Label components of the following:
int age = 32
int = data type age = reference (variable name) 32 = value stored in memory
What are the different types of data? Give examples.
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
What is the following an example of?
if day = “Saturday”:
print (“Yes, day off!”)
else:
print (“Back to work!”)
A conditional statement (IF statement)
Why is Python a useful programming language?
Beginner friendly language, fastest-growing major programming language, lots of useful libraries & features
How do you print a greeting to the user i.e. hello insert users name and last name?
first_name = input (“what is your name?”)
last_name = input (“what is your last name?”)
print (“hello”,first_name,last_name)
What is the input function used for?
Interacting with the user e.g. Enter your name:
Is output a function?
No
How are mathematical operations ordered in Python?
BODMAS - brackets, orders e.g. x^2, division, multiplication, addition, subtraction
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
number1=float(input(“please enter first number: “))
number2=float(input(“please enter second number: “))
answer = number1 + number2
print(number1,”+”,number2,”=”,answer)
Why would we need to sometimes label different data types?
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 would you print this using separate string variables:
carrot beans
veg1 = “carrot”
veg2 = “beans”
print(veg1+ ‘ ‘+ veg2)
You combine strings using + and numbers and strings with ,