2nd Semester Intro to Computer Science

What you will learn

Reading

Lab

Part 1

Using the interpreter, type in the expressions below. Copy and paste the output into the output column. If the result is unexpected, note that in the third column.

Section 1

  Input     Output     Did it do something unexpected?  
a 5 + 2 * 2      
b 2/3      
c 2.0 * 1.5      
d (2 + 3) * 10      
e 5.0 // 2      
f 5.0 % 2      

Section 2

  Input     Output     Did it do something unexpected?  
a a      
b 'a'      

Section 3

  Input     Output     Did it do something unexpected?  
a 'a + b'      
b 'a' + 'b'      

Section 4

  Input     Output     Did it do something unexpected?  
a 'a' * 'b'      
b 'a' * 2      

Part 2

Before going to the IDE

  1. For each item, predict the data type of the result and enter into the “String/Integer/Float” column.
  2. Next, predict the value of the result for each item and enter into it into the “Prediction of Result” column.
  Expression String/Integer/Float Prediction of Result Interpreter Result
a 10 * 2 integer 20 20
b .5 * 2      
c 10/2      
d 10%2      
e 2 ** 3      
f (2+5)*3      
g 2 + 5 * 3      
h 'ab' + '12' + '3'      
i x      
j "ab" + "cd"      
k 'abc' * 2      
l '1'*2 + '2' * 3      
m 1 * 2 + '3' * 2      
n 'A' ** 2      
o 'bc' % 2      
p 'bc' / 2      

Now go to the IDE

Use the interpreter to evaluate the expressions, write down results in the “Interpreter Result” column.

Check your understanding

Pick an answer for each question. You can try again until you get it right.

1. Which of these is a string?

  • 7
  • '7'
  • 7.0
  • 7 + 0

Quotes make a value a string, so '7' is text, while 7 is an integer and 7.0 is a float.

2. What does 'ha' * 3 give you?

  • 'ha' + '3'
  • 'ha3'
  • An error
  • 'hahaha'

Multiplying a string by an integer repeats it, so 'ha' * 3 is 'hahaha'.

3. What is the value of 4 + 2 * 3?

  • 10
  • 18
  • 9
  • 24

Multiplication happens before addition, so the result is 4 + 6 = 10.

Downloads