You are on page 1of 3

MN404 Fundamentals of Operating System and Programming

Laboratory 6: Understand the basic data types and precedence of operators

Introduction

In each lab you will work through a series of exercises that will help you to
reinforce your learning by applying and using the knowledge gained in the
lecture class.

Remember - you are not expected to remember everything from your memory
– you may do a little research / reading of materials from the MIT resources
available. You have to prepare yourself for the lab as much as possible before
the lab session.

Submission Due: End of laboratory class, submit the file on Moodle at least 10
minutes before the end of laboratory class even if you have not completed all
the given exercises.

July 2020 Prepared by: Dr Nandini Sidnal Moderated by - Prof. Savitri


Bevinakoppa
MN404 Lab 7: Data types, operators, Input and output 2

1)

Consider the following code segment:


x= 5
y= 4
if x > y:
print( y )
else:
print( x )

What value does this code segment print?

2)
Consider the following code segment:
count = 5
while count > 1:
print(count, end = " ")
count -= 1

What is the output produced by this code?

July 2020 Prepared by: Dr Nandini Sidnal Moderated by - Prof. Savitri


Bevinakoppa
MN404 Lab 7: Data types, operators, Input and output 3

3)
Consider the following code segment:

theSum = 0.0

while True:
number = input("Enter a number: ")
if number == "":
break
theSum += float(number)

How many iterations does this loop perform?

4. Write a program that accepts the lengths of three sides of a triangle as


inputs. The program output should indicate whether or not the triangle is an
equilateral triangle.

5. Write a program that accepts the lengths of three sides of a triangle as


inputs. The program output should indicate whether or not the triangle is a
right tri- angle. Recall from the Pythagorean theorem that in a right triangle,
the square of one side equals the sum of the squares of the other two sides.

6. A local biologist needs a program to predict population growth. The inputs


would be the initial number of organisms, the rate of growth (a real number
greater than 0), the number of hours it takes to achieve this rate, and a
number of hours during which the population grows. For example, one might
start with a population of 500 organisms, a growth rate of 2, and a growth
period to achieve this rate of 6 hours. Assuming that none of the organisms
die, this would imply that this population would double in size every 6 hours.
Thus, after allowing 6 hours for growth, we would have 1000 organisms, and
after 12 hours, we would have 2000 organisms. Write a program that takes
these inputs and displays a pre- diction of the total population.

July 2020 Prepared by: Dr Nandini Sidnal Moderated by - Prof. Savitri


Bevinakoppa

You might also like