Write a short program with a function called bigger

Assignment Help Python Programming
Reference no: EM133091489

Functions and Classes

Exercises

Question 1: Write a program with a function called abbathat takes two strings as input (a and b), and returns a string which consists of:
• The string a,
• Then the string b,
• Then the string b again,
• And finally the string a again.
So for example, if we passed in the strings 'a' and 'b' the function would return 'abba', andif we passed in the strings 'cat' and 'dog', the function would return 'catdogdogcat'. In your program make a few calls to the function and print out the returned value to ensure it's all working properly.

Question 2: Write a program with two functions called find_firstand find¬_all, each of which take two strings called source and target.as input.
The first_first function takes the two strings and input and returns the location of the target string within the source string as an integer - so for example, if we passed called find_firstwith the source string of "Roses are red, violets are blue" and a target string of "are", it would return the value 6 because that's the index of the first occurrence of the target string within the source string.
The find_allfunction works the same as the find_firstfunction, but it returns a list of all the locations of the target string within the source string - again, passing in "Roses are red, violets are blue" would return the list [6, 23] because the two instances of the substring start at those indices in the source string.
As before, make a few calls to the functions and print out the return values to ensure everything's working correctly.

Question 3: Write a short program with a function called bigger that takes two numbers as input parameters and returns the bigger of the two numbers. For example, if we called bigger(3, 5) it would return the value 5 because 5 is more than 3.
Once you have that working, write a function called biggest that takes three numbers and returns the biggest of the three values. An easy way to accomplish this is by using your bigger function within your biggest function - if you do it this way then it can be accomplished in just a single line of code!

Question 4: Write a program containing a function called swap that takes two parameters called first and second. You should be able to run the function passing it these two parameters and returning a 'swapped' version of these values. So, for example you could execute the function like this:
a = 123
b = 456
a, b = swap(a, b)
print(a, b) # Prints 456, 123 (i.e. the a variable now has b's value, and b now has a's value)

It's perfectly possible to do this with a single line of code within your function.

Question 5: Consider the following class definition:
class Vector:
def __init__(self,x,y):
self.x = x
self.y = y

def add1(self, v):
self.x = self.x + v.x

self.y = self.y + v.y

def add2(v1,v2):
v = Vector(0,0)
v.x = v1.x + v2.x
v.y = v1.y + v2.y
return v

def dot_product(v1,v2):
return v1.x*v2.x + v1.y*v2.y

def print(self):
print('({},{})'.format(self.x,self.y))

Save the class definition in a file and try to understand what this class is for and how it can be used. Run the code and experiment with the class definition.

Reference no: EM133091489

Questions Cloud

Global environmental problems : Why do governments have so much difficulty agreeing with each other on the measures against global environmental problems?
What is corruption : What is corruption? Is it a problem?
Organisation of a well performing information system : You have been asked to conduct a system evaluation. In doing so, you identify some system shortfalls for the payroll department in the organisation.
Prepare all the necessary journal entries on february : Assume the depreciable asset was sold February 1, 2021 for $36,000. Prepare all the necessary journal entries on February 1, 2021 to record this sale
Write a short program with a function called bigger : Write a program containing a function called swap that takes two parameters called first and how it can be used. Run the code and experiment
Calculate wacc and determine the value of the firm : Depreciation is 14.5% of EBIT, changes in NWC is 11% of EBIT and capital expenditures are 20% of EBIT. Calculate WACC and determine the value of the firm
Major public policy issues in pricing : What are the major public policy issues in pricing? Does Amazon practice predatory pricing or just good competitive marketing?
Calculate one year depreciation : An asset cost $120,000 and has a useful life of 6 years or 8,000 units of production, and no residual value. Calculate one year's depreciation
Discuss how marketing research : Select one element of the Marketing mix and discuss how marketing research could help that area.

Reviews

Write a Review

Python Programming Questions & Answers

  Design and write a program that will allow a waitperson

Design and write a program that will allow a waitperson to take orders for each table, and calculate and display the per-person total, per-table total.

  Hyperloop network operations

Hyperloop network operations Assignment Help and Solution - Write a single pseudo code for the route estimator application based on the requirements

  What is the turning angle of the robot

Introduction To Computer Vision - What is the turning angle of the robot and What is the current stage of the robot

  Write an algorithm for pseudo random number generator

Question - Write an algorithm for pseudo random number generator

  Create a new table called custsum that you also write to xyz

create a new table called custSum that you also write to xyz.db, and that has the following characteristics. This table should have one row per customer record.

  Create a jes function

Create a JES function named level1() and include the relevant behaviours. Specifically, in this level, you only need to detect just one character from the text and the text is only in a single row.

  Calculate distance traveled through speed and time driving

You need the code below to calculate Distance Traveled through Speed & Time Driving Versus Miles Per Gallon.

  Find the distance using any of the pair of co-ordinates

What do you do for example if you want to find the distance using any of the pair of co-ordinates using the formulae L=sqrt.

  How to create an output label and associate

How to create an output label and associate it with a StringVar object. Name your Python program name_address_GUI.py

  Write program to determine whether a triangle is right

HS1031 Introduction to Programming Assignment, Holmes Institute, Australia. Write a program triangle.py to determine whether a triangle is a 'right triangle'

  Data cleansing and integration assignment

Data Cleansing and Integration Assignment Help and Solution Auditing and Cleansing the Job dataset and Integrating the Job datasets

  Write a test program that creates two rectangle objects

A constructor that creates a rectangle with the specified width and height. The default values are 1 and 2 for the width and height, respectively.

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