unknowns so far Flashcards
(44 cards)
compare = “Python” * 3
print (compare)
PythonPythonPython
compare = “Python” > “Java”
print (compare)
True
(Python comes first in the alphabet and is at a lower index/would come first)
compare = “Python” + “Java”
print(compare)
PythonJava
word = “python”
firstletter = word[0]
print(firstletter)
p
word = sheep
for letter in word:
print (letter)
S
H
E
E
P
compare = “Hello”
len(compare) =
5
compare = “Hello”
compare.isalpha()
True
compare = 12345
compare.isalpha()
False
compare = “Hello”
compare.upper()
HELLO
compare = 12345
compare.upper()
TypeError - The two data types conflict.
compare = 12345
compare.isalnum()
True
compare = “Hello”
compare.isalnum()
False
What is a data structure?
a container that can hold several items at the same time.
What is an array?
A data structure that can hold a number of items grouped together.
It contains a number of items grouped together, and named using a single identifier, however can only hold the same data type.
What is a syntax error?
When code written does not follow the rules of the programming language
What is a runtime error?
If something unexpected is typed in by the user, the code will crash, eg. A string where a bool/real is expected.
It occurs WHILE the program is running.
What is a type error?
TypeError = When the two data types conflict
How can you convert types?
int() -> Turns into a number as long as the input is acceptable
str() -> Can turn anything into a string.
float() -> 7 = 7.0
bool() -> True / False
What is the most significant bit?
Left most number
What is the least significant bit?
Right most number
What is a signed integer?
signed = assigned as positive or negative
What is an unsigned integer?
positive integer including 0 that hasn’t been assigned as positive or negative
What is an overflow error?
when the result of a calculation is too large to be represented in the number of bits allocated
when you have a carry on the end of a sum and it overflows
eg. your result being a 9 bit number and your calculation being 8 extra carry has nowhere to go
a computer handles this by:
- crashing and reporting the overflow error
- truncating the answer and leaving off the extra one, resulting in an unexpected answer
- wrapping the number back around to 0
What is two’s complement?
- the whole number when added makes the intended denary, as the MSB is negative.
- most common way of representing signed binary integers
- ARITHMETIC WORKS IN TWO’S COMPLEMENT!!! doesn’t work in sign and magnitude.