Programming Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is the structure of a for loop

A

For i in range (0,10)

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

What does the break command do

A

Breaks the loop when the condition is reached or when break shows up in the program

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

What is the structure of while loop

A

While(i<——)

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

What is the list comprehension structure

A

vowels = [‘a’, ‘e’, ‘i’, ‘o’, ‘u’]
If text[i] in vowels:
print(“——“)

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

How do you use a counter

A

Count=0
If character fits the condition(s)
Count=count+1

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

What’s important in a loop

A
  • always updated the i counter - i=i+1
  • remember to have a counter and stopping condition - (0,10)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the structure of the length command

A

Length=len(——)

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

How do you separate out a single character from a string

A

For letter k:
School=“kisc”
Print(school[0])

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

How do you separate out multiple letter from a string

A

For ki:
School=“kisc”
Print(school[0:2])

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

What will this print:
School=“kisc”
Print(school[2:])

A

Everything after 2, including 2

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

What will this print:
School=“kisc”
Print(school[:2])

A

Everything before 2, not including 2

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

What is important to remember for string handling

A
  • Remember that the first letter of the string is counted as 0 and not 1
  • always use [ ]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is important to remember for list comprehension

A
  • be very specific - for example ‘a’ and ‘A’ are two different things
  • always use [ ] and ‘ ’ around whatever that is part of the list
How well did you know this?
1
Not at all
2
3
4
5
Perfectly