Python Assignment

Order Description

1. Preparation

Before your workshop class:

• Read all of this document.

• Review the lecture notes sections 1 to 8.

• Complete the Griffith Science Laboratory Induction if you have not done so in the last year.

• Bring some paper (a print-out of this document is best) and writing implements.

• Bring a storage device, such as a portable hard drive and cable, or a USB drive.

2 Pre-workshop questions (2 marks)

Complete these questions in writing before the start of the workshop. They will be marked early in the workshop.

1. My workshop tutor’s name is .

2. What is the expression that starts the interactive help feature?

3. What is the expression that terminates the Python REPL?

4. What is the function that reports the type of an expression?

5. Complete this table. Confirm your answers using the Python REPL.

6. Write Python expressions that will calculate the following, and use the REPL to calculate the value of the answer.

(a) What is the volume of a cube that has edges that are 1.2 metres long?

expression: value:

(b) How many whole weeks are there in October?

expression: value:

(c) What is the molecular weight of formaldehyde (CH2O)? (Atomic weights: H = 1.00784; C = 12.0096; O = 15.99903)

expression: value:

(d) A rugby team has 15 players. A bus company has small buses that can carry 10 passengers, and big buses that can carry 38 passengers. A rugby tournament organiser can afford to hire 3 big buses and 2 small buses. How many teams can be taken to the tournament?

expression: value:

3 Workshop activities

At any stage, when you are stuck, ask your tutor!

3.1 Griffith Sciences Lab Induction

Please show us that you have completed this induction within the last year, by workshop 2. If you complete the rest of the activities with time to spare, you can complete the test at the end of this workshop.

3.2 Create and run an interactive script in PyCharm (1 mark)

For this you must use the PyCharm IDE, either:

• on the lab PC, using Windows or Mac; or• on your own laptop, if you have already installed PyCharm.

Steps:

1. Open the PyCharm IDE.

2. Make a new project:

(a) Choose menu item File ▶ New Project....

(b) Edit the name and location of the project so that it is called Hello and saved on either:

• your network storage drive (typically called H:); or

• your personal storage device that you brought with you.

(c) Click Create.

3. Using menu item File ▶ New... create a new Python File in your project and name it hello.py.

4. Type in the following program:

name = input("What’s your name? ")

print("Hello, ", name)

5. Save it, use menu item Run ▶ Run..., and choose hello.py to run your program.

6. Your program will run in a pane at the bottom of the window, prompting you to enter your name.

When your screen shows that you have run your program successfully, show your tutor for a mark.

3.3 Problem 1 (1 mark)

For this and the next problem, you may choose any tools you like, so long as the program is written in Python 3.

Problem: A painter needs to estimate how much paint is needed for a rectangular wall. Write a program that asks the user for the width of the wall in metres, the height of the wall in metres, and the volume of paint required in litres per square metre. Print the total litres required.

For example, the program should look like this when run.

Width of wall (m): 4.5Height of wall (m): 2.3Litres per square metre: 0.3Litres required = 3.105

When your screen shows that you have run your program successfully, show your tutor for a mark. If you get stuck, as always ask for help. If you run out of time show your tutor what you have for possible part marks.  

3.4 Problem 2 (2 marks)

Problem: A rugby team has 15 players. A bus company has small buses that can carry 10 passengers, and big buses that can carry 38 passengers. Write a program that the tournament organiser can use to calculate how many full teams can be carried in input numbers of small and large buses.

For example, the program should look like this when run.

How many big buses? 3How many small buses? 2Number of teams = 8

When your screen shows that you have run your program successfully, show your tutor for a mark. If you run out of time show your tutor what you have for possible part marks.  

4 After the workshop

• You have created programs that might be useful to refer back to in future workshops. Make sure that you will have that work in the future. One copy is not enough for at IT professional. You should have at least 2 copies:

1. on your Griffith network storage drive; and

2. on your portable storage device.