Question

# Simple python Question. ============================ Usinginput(),ascertain whether or not a user wants to convert fahrenheit to...

# Simple python Question.

============================

  1. Usinginput(),ascertain whether or not a user wants to convert fahrenheit to celsius, or celcius to farenheit. Then have your python script do so, and output the answer.

  2. Create a ​function​ called question_2 to calculate the sum of 2 given numbers, if the values are equal, then return thrice of their sum.

  3. Create a ​function ​called question_3​ ​that accepts 3 arguments. The function will compare the three arguments, and return the highest value.

  4. Create a ​function​ called question_4​ ​that accepts 2 arguments. The function will compare the two arguments, and returns only the 2nd argument’s value, only if the 2nd argument is more than double the 1st argument’s value.

  5. When defining a function, you are able to call that same function inside of its own definition. This creates a “stack” of function calls known as recursion. One very important step to using a recursive function is known as the “base case,” and is required so that the function does not infinitely call itself during run time. (You may recall me programming our turtle to do something X amount of times using this technique).

    -Create a ​function called facto_compute ​that computes the factorial of your argument “n”. Then using comments in your code, explain the base case, and explain step by step the journey of facto_compute(3).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#function that takes temprature and flag
#of type Boolean.
#if it is True that menas convert temprature in fahrenheit to celsius
#otherwise convert temprature in celsius to fahrenheit
#it returns the respective converted temprature
def question_1(temp,flag):
   if(flag == True):
       temp_cel = (temp - 32) / 1.8
       return temp_cel
   else:
       temp_fahr = (temp * 1.8) + 32
       return temp_fahr

#function that returns the sum of 2 given numbers
#returns thrice of sum if 2 nums are equal
def question_2(one, two):
   add = one + two
   if(one == two):
       return add*3
   else:
       return add

#function that retuns maximum of three values
def question_3(one, two, three):
   if(one > two and one > three):
       return one
   elif(two > one and two >three):
       return two
   else:
       return three
#function that returns the second arg
#if it is >= double of first arg else None
def question_4(one,two):
   if(two >= one * 2):
       return two
   else:
       return None

def facto_compute(n):
   if(n ==1):
       return 1
   elif(n <=0):
       return 0
   else:
       return n * facto_compute(n-1)

temp = float(input("Enter Temprature: "))
print("Enter y to Convert Temp in Fahrenheit to Celsius")
print("\tor")
print("Enter n to Convert Temp in celsius into Temp in Fahrenheit")
choice = input("").strip().lower()
if(choice == "y"):
   print("Temprature in Celsius:",question_1(temp, True))
elif(choice == "n"):
   print("Temprature in Fahrenheit:",question_1(temp, False))
else:
   print("Invalid Choice")

#question_2()
print("Sum of 10 + 12 =",question_2(10,12))
print("Sum of 10 + 10 =",question_2(10,10))

#question_3()
print("Maximum of 84,34,88 is :",question_3(84,34,88))

#question_4()
print("question_4(10,23): ", question_4(10,23))

#facto_compute()
print("Factorial of 10:",facto_compute(10))

Add a comment
Know the answer?
Add Answer to:
# Simple python Question. ============================ Usinginput(),ascertain whether or not a user wants to convert fahrenheit to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT