[SOLVED] ITI1120 Lab3-Boolean expressions, if statements, debugging 

30.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon Lab3-jqsqvs.zip (125.1 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
🔒 Securely Powered by:
Secure Checkout
5/5 - (1 vote)

 

  1. This lab bas 3    Tasks   (3rd task     has several      parts). You     should try to  do  these   parts      at

Task     2    and      3 are   in   the interactive textbook.  Watch the video   I     provided (follow      the link      at   page    7)   before doing  these   two     tasks.

  1. And 5 programming   exercises  (0   to  4)

The      slides  that     are included   here    but do not explain      either  Tasks   or  Programming exercises  are there   as  reminder  of   some relevant    material    that     is   needed     for this lab.

Lab  3 overview

  • Open a    browser    and      log into Brightspace
  • On the left hand   side     under  Labs    tab, find     lab3     material    contained in   either  lab3-students.zip or  lab3-studnets.pdf      file
  • Download that     file to  the Desktop    and open
  • Read slides  one     by  one     and      follow the instructions    explaining what   to  When stuck   ask for help    from    TA. Ideally you should try to  complete  some,  or  all  of   this,       at   home  and      then    use      the lab as  a place   where you      can      get help    with things  you      may     have    had      difficulties with.

Before   starting,   always make sure you  are  running Python    3

This   slide      is    applicable  to   all   labs,    exercises,   assignments     …    etc

ALWAYS  MAKE   SURE    FIRST    that      you are    running       Python 3.4 (3.5

and 3.6 are    fine       too).     That      is,   when    you click      on  IDLE      (or  start     python any    other    way)     look      at   the first       line that    the Python shell      displays.     It    should  say    Python 3.4 or   3.5 or   3.6        (and      then    some    extra     digits)

If you do  not know    how      to   do  this,      read    the material      provided     with      Lab 1.   It    explains      it    step      by   step

div   // and mod % operators    in Python

If uncertain,  here      is    how      to   compute a//b (i.e.    integer division)      and a%b (i.e remainder)

  1. Compute x=a/b
  2. a//b is then equal    to   the whole   (i.e integer)  part      of   More   precisely   a//b is    equal    the integer that      is   closest  to   a/b but    not bigger  than   a/b
  3. a%b is equal    to          a – (a//b) * b

 

Task 1

What is    the type      and value     of   each      of   the    following     expressions in    Python? Do  this in    you    head     (and/or paper)   first.      The check    both    columns       in    Python  shell.     eg.  You can test what    kind       of   value     the first expression   returns  by    typing   type(13*0.1) in      Python  shell

Expression Type Value
13 * 0.1 float 1.3
int(13) * 0.1    
13 * int(0.1)    
int(13 * 0.1)    
13 % 7    
6%3    
6//2.5    
6%2.5    
2<3== 4<5    

6

Interactive   textbook    (Reminder)

Here    is   a    link      to  the interactive      textbook: https://runestone.academy/runestone/static/thinkcspy/index.html

Task 2: Debugging

Follow   this      link,     and      read,   run and      do  the exercises  there:

https://runestone.academy/runestone/static/thinkcspy/Debugging/HowtoAvoidDebugging.html

An      example      used      in    the above    link    refers    to   the following     problem      from    Chapter:      Simple  Python  Data,     Section:    Exercises,    Question     3:

https://runestone.academy/runestone/static/thinkcspy/SimplePythonData/Exercises.html

Many people keep time using a 24 hour clock (11 is 11am and 23 is

11pm, 0 is midnight). If it is currently 13 and you set your alarm to go off in 50 hours, it will be 15 (3pm). Write a Python program to solve the general version of the above problem. Ask the user for the time now (in hours), and then ask for the number of hours to wait for the alarm. Your program should output what the time will be on the clock when the alarm goes off.

Programming   exercise 0:

More   debugging    and  coding

Open   file     q0.py and    solve the     3  programming  exercises     as instructed.

 

Boolean   Expressions

Boolean    expressions    evaluate   to  True or False

Logical/Boolean   operators in   Math   and Python:

Math               Python

AND        and

OR         or

NOT        not

Here    is   how     your    compare   two     variables a    and      b    in   Math   and      Python

Math Python
a = b a == b
a ≤ b a <= b
a ³ b a >= b
a ¹ b a != b

Truth    table

A    TRUTH TABLE for a    compound     Boolean expression     shows the results for all  possible combinations of   the simple expressions:

Testing  if two   strings  are equal

For    one of   the        programming     exercise you  will need     to   know     that       how      to  compare      if     two strings   are equal.   You can  do   that       simply   buy using     == operator.  Here      are some     examples

>>> ‘A’==‘A’

True

>>> ‘Anna’==‘Anna’

True

>>> ‘Anna’=‘anna’

False

>>> a=‘June’

>>> a==‘june’

False

>>> a==‘June’

True

>>> b=‘Ju’ + ’ne’

>>> a==b True

  1. Do not  copy        paste      the  above     into python    shell.       It     will  likely       give you syntax     errors    since       quotes    do   not  copy/paste    correctly from    Word.

 

Examples of compound boolean  expressions:

  • This is    how      you would   test if     age is at       least      18   and at   most     65:

age>=18 and age <= 65

  • not is an operator      to   negate  the value     of   a       simple   or   compound   Boolean        Suppose       age = 15.       Then: age > 16 evaluates       to    False,  and not(age > 16) evaluates       to    True
  • Suppose day refers    to   a     string    which    is    a       day of   a         Here      is    how      you       would   test if           day is a     weekend:

day==“Saturday” or day==“Sunday”

  • Here are two ways     to   test if     age is less than       18   and greater than        Think     about    the       2nd one
    • 1st way: age<18 and age > 65
    • 2nd way: not(age>=18 and age <= 65)

Task  3: if  statements

Follow   all   the links      below.  Read,    run and do   the       exercises     in    each      of   them.    No  need     to       watch   the videos.

  • Lab3-jqsqvs.zip