Write a function to evaluate returns the area

Assignment Help Python Programming
Reference no: EM131549076

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

Reference no: EM131549076

Questions Cloud

Discuss the knowledge of research principles : Since this assessment is written in report format, it needs to be presented in professional layout, including: title page, executive summary, table of contents.
The market yield on its otherwise similar straight debt : The coupon interest rate on a firm's convertibles is generally set higher than the market yield on its otherwise similar straight debt.
What is the gain from leverage-value of the levered firm : What is the gain from leverage? What is the value of the levered firm.
Why were the dutch able to take over new sweden : Who agreed on July 1, 1676 to split the land along an indefinite line from Little Egg Harbor to the northwest corner? Why was this done?
Write a function to evaluate returns the area : Write a function called area_triangle() that takes the height and width of a triangle and returns the area
What are the different forms of management education : What are the different forms of management education? In your opinion, can they be substituted by training or on the job experiences? Why or why not?
Identify and describe the hso : Identify and Describe the HSOs (Health Service Organizations) departments, team (workgroups); cluster of workgroups
Data collection and statistical tools : Shewhart's Theory for Statistical Process Control (SPC) requires a change in thinking from error detection to error prevention and has a number of benefits
An important contribution in our society : Write an essay on a NJ place which has made an important contribution in our society...i.e. politics, entertainment, religion etc.

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd