Practice: if

Tags

Try these questions. They don't count towards your grade, so relax and give it a whirl.

Multiple choice

What will this code output?

Try to predict the output without running the program.

  • animal1 = 'doggo'
  • animal2 = 'catto'
  • if animal1 + animal2 == 'doggocatto':
  •     print('Goats!')
  • else:
  •     print('No goats!')
Saving
A

Nothing.

B

Error message

C
Goats!
D
No goats!

Not graded. So why do it?

Multiple choice

What does this output? Think it through and answer, before you try the code.

  • au = 79
  • ag = 47
  • cu = 29
  • if au - cu > ag:
  •     pb = 82
  • else:
  •     pb = 'peanut butter'
  • print('Put some ' + str(pb) + ' on your bread.')
Saving
A

Nothing

B

Error

C
Put some 82 on your bread.
D
Put some peanut butter on your bread.

Not graded. So why do it?

Multiple choice

What does this output? Think it through and answer, before you try the code.

  • kaitlin = 80
  • yolinda = kaitlin / 2
  • bethany = yolinda / 2
  • if bethany > yolinda and bethany > kaitlin:
  •     highest = 'Bethany'
  • elif yolinda > bethany and yolinda > kaitlin:
  •     highest = 'Yolinda'
  • else:
  •     highest = 'Kaitlin'
  • print("And it's " + highest + ' for the win!')
Saving
A

Nothing

B
And it's Bethany for the win!
C
And it's Kaitlin for the win!
D
And it's Yolinda for the win!

Not graded. So why do it?

Multiple choice

What does this output? Think it through and answer, before you try the code.

  • x = 10
  • y = 20
  • z = 40
  • if z - x < y or x + y > z:
  •     print('Something to see!')
  • else:
  •     print('Move along! Nothing to see.')
Saving
A
Something to see!
B
Move along! Nothing to see.
C

Error

D
Doggos rule!

Not graded. So why do it?

Multiple choice

What does this output? Think it through and answer, before you try the code.

  • ant = 6
  • spider = 7
  • elk = 4
  • emu = 2
  • if elk > spider or spider > ant:
  •     print("Well, I'll bee!")
  • else:
  •     print('By Jiminy!')
Saving
A
Well, I'll bee!
B
By Jiminy!
C

Nothing

D
Koalas kill!

Not graded. So why do it?

Multiple choice

What does this output? Think it through and answer, before you try the code.

  • ant = 6
  • spider = 7
  • elk = 4
  • emu = 2
  • if not (elk > spider or spider > ant):
  •     print("Well, I'll bee!")
  • else:
  •     print('By Jiminy!')
Saving
A
Well, I'll bee!
B
By Jiminy!
C

Nothing.

D
Emus are stroppy.

Not graded. So why do it?

Multiple choice

What does this output? Think it through and answer, before you try the code.

  • red = 16
  • blue = 8
  • green = 4
  • ralts = 2
  • if green ** ralts == red:
  •     print("Well, here's the thing.")
  •     if red - blue > green * ralts:
  •         print('Ralts is a pokemon.')
  •     else:
  •         print("I'm so confused!")
  • else:
  •     print('The rest are colors.')
Saving
A
Well, here's the thing.
Ralts is a pokemon.
B
Well, here's the thing.
I'm so confused!
C
I'm so confused!
D
The rest are colors.
E

Error

Not graded. So why do it?

Multiple choice

What does this output? Think it through and answer, before you try the code.

  • cards1 = 'Uno'
  • cards1_score = 17
  • cards2 = 'Go fish'
  • cards2_score = 11
  • cards3 = 'Kiss the bishop'
  • cards3_score = 19
  • cards4 = 'Gotcha!'
  • cards4_score = 7
  • if cards1_score >= cards2_score:
  •     print(cards1 + ' dominates ' + cards2)
  •     if cards1_score > cards3_score:
  •         print("It don't look good, Zeke.")
  •     else:
  •         print("Zeke, you ol' possum!")
  • else:
  •     print('I knew it, I knew it!')
  •     if cards3_score > cards4_score:
  •         print('Umm... is that right?')
Saving
A
I knew it! I knew it!
B
I knew it! I knew it!
Umm... is that right?
C
Go fish dominates Uno
Zeke, you ol' possum!
D
Uno dominates Go fish
It don't look good, Zeke.
E
Uno dominates Go fish
Zeke, you ol' possum!
F

Error

Not graded. So why do it?

Multiple choice

What does this output? Think it through and answer, before you try the code.

  • cards1 = 'Uno'
  • cards1_score = 23
  • cards2 = 'Go fish'
  • cards2_score = 31
  • cards3 = 'Kiss the bishop'
  • cards3_score = 5
  • cards4 = 'Gotcha!'
  • cards4_score = 7
  • if cards1_score >= cards2_score:
  •     print(cards1 + ' dominates ' + cards2)
  •     if cards1_score > cards3_score:
  •         print("It don't look good, Zeke.")
  •     else:
  •         print("Zeke, you ol' possum!")
  • else:
  •     print('I knew it, I knew it!')
  •     if cards3_score > cards4_score:
  •         print('Umm... is that right?')
Saving
A
Uno dominates Go fish
It don't look good, Zeke.
B
Uno dominates Go fish
Zeke, you ol' possum!
C
I knew it! I knew it!
Umm... is that right?
D
I knew it! I knew it!
E

Error

Not graded. So why do it?

Multiple choice

What does this output? Think it through and answer, before you try the code.

  • cards1 = 'Uno'
  • cards1_score = 5
  • cards2 = 'Go fish'
  • cards2_score = 7
  • cards3 = 'Kiss the bishop'
  • cards3_score = 2
  • cards4 = 'Gotcha!'
  • cards4_score = 1
  • if cards1_score >= cards2_score:
  •     print(cards1 + ' dominates ' + cards2)
  •     if cards1_score > cards3_score:
  •         print("It don't look good, Zeke.")
  •     else:
  •         print("Zeke, you ol' possum!")
  • else:
  •     print('I knew it, I knew it!')
  •     if cards3_score > cards4_score:
  •         print('Umm... is that right?')
Saving
A

Error

B
Uno dominates Go fish
Zeke, you ol' possum!
C
Uno dominates Go fish
It don't look good, Zeke.
D
I knew it! I knew it!
E
I knew it! I knew it!
Umm... is that right?
F
I should ride a kangaroo.

Not graded. So why do it?

Multiple choice

What does this output? Think it through and answer, before you try the code.

  • sixes = 2
  • boundaries = 4
  • runs = 40
  • sundries = 8
  • if not sixes * 6 > runs and boundaries * 4 != runs:
  •     print('Cricket is strange')
  • else:
  •     print('Cricket is... just is')
Saving
A

Error

B
Cricket is strange
C
Cricket is... just is
D
Australia has five states.

Not graded. So why do it?

Multiple choice

What does this output? Think it through and answer, before you try the code.

  • sheep = 11
  • goats = 13
  • cows = 2
  • if cows + sheep = goats:
  •     print('Well, fine! If that is what you want!')
  • else:
  •     print("I just can't today!")
Saving
A
Well, fine! If that is what you want!
B
I just can't today!
C

Error

D
Bluey is from Perth.

Not graded. So why do it?