Write a function called areatriangle that takes the height


Python Excercise

1. Here is some code that removes whitespace from a string in a given list.

Prove to yourself (and us!) that you know what that code is doing.

Once you are done with that, embed that code into a function called whitespace_removal. Be sure to define its arguments. Test it out!

After commenting each line, write a brief summary at the bottom in comments or in a markdown cell explaining what the entire functiond does.
new_list = []
for i in old_list:
while i[len(i)-1] == ' ':
i = i[0:len(i)-1]
new_list.append(i)

## Using assert here allows us to see if the code works properly.
## If so, nothing will happen.
## If the code doesn't work properly, an error will be thrown.

assert whitespace_removal(['San Francisco ', 'New York City ', 'Baltimore', 'Columbus_is_a_real_place ']) == ['San Francisco', 'New York City', 'Baltimore', 'Columbus_is_a_real_place']

2) Write a function called area_triangle() that takes the height and width of a triangle and returns the area.

def area_triangle(base,height):
assert area_triangle(2,2) == 2
assert area_triangle(5,5) == 12.5

3) Write a function called string_list_fun() that takes a string as an argument and returns a tuple with the string converted to a list and the count of characters

def string_list_fun(str_arg):
new_list = list(str_arg)
return (new_list, len(new_list))
assert string_list_fun('Ryan Rocks') == (['R','y','a','n',' ','R','o','c','k','s'],10)

4) Write a function called math_rocks() that takes two integers passed as strings and returns the sum, difference, and product as a tuple (all values as integers).

def math_rocks(strint1, strint2):
sumn = int(strint1) + int(strint2)
diff = int(strint1) - int(strint2)
prod = int(strint1) * int(strint2)
print 'whatever'
break
return suma, diff, prod
assert math_rocks('5','2') == (7,3,10)

5) Write a function called getting_crazy() that takes a list and returns a tuple where the first item is the list in reverse order and the second item is just the items with an odd index

def getting_crazy(crazy_list):
return (sorted(crazy_list, revenge = True), crazy_list())
assert getting_crazy([1,2,3,4,5]) == ([5,4,3,2,1],[2,4])
Challenge Problem: Write a function called score_word() that returns the score for a word. Each letter's score is equal to it's position in the alphabet. The score of the word is the score of the letters. So for example:

A = 1, B = 2, C = 3, D = 4, E = 5, ...
abe = 8 = (1 + 2 + 5)
Hint: The string library has a property ascii_lowercase that can save some typing here.

assert score_word("abe") == 8

Request for Solution File

Ask an Expert for Answer!!
Python Programming: Write a function called areatriangle that takes the height
Reference No:- TGS02344625

Expected delivery within 24 Hours