Programming Flashcards
What is the structure of a for loop
For i in range (0,10)
What does the break command do
Breaks the loop when the condition is reached or when break shows up in the program
What is the structure of while loop
While(i<——)
What is the list comprehension structure
vowels = [‘a’, ‘e’, ‘i’, ‘o’, ‘u’]
If text[i] in vowels:
print(“——“)
How do you use a counter
Count=0
If character fits the condition(s)
Count=count+1
What’s important in a loop
- always updated the i counter - i=i+1
- remember to have a counter and stopping condition - (0,10)
What is the structure of the length command
Length=len(——)
How do you separate out a single character from a string
For letter k:
School=“kisc”
Print(school[0])
How do you separate out multiple letter from a string
For ki:
School=“kisc”
Print(school[0:2])
What will this print:
School=“kisc”
Print(school[2:])
Everything after 2, including 2
What will this print:
School=“kisc”
Print(school[:2])
Everything before 2, not including 2
What is important to remember for string handling
- Remember that the first letter of the string is counted as 0 and not 1
- always use [ ]
What is important to remember for list comprehension
- be very specific - for example ‘a’ and ‘A’ are two different things
- always use [ ] and ‘ ’ around whatever that is part of the list