Python Basics revision Flashcards
REVISE FOR TEST
what is a variable
A variable is a storage space for data that can be accessed and changed.
what are the three Rules for Naming Variables
Start with a letter or an underscore ( _ is a underscore)
Cannot use spaces or special characters.
Cannot start the name with a number
name the 4 Data types
integers
floats
strings
Booleans
what do es this symbol in python mean ( + )
Addition
what are the python names for the 4 data types:
integers
floats
strings
Booleans
Integers: int
Floats: float
Strings: str
Booleans: bool
what are the different data types: integers
floats
strings
Booleans
used to store
integer is Used for whole numbers
floats are Used for numbers with decimals
string: Represents text or characters, inside quotation marks
Booleans: Represents True or False.
what do es this symbol in python mean ( - )
Subtraction
what do es this symbol in python mean ( / )
Division
what do es this symbol in python mean ( * )
Multiplication
what do es this symbol in python mean ( % )
Modulas ( outputs the remainder of a division )
what are the 4 comparison signs in python
==
!=
>
<
what does ==
!=
>
<
these in python mean
==: Equal to
!=: Not equal to
> : Greater than
<: Less than
what are the three logical operators in python
and
or
not
what are logical operators
logical operators are used to combine conditional statements
when are the three logical operators and, or and not used
and: Both conditions must be true.
or: At least one condition must be true.
not: If something is true, it makes it false. If something is false, it makes it true.
what are the three conditional statements
if
elif
else
when are if elif and else used
if: Used to check a condition. If it’s true,
elif: Used to check another condition if the previous if condition was false.
else: Used to run something if none of the previous if or elif conditions were true
what is a while loop and what does it do
a syntax that Repeats a code as long as a condition is True.
what is a while condition and what is it used for
its for the while loop Often Used to go through a list or a range of numbers repeatedly checking if the condition matches until the
condition is met.
what code do you need to generate a random number 1 to 10
import random
number=random.randint(1, 10)
print(number)
what is a input and output in python
input: captures user input as a string.
output: displays text to the user.
what is a function
A function is a reusable block of code that performs a specific task.
def say_hello():
print(“Hello!”)
say_hello()
what is a calling Function
A calling function is when you use a function’s name followed by parentheses to execute its code def say_hello():
print(“Hello!”)
say_hello()
what are the 4 common errors in python
Syntax Error
Infinite loops
Runtime Error
Logic Errors
when do
Syntax Error
Infinite loops
Runtime Error
Logic Errors
Occur
Syntax Errors: Result from improper syntax
Infinite Loops: Occurs when loop conditions are never met to stop
Runtime Errors: Occur during execution due to invalid operations ( dividing by 0 )
Logic Errors: Occurs when there is something wrong with the Logic (example 1+1=3)
write a code that uses a function to print out hello
def say_hello():
print(“Hello!”)
say_hello()
write a code that ask a user a number and make that number a int (in the simplest form)
number = int(input(“Enter a number: “))
write a code that ask a user a decimal number and make that number a float (in the simplest form)
decimal_number = float(input(“Enter a decimal number: “))
write a while loop code that reputedly counts until they get to 5 stop and after every count tell them the current number
count = 0
while count < 5:
print(“Count is:”, count)
count += 1