Chapter 3 : Phython Codes Flashcards

1
Q

What is a data structure

A

A data structure s a special kind of variable that can hold serveral values.

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

Give 3 examples of storing data values

A
  • Social media platforms storing data on all the different accounts.
  • A team manager who wants to store data on all his team players.
  • A busniess owner storing data on all their products
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does traversing mean?

A

To look at every value on a data structure

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

Name 2 reasons people might want to traverse data

A
  • A team manager wants to send an email to all its players
  • Social Media platofrm wants to know which accounts are online and which are offline.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How can a user change the size of a list?

A
  • Append a value to make the list longer
  • Delete a value to make the list shorter
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What happens if the stop value doesnt match the size of the list?

A

It will either end too early, missing a few values or it will go on for too long, causing an out of bounds error.

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

Phython code for traversing a list

A

topiclist = [“A”, “B”, “C”]
for i in range [3] :
print (i, topiclist[i])

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

Phython code for finding the list length

A

topiclist = [“A”, “B”, “C”]
stop = len(topiclist)
for i in range (stop) :
print (i, topiclist[i])

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

What is a program interface?

A

The part of the program that handles input and output.

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

Name 5 requirments for a program interface

A
  • Tell the user what the program is and what does it do
  • Allow the user to exit the program
  • Allow the user to enter an input
  • Let the user make choices or select options
  • Display results or answers
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the error in this program?

topiclist = []
choice == “X”
while choice == “X” :
print(T O P I C S)
print(===================)
print(“\n”)
print(“A: Append a value”)
print(“B: Print the teamlist”)
print(“X: Exit the Program”)

A

The wrong logical test is used.

It should be != instead of ==

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

What is the error in this program?

topiclist= []
while choice != “X” :
print(T O P I C S)
print(===================)
print(“\n”)
print(“A: Append a value”)
print(“B: Print the teamlist”)
print(“X: Exit the Program”)
choice = input(“Enter your choice: “)

A

Choice is not defined as it has not been given a value yet.

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

What is the error in this program?

choice = “ “
while choice != “X” :
topiclist []
print(T O P I C S)
print(===================)
print(“\n”)
print(“A: Append a value”)
print(“B: Print the teamlist”)
print(“X: Exit the Program”)
choice = input(“Enter your choice: “)

A

The topiclist is inside the loop. Whenever the loop is repeated, the topiclist will be cleared and go back to being empty.

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

What is nesting?

A

When a program structure is inside of another structure.

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

What is the command to print an element?

A

i = input (“Which list item do you want to print?”)
i = int(i)
print (topiclist[i])

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

What is the command to edit an element?

A

i = input (“Which list item do you want to edit?”)
i - int(i)
teamlist[i] = input (“Enter a new value.”)

17
Q

What is the command to delete an element?

A

i = input (“Which list item do you want to delete?”)
i - int(i)
del topiclist[i]

18
Q

What is the full program using double indentation?

A

teamlist = []
choice = “ “

while choice != “X” :
print(“ T O P I C S”)
print(“=======================”)
print(“This list will show you all the topics”)
print(“\n”)
print(“A: Append a value”)
print(“B: Print the topic list”)
print(“X: Exit the program”)

if choice == “A” :
topic = input(“Enter a new topic”)
topiclist.append(topic)

if choice == “B” :
print(topiclist)