Python - Computer Science

Cards (29)

  • Code
    1. print("STAY")
    2. print("CALM")
    3. print("AND")
    4. print("LEARN")
  • IDLE
    • STAY
    • CALM
    • AND
    • LEARN
  • Which one of the following will produce the following output Hello World ?

    a)print“Hello World”
    b)print(“Hello World”);
    c)print(“Hello World”)
    d)print(“Hel World”)
    e)print(Hello World)
    Ans: C
  • print("Hello, what is your name?")
    name = input()
    print("What is your top 2 favourite films" + name"?")
    favouritefilm1 = input("1.")
    favouritefilm2= input("2.")
    favouritefilm3 = input("3.")
    Hello Vaishaa, your top 3 favourite films are as follows:
    1.Guardians of the Galaxy
    2.Endgame
    3. Finding Nemo
  • To make a variable that will be stored in the python program, what must you remember?

    no blank space, can not start with number , case sensitive , underscore permitted
  • What symbol do you use to comment on your code?

    # (hashtag)
  • For python to do mathematical calculations, e.g. division.... you would use what symbol?

    / (forward slash)
  • *
    means multiplication in python for mathematical calculations
  • symbol for equals to
    ==
  • symbol for not equals to
    !=
  • greater than
    >
  • less than
    <
  • greater than or equal to

    >=
  • less than or equal to
    <=
  • True or false
    6>=8
    False
  • True or false
    6!=7
    True
  • When do you use the int function? e.g. int(answer)

    when the answer is a whole integer
  • What is the error in this code?
    if answer ==5
    print("Well Done")
    else:

    ANSWER:
    print("Sorry the answer was 5")
    if answer ==5:
    print("Well Done")
    else:
    print("Sorry the answer was 5")
  • What is the difference between == and = ?

    == means equal to
    = means assigned to like a name being assigned to a variable
  • Key points


    print("Please enter your name: ")
    my_name = input ()
    print(my_name + " what age are you")
    my_age = input()
    my_age = int(my_age)
    if my_age > 11:
        print("You must go to Secondary school")
    else:
         print("You must go to Primary school")
  • What is a score known as?
    a counter
  • Elif statements

    if score==6:
    print("You scored, score, out of 6,", name,". Your rank is TOTAL GENIUS.")
    elif score==5:
    print("You scored, score, out of 6,", name,". Your rank is MATHS GENIUS.")
    elif score==4:
    print("You scored, score, out of 6,", name,". Your rank is INTERMEDIATE .")
    elif score==3:
    print("You scored, score, out of 6,", name,". Your rank is BEGINNER.")
  • iteration definition

    Repetitive execution of the same block of code over and over is referred to as iteration. There are two types of iteration: Definite iteration, in which the number of repetitions is specified explicitly in advance. Indefinite iteration, in which the code block executes until some condition is met.
  • looping definition

    repeating something over and over until a particular condition is satisfied
  • CODE
    for i in range (0,5):
    print(i , "looping")

    IDLE
    0 looping
    1 looping
    2 looping
    3 looping
    4 looping
  • For i ....

    0 is the starting value
  • for i in range (3,31,3):
    print (i)
    3 - starting number (times table)
    31 - one higher than number want to finish with (counter)
    3 - difference of each number( number to increase each i by)
  • CODE
    for i in range (4,21,4):
    print(i)
    IDLE
    4
    8
    12
    16
    20
  • CODE
    num = 0
    for i in range (6,37,6)
    num= num+1
    print(num, "*", "6", "=", i)
    IDLE
    1 * 6 = 6
    2 * 6 = 12
    3* 6 = 18
    4* 6 = 24
    5 * 6 = 30
    6 * 6 = 36