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

  Asign true to the variable has_dups

Asign True to the variable has_dups if the string s1 has any duplicate character (that is if any character appears more than once) and False otherwise

  Code a console-based program in python

CP1404/CP5632 2016 SP2/22/52 Assignment - Shopping List 1.0. You are to plan and then code a console-based program in Python 3, as described in the following information and sample output. This assignment will help you build skills using selection,..

  Develop program which reads data file containing information

In this assignment you will write a program which reads a data file containing information in different formats, validates this data, and prints out a report incorporating this data.

  Modify the caesar cipher program you completed

In this project, you will be modifying the Caesar Cipher program you completed earlier in the semester.

  How many cents for each paper

Using Tkinter for cents Program, find the How many cents for each Paper

  Design an application in python

Design an application in Python- The application would generate a set of 100 integers in a random manner in the range of 50 to 150 including both the numbers in the range

  Write python program isosceles tri equilateral tri rectangle

Write python program Isosceles Tri Equilateral Tri Rectangle, Write another "driver" script called project1.py which imports the polygon.py module, reads an input file of polygonal data and writes another file of areas and perimeters.

  Development on windows and linux systems

develop a simple, data-intensive application in Python - Data Analysis of a Document Tracker

  Develop and test a python program

develop and test a python program to track student marks in the various assignments in a given unit of study. The time allocated for this project is 10 weeks.

  Create a ride share simulator assignment

Create a ride share simulator assignment. In this particular function, I am trying to create a list of the drivers in a Driver Class that are currently listed as idle. Since they are idle, I can then match them up with an awaiting rider. The assignme..

  You will define an operation on positive integers called

you will define an operation on positive integers called twiddle which consists of summing the squares of the digits of

  Find the number of vowels in the string

Using list and one definition for find the Number of vowels in the String.

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