Chapter 13: Python Flashcards
1
Q
Declaration of variables
A
- No declaration necessary
- A comment should be used either way
#Number1: Type INTEGER #YourName: Type STRING
2
Q
Assignment of constants
A
- identifier=value
* PI=3.14
3
Q
Assignment of variables
A
•identifier=expressions
- A=34
- B=B+1
4
Q
Arithmetic operations
A
- | - | * | / | ** | // | %
* Rules of precedence should be followed
5
Q
Outputting information
A
- print(printlist)
* print(“Hello, ”,YourName,”Your number is: “,Number1)
6
Q
Comments
A
This is a comment
7
Q
Data types
A
- int
- float
- str
- bool
- datetime
8
Q
Boolean expressions
A
- ==
- !=
- >
- <
- > =
- <=
- and | or | not
- in
9
Q
Selection statements
A
if x<0: print(“Negative”) elif x=0: print(“Zero”) else: print(“Positive”)
10
Q
Count-controlled loops
A
for x in range (5):
print(x)
11
Q
Pre-condition loops
A
Answer=‘ ‘
while Answer != “Y”:
Answer=input(“Enter Y or N”)
12
Q
Creating 1D arrays
A
•List1=[] List1.append(“Fred”) List1.append(“Jack”) List1.append(“Ali”) •List2=[0,0,0,0,0,0,0] •List3=[0 for i in range (100)] •List4=[“ “]*100
13
Q
Accessing 1D arrays
A
- NList[24]=0
* AList[3]=“D”
14
Q
Creating 2D arrays
A
•Board=[0 for i in range(7)]
for j in range(6)
•Board=[07]6
15
Q
Accessing 2D arrays
A
Board [2][3]=0