Tutorial 1¶
Question 1¶
A time t
in seconds can be converted to days, hours, minutes and seconds using integer division:
Divide
t
by 60; sett
to the quotient and call the remainders
.Divide
t
by 60; sett
to the quotient and call the remainderm
.Divide
t
by 24; setd
to the quotient and call the remainderh
.
Calculate the number of days, hours, minutes and seconds in one million seconds. Display the result as follows:
1000000 seconds is xx days H:M:S
Question 2¶
Iodine-131 is a radioisotope with a half-life \(t_\mathrm{half} = 8.02\) days.
Use the equation \(r = \left(\frac{1}{2}\right) ^ {1/t_\mathrm{half}}\) to calculate the daily decay rate (i.e. the proportion of a sample of Iodine 131 that decays in one day).
A sample of radioactive material containing Iodine-131 has an activity of \(1.67 \times 10^{12}\) Becquerels. Write a program which calculates the number of days it takes for the sample to reach an activity of \(10000\) Becquerels.
Print the activity of the sample once every 7 days.
Question 3¶
We can calculate how many digits there are in a number by repeatedly dividing by 10 until the number is less than one.
Write peudo-code for this calculation.
Write a Python program to implement it, displaying the result in the format
1234 has 4 digits.
Test your program with a variety of numbers.
Extend your program so that it works for negative numbers.
Question 4 (The Collatz Problem)¶
Given a positive integer n
, the Collatz Operation is defined as follows:
If the number is even, divide it by two
If the number is odd, triple it and add one
Repeatedly applying the Collatz Operation results in a sequence of integers which eventually reaches the number 1.
Write a program which generates the Collatz Sequence for a given positive integer \(n\).
For example, if \(n = 5\) then your program should produce the following:
5
16
8
4
2
1
Given a positive integer \(n\), define the Collatz Number to be the length of the Collatz Sequence for \(n\). For example, the Collatz number of 5 is 6.
Write a program which calculates and prints the Collatz number of a given number \(n\). For example, if \(n=5\) your program should print
The Collatz number of 5 is 6
.
Write a program which finds the smallest number \(n\) whose Collatz Number is greater than 200.