Python Basics revision Flashcards

REVISE FOR TEST

1
Q

what is a variable

A

A variable is a storage space for data that can be accessed and changed.

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

what are the three Rules for Naming Variables

A

Start with a letter or an underscore ( _ is a underscore)

Cannot use spaces or special characters.

Cannot start the name with a number

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

name the 4 Data types

A

integers
floats
strings
Booleans

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

what do es this symbol in python mean ( + )

A

Addition

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

what are the python names for the 4 data types:
integers
floats
strings
Booleans

A

Integers: int
Floats: float
Strings: str
Booleans: bool

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

what are the different data types: integers
floats
strings
Booleans
used to store

A

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.

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

what do es this symbol in python mean ( - )

A

Subtraction

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

what do es this symbol in python mean ( / )

A

Division

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

what do es this symbol in python mean ( * )

A

Multiplication

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

what do es this symbol in python mean ( % )

A

Modulas ( outputs the remainder of a division )

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

what are the 4 comparison signs in python

A

==
!=
>
<

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

what does ==
!=
>
<
these in python mean

A

==: Equal to

!=: Not equal to

> : Greater than

<: Less than

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

what are the three logical operators in python

A

and
or
not

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

what are logical operators

A

logical operators are used to combine conditional statements

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

when are the three logical operators and, or and not used

A

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.

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

what are the three conditional statements

A

if
elif
else

13
Q

when are if elif and else used

A

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

14
Q

what is a while loop and what does it do

A

a syntax that Repeats a code as long as a condition is True.

15
Q

what is a while condition and what is it used for

A

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.

16
Q

what code do you need to generate a random number 1 to 10

A

import random
number=random.randint(1, 10)
print(number)

17
Q

what is a input and output in python

A

input: captures user input as a string.
output: displays text to the user.

18
Q

what is a function

A

A function is a reusable block of code that performs a specific task.
def say_hello():
print(“Hello!”)
say_hello()

19
Q

what is a calling Function

A

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()

20
Q

what are the 4 common errors in python

A

Syntax Error
Infinite loops
Runtime Error
Logic Errors

21
Q

when do
Syntax Error
Infinite loops
Runtime Error
Logic Errors
Occur

A

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)

22
Q

write a code that uses a function to print out hello

A

def say_hello():
print(“Hello!”)
say_hello()

23
Q

write a code that ask a user a number and make that number a int (in the simplest form)

A

number = int(input(“Enter a number: “))

24
Q

write a code that ask a user a decimal number and make that number a float (in the simplest form)

A

decimal_number = float(input(“Enter a decimal number: “))

25
Q

write a while loop code that reputedly counts until they get to 5 stop and after every count tell them the current number

A

count = 0
while count < 5:
print(“Count is:”, count)
count += 1