python Flashcards

1
Q

create a list of favourite films
print the second film in the list
add a new film to the list
print the whole list

A

favFilms=[“Mulan”, “frozen”, “moana”]
print(favFilms[1])
favFilms.append(“Harry Potter”)
print (favFilms)

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

What is a for loop?

A

This will repeat lines of code for a set number of times.​

A FOR loop has a definite number of loops.

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

what is a while loop?

A

This will keep repeating lines of code until a variable or condition changes. A WHILE loop may loop forever if the condition doesn’t change.

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

while loop example:

A

carry0n=”Y”
while carry0n==”Y”:
print(“keep going…”)
carry0n= input(“Do u want to carry on? Y/N”)

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

Create a program that asks the user a general knowledge question.​

While they keep getting the answer wrong, the program should tell them they got it wrong and let them have another attempt.

A

guess = input(“What is the capital of England?”)

while guess!= "London":
  Print ("incorrect")
  guess= input("Try again: what is the capital of 
  England?")
Print("Well done!")
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Create a list, print the list, print the 4th item and then add to the list

A

lessons= [“Maths”, “PE”, “History”, “RE”]
print (lessons)
print (lessons[3])
lessons.append (“Computer Science”)

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

How do u use IF to test a variable

A

if age <18:
Print (“you are a child”)
else:
print (“you are an adult”)

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