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
Lines changed: 13 additions & 0 deletions
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))
Lines changed: 35 additions & 0 deletions
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+
Lines changed: 22 additions & 0 deletions
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+
Lines changed: 22 additions & 0 deletions
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+
Lines changed: 15 additions & 0 deletions
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+
Lines changed: 19 additions & 0 deletions
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+
Lines changed: 21 additions & 0 deletions
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]))
Lines changed: 35 additions & 0 deletions
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+
Lines changed: 23 additions & 0 deletions
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+
Lines changed: 14 additions & 0 deletions
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))

0 commit comments

Comments
 (0)