Lesson 1 – Challenge Questions

Here are a few challenges that you should be able to complete based on the knowledge you have currently.

Challenge 1.1

Objective

Write a function that takes a text string (i.e. text_var = "Hello World") prints it back out with a border above and below it.

Hints

  • You need to count the number of characters in a string, use the len(text_var) function
  • Use the equal sign (=) for the border
  • The function should create the same number of = characters as the number of characters in the string

Solution

Here are a few examples:

border_text("Hello World") # will return
===========
Hello World
===========


border_text("Hello Mike") # will return
==========
Hello Mike
==========


border_text("Hello") # will return
=====
Hello
=====

Challenge 1.2

Objective

Write a set of Python statements that can find the length of each side of this right triangle.

Triangle

Given the following:

  • Angle C is 90 degrees
  • Angle B is 54 degrees
  • Side a has a length of 4 inches

Hints

  • Use the Math library
  • Use basic Trigonometry (if you need help, ask)
  • You will probably need to convert degrees to radians (there’s a function for that)

Challenge 1.3

Objective

Create and print Pascal’s triangle by showing 10 levels. Have each level’s list in one big list (i.e. pascals_triangle = [[1], [1, 1], [1, 2, 1], [etc.]]). You cannot just write [1,3,3,1] in your code, you must find it through an algorithm.

You can append a list after you have created it. For example,

pascals_triangle = [[1]]

pascals_triangle.append([1,1])
pascals_triangle.append([1,2,1])

print(pascals_triangle)

Pascal's Triangle

Solution

pascals_triangle[0] # Should return
[1]
pascals_triangle[1] # Should return
[1, 1]
pascals_triangle[2] # Should return
[1, 2, 1]

# All the way to
pascals_triangle[9] # Should return
[1, 9, 36, 84, 126, 126, 84, 36, 9, 1]