Assignments

advertisement
ICAPRG301A Classroom Checklist
Student No:
____________________________________________
Student Name:
____________________________________________
Task
Can start IDE and run simple programs
Can use indent to create blocks of code
Can write a function
Can write a loop
Can write if statements
Can use lists
Can use library functions
Can use IDE debugging
Can write a comment
Can structure an application using
functions
Can create and manipulate Strings
Student Initialled
and dated
Lecturer Initialled
and dated
Assignment B
Fizz Buzz
This is a primary school children’s game. Children count but do not say any multiple of 3,
they say Fizz instead. With multiples of 5 they say Buzz. If the number is a multiple of both
3 and 5 they say FizzBuzz. Create a function which does this.
For example fizzbuzz(20) would output
1,2,fizz,4,buzz,fizz,7,8,fizz,buzz,11,fizz,13,14,fizzbuzz,16,17,fizz,19,buzz
Note this is quite hard to do and has been used in interviews for programming jobs.
Competent programmers should be able to write this in 5 minutes.
Hint



you need if statements and modulo to do this
the order they are interpreted is important.
Don’t print directly in your function, create a variable to output so it can be changed
depending on the if statements. By doing this you are making a function which can
be used in a variety of ways (is can be printed on the console or a text file or it can
be used to help build other strings or list)
You must also complete the Program Documentation and Feedback sheet and you must
use comments in your code.
Good programmers always document their code and the processes around their code.
Even at this early stage of your learning you need to get into the habit of documenting
your code.
Your code must contain comments. At the very least you should have a header section
in your code with your name, student number, assignment number and unit code.
Assignment C
10 Green Bottles
Develop a program that creates a text file containing the words of the song 10 green bottles, exactly
like the sample. The text file is to be saved in the current directory using the name
TenGreenBottles.txt. Your program must:
1.
2.
3.
4.
Use the Python template
Use at least two functions
Most of the song should be created in a loop
Use lists and variables to help create the verses
Hints:







Creating the text file would make a good function
Most of the song is repeated with few changes, though the last verse is different. This is a
good candidate for a loop
The code to force a new line is ‘\n’
Use meaningful names for your lists and variables
There is no right answer, so long as your program prints out the correct text file and satisfies
the four requirements you have done the task.
There are many ways to do this, I will get suspicious if everyone’s code is exactly the same.
My file to do this, including the comments is 40 lines. I am sure that someone can do it in
less.
Assignment D
Magic Number Game
Develop a small working version of the Magic Number game. All displays to be in windows, not the
console. You may use EasyGUI to create the display or something similar.
In the Magic Number game the computer thinks of a number between 1 and 100. The user then
guesses a number and the computer responds with the correct response. The computer’s available
responses are:
The number is higher
The number is lower
You guessed correctly
This continues until the user gets the right answer. The number of guesses is then displayed. Your
program must be able to handle the user typing in characters not numbers. How you handle this is
up to you but it should not crash your program.
Hints:





There is a library called random to generate the number. It is pretty easy to use. Google it
to see how it works
Use Enter boxes and Message boxes from Easy GUI for your displays
You should use try except when getting information from the user who might not type in
what you expect. Your program should just accept this and move on. A good way to do this
would be to create a function called safe_enter_box which will return the correct number in
the right range or else a standard response like 0.
Try to write this as a well-structured program.
You might want to use the endless loop structure with a break if the user guesses the correct
number.
Program Documentation and Feedback
Name:
Student Number:
Program started
Date:
Time:
Testing of initial code
Date:
Time:
Date:
Time:
Date:
Time:
What needs changing:
Final code done
What could be added later:
Comments:
What are you proud of:
What could be done better:
Program finished
Download