python Flashcards
create a list of favourite films
print the second film in the list
add a new film to the list
print the whole list
favFilms=[“Mulan”, “frozen”, “moana”]
print(favFilms[1])
favFilms.append(“Harry Potter”)
print (favFilms)
What is a for loop?
This will repeat lines of code for a set number of times.
A FOR loop has a definite number of loops.
what is a while loop?
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.
while loop example:
carry0n=”Y”
while carry0n==”Y”:
print(“keep going…”)
carry0n= input(“Do u want to carry on? Y/N”)
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.
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!")
Create a list, print the list, print the 4th item and then add to the list
lessons= [“Maths”, “PE”, “History”, “RE”]
print (lessons)
print (lessons[3])
lessons.append (“Computer Science”)
How do u use IF to test a variable
if age <18:
Print (“you are a child”)
else:
print (“you are an adult”)