Skip to content

Commit c687cbb

Browse files
committed
additional exercises
Signed-off-by: Adam McNicol <[email protected]>
1 parent f9b30ec commit c687cbb

File tree

71 files changed

+2407
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+2407
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#16-01-2012
2+
#additional exercise 1
3+
#sample solution
4+
5+
print("Number Addition")
6+
print("This program asks for three numbers and then outputs the total")
7+
print()
8+
num1 = int(input("Please enter a number: "))
9+
num2 = int(input("Please enter a second number: "))
10+
num3 = int(input("Please enter a third number: "))
11+
print()
12+
ans = num1 + num2 + num3
13+
print("The total of {0} + {1} + {2} is {3}.".format(num1,num2,num3,ans))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#16-01-2012
2+
#additional exercise 10
3+
#sample solution
4+
5+
import math
6+
7+
print("Plane Distance")
8+
print("This program calculates how far north and east a plane has travelled")
9+
print("when given the number of degrees from north and the distance travelled in")
10+
print("a straight line.")
11+
print()
12+
degreesFromNorth = float(60)
13+
distanceInStraightLine = float(20)
14+
#north distance travelled
15+
#work out the sine angle
16+
sineDegrees = 90 - degreesFromNorth
17+
#convert to degrees to radians
18+
sineRadians = math.radians(sineDegrees)
19+
#work out sine
20+
sine = math.sin(sineRadians)
21+
#distance north travelled
22+
distanceNorth = round(sine * distanceInStraightLine,2)
23+
#
24+
#distance east travelled
25+
#convert to radians
26+
sineRadians = math.radians(degreesFromNorth)
27+
#work out sine
28+
sine = math.sin(sineRadians)
29+
#distance east travelled
30+
distanceEast = round(sine * distanceInStraightLine,2)
31+
print()
32+
print("The plane has travelled {0} north.".format(distanceNorth))
33+
print("The plane has travelled {0} east.".format(distanceEast))
34+
35+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#16-01-2012
2+
#additional exercise 11
3+
#sample solution
4+
5+
import math
6+
7+
print("Ladder Height")
8+
print("This program calculates how far a ladder reaches up a wall")
9+
print("when given the number of degrees the ladder makes with the horizontal")
10+
print("and its distance from the wall.")
11+
print()
12+
degreesFromHorizontal = float(68)
13+
distanceFromWall = float(1.5)
14+
#degrees in radians
15+
radiansFromHorizontal = math.radians(degreesFromHorizontal)
16+
#tan
17+
tan = math.tan(radiansFromHorizontal)
18+
wallReach = round(tan * distanceFromWall,2)
19+
print("The ladder reaches {0} up the wall.".format(wallReach))
20+
21+
22+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#16-01-2012
2+
#additional exercise 12
3+
#sample solution
4+
5+
import math
6+
7+
print("Balloon Height")
8+
print("This program calculates how high a balloon has reached")
9+
print("when given the number of degrees the string makes with the horizontal")
10+
print("and the length of the string")
11+
print()
12+
degreesFromHorizontal = float(70)
13+
lengthOfString = float(120)
14+
#degrees in radians
15+
radiansFromHorizontal = math.radians(degreesFromHorizontal)
16+
#sine
17+
sine = math.sin(radiansFromHorizontal)
18+
balloonHeight = round(sine * lengthOfString,2)
19+
print("The balloon is {0} in the air.".format(balloonHeight))
20+
21+
22+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#16-01-2012
2+
#additional exercise 13
3+
#sample solution
4+
5+
print("Quote Formatter")
6+
print("This program displays a given quote in different formats")
7+
print()
8+
quote = input("Please enter a quote to format: ")
9+
print(quote)
10+
print(quote.upper())
11+
print(quote.lower())
12+
print(quote.capitalize())
13+
print(quote.title())
14+
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#16-01-2012
2+
#additional exercise 14
3+
#sample solution
4+
5+
print("Quote Formatter")
6+
print("This program displays a given quote in different formats")
7+
print()
8+
quote = input("Please enter a quote to format: ")
9+
print(quote)
10+
print(quote.upper())
11+
print(quote.lower())
12+
print(quote.capitalize())
13+
print(quote.title())
14+
replaceWord = input("Which word in the quote would you like to replace: ")
15+
replaceWith = input("Please enter the word to replace it with: ")
16+
print("The original quote is: {0}".format(quote))
17+
print("The new quote is: {0}".format(quote.replace(replaceWord,replaceWith)))
18+
19+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#16-01-2012
2+
#additional exercise 15
3+
#sample solution
4+
5+
print("Quote Formatter")
6+
print("This program displays a given quote in different formats")
7+
print()
8+
quote = input("Please enter a quote to format: ")
9+
print(quote)
10+
print(quote.upper())
11+
print(quote.lower())
12+
print(quote.capitalize())
13+
print(quote.title())
14+
replaceWord = input("Which word in the quote would you like to replace: ")
15+
replaceWith = input("Please enter the word to replace it with: ")
16+
print("The original quote is: {0}".format(quote))
17+
print("The new quote is: {0}".format(quote.replace(replaceWord,replaceWith)))
18+
startLetter = int(input("Which letter would you like to start your quote from: "))
19+
stopLetter = int(input("Which letter would you like to finish your quote before: "))
20+
print("The original quote is: {0}".format(quote))
21+
print("The new quote is: {0}".format(quote[startLetter:stopLetter]))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#16-01-2012
2+
#additional exercise 11
3+
#sample solution
4+
5+
import math
6+
7+
print("Plane Distance")
8+
print("This program calculates how far north and east a plane has travelled")
9+
print("when given the number of degrees from north and the distance travelled in")
10+
print("a straight line.")
11+
print()
12+
degreesFromNorth = float(input("Please enter the number of degrees from north: ")
13+
distanceInStraightLine = float(input("Please enter the distance travelled in a straight line: "))
14+
#north distance travelled
15+
#work out the sine angle
16+
sineDegrees = 90 - degreesFromNorth
17+
#convert to degrees to radians
18+
sineRadians = math.radians(sineDegrees)
19+
#work out sine
20+
sine = math.sin(sineRadians)
21+
#distance north travelled
22+
distanceNorth = round(sine * distanceInStraightLine,2)
23+
#
24+
#distance east travelled
25+
#convert to radians
26+
sineRadians = math.radians(degreesFromNorth)
27+
#work out sine
28+
sine = math.sin(sineRadians)
29+
#distance east travelled
30+
distanceEast = round(sine * distanceInStraightLine,2)
31+
print()
32+
print("The plane has travelled {0} north.".format(distanceNorth))
33+
print("The plane has travelled {0} east.".format(distanceEast))
34+
35+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#16-01-2012
2+
#additional exercise 12
3+
#sample solution
4+
5+
import math
6+
7+
print("Distance Climbed")
8+
print("This program calculates how much height is gained when travelling a")
9+
print("given distance and an incline angle")
10+
print()
11+
distanceTravelled = float(input("Please enter the distance travelled: "))
12+
inclineAngle = float(input("Please enter the incline angle: "))
13+
#convert degrees to radians
14+
inclineRadians = math.radians(inclineAngle)
15+
#get the sine
16+
sine = math.sin(inclineRadians)
17+
#calculate height
18+
height = round(distanceTravelled * sine,2)
19+
print()
20+
print("The distance travelled horizontally is {0}".format(height))
21+
22+
23+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#16-01-2012
2+
#additional exercise 2
3+
#sample solution
4+
5+
print("Number Multiply and Divsion")
6+
print("This program asks for three numbers, adds the first two together")
7+
print("then divides the total by the third number before displaying the answer")
8+
print()
9+
num1 = int(input("Please enter a number: "))
10+
num2 = int(input("Please enter a second number: "))
11+
num3 = int(input("Please enter a third number: "))
12+
print()
13+
ans = (num1 + num2) / num3
14+
print("The total of ({0} + {1}) / {2} is {3}.".format(num1,num2,num3,ans))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#16-01-2012
2+
#additional exercise 3
3+
#sample solution
4+
5+
print("Dividing")
6+
print("This program asks for two numbers and then divides them,")
7+
print("it then displays the number of times one goes into the other and")
8+
print("the remainder")
9+
print()
10+
num1 = int(input("Please enter a number: "))
11+
num2 = int(input("Please enter a second number: "))
12+
print()
13+
intans = num1 // num2
14+
remainder = num1 % num2
15+
print("{0}/{1} = {2} remainder {3}.".format(num1,num2,intans,remainder))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#16-01-2012
2+
#additional exercise 4
3+
#sample solution
4+
5+
("Dividing - improved")
6+
print("This program asks for two numbers and then divides them,")
7+
print("it then displays the number of times one goes into the other")
8+
print()
9+
num1 = int(input("Please enter a number: "))
10+
num2 = int(input("Please enter a second number: "))
11+
print()
12+
#many ways to do this
13+
intans = num1 // num2
14+
#intans = int(num1/num2)
15+
#intans = int(round(num1/num2,0))
16+
remainder = num1 % num2
17+
print("{0}/{1} = {2}.".format(num1,num2,intans,remainder))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#16-01-2012
2+
#additional exercise 5
3+
#sample solution
4+
5+
print("Volumes")
6+
print("This program asks for dimensions of both a fridge and a lift")
7+
print("then it works out how much volume remains inside the lift once the")
8+
print("fridge is inside.")
9+
print()
10+
liftW = float(input("Please enter the width of the lift: "))
11+
liftH = float(input("Please enter the height of the lift: "))
12+
liftD = float(input("Please enter the depth of the lift: "))
13+
print()
14+
fridgeW = float(input("please enter the width of the fridge: "))
15+
fridgeH = float(input("please enter the height of the fridge: "))
16+
fridgeD = float(input("please enter the depth of the fridge: "))
17+
print()
18+
liftV = liftW * liftH * liftD
19+
fridgeV = fridgeW * fridgeH * fridgeD
20+
liftSpace = liftV - fridgeV
21+
print("The lift's volume is {0}.".format(liftV))
22+
print("The fridge's volumne is {0}.".format(fridgeV))
23+
print("The lift has {0} of remaining space.".format(liftSpace))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#16-01-2012
2+
#additional exercise 6
3+
#sample solution
4+
5+
print("Foreign Currency")
6+
print("This program asks for your holiday money (in pounds)")
7+
print("and the current exchange rate then displays the number of")
8+
print("euros you will recieve.")
9+
print()
10+
holidayMoney = int(input("Please enter amount of money you will take on holiday: "))
11+
exchangeRate = float(input("Please enter the current pound-euro exchange rate: "))
12+
print()
13+
#this is a div calculation
14+
euroHolidayMoney = holidayMoney//exchangeRate
15+
print("You will receive {0} Euros for your holiday.".format(euroHolidayMoney))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#16-01-2012
2+
#additional exercise 7
3+
#sample solution
4+
5+
print("Foreign Currency")
6+
print("This program asks for your holiday money (in pounds)")
7+
print("and the current exchange rate then displays the number of")
8+
print("euros you will recieve.")
9+
print()
10+
holidayMoney = int(input("Please enter amount of money you will take on holiday: "))
11+
exchangeRate = float(input("Please enter the current pound-euro exchange rate: "))
12+
print()
13+
#this is a div calculation
14+
euroHolidayMoney = holidayMoney//exchangeRate
15+
print("You will receive {0} Euros for your holiday.".format(euroHolidayMoney))
16+
print("This will be made up of:")
17+
euro50s = int(euroHolidayMoney // 50)
18+
#this is a mod calculation
19+
remainingEuros = euroHolidayMoney % 50
20+
euro20s = int(remainingEuros // 20)
21+
remainingEuros = remainingEuros % 20
22+
euro10s = int(remainingEuros // 10)
23+
remainingEuros = remainingEuros % 10
24+
euro5s = int(remainingEuros // 5)
25+
remainingEuros = remainingEuros % 5
26+
print("{0} 50 Euro notes.".format(euro50s))
27+
print("{0} 20 Euro notes.".format(euro20s))
28+
print("{0} 10 Euro notes.".format(euro10s))
29+
print("{0} 5 Euro notes.".format(euro5s))
30+
print("and {0} in coins.".format(remainingEuros))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#16-01-2012
2+
#additional exercise 8
3+
#sample solution
4+
5+
import math
6+
7+
print("Circles")
8+
print("This program asks the radius of a circle and")
9+
print("calculates the circumference and area")
10+
11+
print()
12+
radius = float(input("Please enter the radius of the circle: "))
13+
circumference = round(2 * math.pi * radius,2)
14+
#radius**2 means radius squared
15+
area = round(math.pi * radius**2,2)
16+
print()
17+
print("The circumference of this circle is {0}.".format(circumference))
18+
print("The area of this circle is {0}.".format(area))
19+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#16-01-2012
2+
#additional exercise 9
3+
#sample solution
4+
5+
import math
6+
7+
print("Circular Swimming Pool")
8+
print("This program calculates the volume of a circular swimming pool")
9+
print()
10+
diameter = float(input("Please enter the diameter of the pool: "))
11+
depth = float(input("Please enter the depth of the pool: "))
12+
radius = diameter/2
13+
#radius**2 means radius squared
14+
area = round(math.pi * radius**2,2)
15+
volume = round(area * depth,2)
16+
print()
17+
print("The volume of the swimming pool is {0}.".format(volume))
18+

0 commit comments

Comments
 (0)