Task 1 Task 2 Task 3
ducks

Task 1

An ornithologist collects and analyses data about ducks. She is writing a program which will allow her to determine if a duck is stressed.

Here is the program, written in PYTHON:

#ask for and get the number of quacks

quacks = int(input("Please enter the number of quacks: "))

if quacks >=10:

sickDuck()

else:

healthyDuck()

Using your own creativity, design the sickDuck and healthyDuck functions.

dreambig

Task 2

The following code segment is being tested as part of a game about dreams and nightmares.

It generates a random number in the range 1 to 10.

If the number is greater or equal to 8, it means a dream occured

Else if the number is greater than or equal to 4, it means a nightmare occured

Else both a dream and a nightmare occured!

#import the random library file

import random

#generate a random number and assign to a variable

rand = random.randint(1,10)

#evaluate the random number

if rand>=8:

print("Welcome to the world of dreams!")

print("Let your imagination lift you high!")

elif rand>=4:

print("Welcome to the world of nightmares!")

print("Let your imagination drown you in despair!")

else:

print("Welcome to the world of dreams!")

print("Let your imagination lift you high!")

print("Welcome to the world of nightmares!")

print("Let your imagination drown you in despair!")

print("End of program!")

Design 2 functions, dreams() and nightmares() to handle the tasks of displaying the output.

Rewrite the above program to call the functions when necessary.

stock

Task 3 - Tricky!

A statistician needs to compare 2 randomly generated numbers. Here is an attempt at writing a program.

import random

def start():

rand1 = random.randint(-5,5)

rand2 = random.randint(-5,5)

#compare the 2 numbers

if rand1 == rand2:

display1()

elif rand1 > rand2:

display2()

else

display3()

 

def end():

print("End of program")

 

def main():

start()

end()

 

#####call the main function#####

main()

What do you think the purpose of the 3 display functions is?

Design the functions using your own ideas.

Test your program and see if it works as you expect.