Part 1: Simple Functions

Challenge 1

Begin by copying the following program into a new file.

# these are the basic arithmetic functions you will be using for this challenge

# function: add

# input: two integers/floats

# processing: adds the two supplied values

# output: returns the sum (integer/float)

def add(a,b):

return a b

Don't use plagiarized sources. Get Your Custom Essay on

Functions program | Urgent Essays

Get an essay WRITTEN FOR YOU, Plagiarism free, and by an EXPERT!

# function: sub

# input: two integers/floats

# processing: subtracts the two supplied values

# output: returns the difference (integer/float)

def sub(a,b):

return a-b

# function: mult

# input: two integers/floats

# processing: multiplies the two supplied values

# output: returns the product (integer/float)

def mult(a,b):

return a*b

# function: div

# input: two integers/floats

# processing: divides the first value by the second value

# output: returns the result (float)

def div(a,b):

return a/b

# function: sqrt

# input: one integer/float

# processing: computes the square root of the supplied value

# output: returns the square root (float)

def sqrt(a):

return a**0.5

# function: square

# input: one integer/float

# processing: raises the supplied integer/float to the 2nd power

# output: returns the square (integer/float)

def square(a):

return a**2

Your task is to translate some simple expressions into function calls. Here are the rules:

You can only fill in the blank with a single line of code

You cannot use any math operations (i.e. , -, /, *, // or % are strictly prohibited)

You cannot use any print statements

You cannot reduce your terms (i.e. if you are asked to translate 1 2 3 you can’t simply add these together yourself and supply the number 5 to the program)

The only thing you can use are calls to the functions above, in any order

You cannot use any calls to any functions other than the ones above (i.e. input, len, etc. are all prohibited)

Here is an example to get you started:

# translate this expression:

# y = mx b

m = 3

x = 2

b = 5

y = __________

print(y) # you should expect 11 as your outputYou can solve this by create a function call that looks like the following:

y = add(mult(m,x),b)Challenge 1: Expression 1# translate this expression:

# x = (3-4) (1*2)

x = __________

print(x) # you should expect 1 as your outputChallenge 1: Expression 2# translate this expression:

# x = 5 1 7 9 13 12

x = __________

print(x) # you should expect 47 as your outputChallenge 1: Expression 3# translate this expression:

# x = (5 1) / (7 2 3)

x = __________

print(x) # you should expect 0.5 as your outputChallenge 1: Expression 4# compute the distance between these two points

# point 1

x1 = 0

y1 = 0

# point 2

x2 = 100

y2 = 100

distance = ______________________

print (distance) # you should expect 141.4213562373095 as your outputRecall that the distance formula is defined as follows:

Challenge 2

Write two functions called ‘maximum’ and ‘minimum’ – these function should accept two arguments and return the larger/smaller of the two supplied values. For the purpose of this program you can always assume that the arguments being supplied are numeric. Describe your function using IPO notation. Your program should work perfectly with the following code:

a = 5

b = 10

c = 15

d = 20

e = 20

ans1 = maximum(a,b)

ans2 = maximum(a,c)

ans3 = maximum(a,d)

print (ans1,ans2,ans3) # 10 15 20

ans4 = minimum(d,c)

ans5 = minimum(d,b)

ans6 = minimum(d,a)

print (ans4,ans5,ans6) # 15 10 5

ans7 = maximum( maximum(a,b), maximum(c,d) )

print (“The biggest is:”, ans7)

ans8 = maximum(d,e) # d and e are the same, so either is considered the maximum

ans8 = minimum(d,e) # d and e are the same, so either is considered the minimum

print(ans8, ans8) # 20 20Challenge 3

Write a function called ‘valid_date’ which accepts two arguments – a month and a day (both integers, will always be integers). Test to see if the date being described is valid or not. If the date is valid your function should return a True value, and if it is not it should return a False value. For the purpose of this program you can assume February has 28 days. Describe your function using IPO notation. Your program should work perfectly with the following code:

print (valid_date(99,1)) # False

print (valid_date(1,99)) # False

print (valid_date(99,99)) # False

print (valid_date(-99,1)) # False

print (valid_date(1,-99)) # False

print (valid_date(-99,-99)) # False

print (valid_date(9,25)) #True

print (valid_date(10,15)) # True

print (valid_date(11,31)) # False

print (valid_date(2,28)) # True

print (valid_date(2,29)) # FalseChallenge 4

# write a function called ‘simple_sort_version1’ that accepts two values. you can assume

# that your three values will always be the same data type (all ints, all floats or all strings).

# sort these two values in ascending order and return them in that order.

# you may use any function that you’ve written so far in this assignment if you’d like to (maximum, minimum, etc)

# your function should work perfectly with the following lines of code

a,b = simple_sort_version1(10,20)

print (a,b) # 10 20

a,b = simple_sort_version1(20,10)

print (a,b) # 10 20

a,b = simple_sort_version1(30,30)

print (a,b) # 30 30Challenge 5

# next, write a new function called ‘simple_sort_version2’ that accepts three values. you can assume

# that your three values will always be the same data type (all ints, all floats or all strings).

# sort these values in ascending order and return them.

# you may use any function that you’ve written so far in this assignment if you’d like to (simple_sort_version1, maximum, minimum, etc)

# your function should work perfectly with the following lines of code

a,b,c = simple_sort_version2(10,20,30)

print (a,b,c) # 10 20 30

a,b,c = simple_sort_version2(10,30,20)

print (a,b,c) # 10 20 30

a,b,c = simple_sort_version2(30,20,10)

print (a,b,c) # 10 20 30

a,b,c = simple_sort_version2(30,20,20)

print (a,b,c) # 20 20 30

Why Work with Us

Top Quality and Well-Researched Papers

We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.

Professional and Experienced Academic Writers

We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.

Free Unlimited Revisions

If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.

Prompt Delivery and 100% Money-Back-Guarantee

All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.

Original & Confidential

We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.

24/7 Customer Support

Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.

Try it now!

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.

Essays

No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.

Admissions

Admission Essays & Business Writing Help

An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.

Reviews

Editing Support

Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.

Reviews

Revision Support

If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.