Question

In python (use loop, if, else...) a)Enter a function that calculates the maximum common divider of...

In python (use loop, if, else...)

a)Enter a function that calculates the maximum common divider of 2 numbers.

b)Write a function that asks for time in seconds and converts it into hours, minutes, and seconds

Homework Answers

Answer #1

a)

Code:

def mcd(a, b):
  
minimum = min(a, b)
  
  
for i in range(2, minimum+1):
if a%i==0 and b%i==0:
mcd = i
  
return mcd

b)

Code:


def seconds(sec):
  
#Taking the odd seconds out
sec = sec%86400
#Calculating the hours
hours = int(sec/(36*100))
sec = sec%3600
  
#Calculating minutess
mins = int(sec/60)
sec = sec%60
  
print(hours, mins, sec)

seconds(3666)

Output:

PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!

Know the answer?
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
Similar Questions
Write a Python program which calculates the average of the numbers entered by the user through...
Write a Python program which calculates the average of the numbers entered by the user through the keyboard. Use an interactive loop and ask the user at each iteration if he/she wants to enter more numbers. At the end dispay the average on the screen. Using built-in library functions for finding average is not allowed. Sample output of the program: Enter a number > 23 More numbers (yes or no)? y Enter a number > 4 Do you have more...
Write a PYTHON function called myMax which accepts a LIST of numbers and returns the maximum...
Write a PYTHON function called myMax which accepts a LIST of numbers and returns the maximum number in the list. Do NOT use Python’s built-in function max. Example: result = myMax([-999000, -1000000, -2000000]); print(result) #output is -999000 Example: result = myMax([1000000, 1000001, 1000002]); print(result) #output is 1000002
THIS IS IN PYTHON 3.0 Let's call the first function power(a,b). Use the built-in power function...
THIS IS IN PYTHON 3.0 Let's call the first function power(a,b). Use the built-in power function a**b to write a second function called testing(c) that tests if the first function is working or not. I already have the function power(a,b), which is as follows: def power(a, b):     if (b == 0): return 1     elif (int(b % 2) == 0):         return (power(a, int(b / 2)) *                power(a, int(b / 2)))     else:         return (a * power(a, int(a / 2)) *                    power(a, int(b...
Please use Python 3 4). Write a program that asks the user to enter 10 numbers....
Please use Python 3 4). Write a program that asks the user to enter 10 numbers. The program should store the numbers in a list and then display the following data: • The lowest number in the list • The highest number in the list •The total of the numbers in the list • The average of the numbers in the list   Sample input & output: (Prompt) Enter Number 1: (User enter) 4 (Prompt) Enter Number 2: (User enter) 7...
Function Example: Write a Python function that receives two integer arguments and writes out their sum...
Function Example: Write a Python function that receives two integer arguments and writes out their sum and their product. Assume no global variables. def writer(n1, n2): sum = n1 + n2 product = n1*n2 print("For the numbers", n1, "and", n2) print("the sum is", sum) print("and the product is", product) ... 1) Create a PYHW2 document that will contain your algorithms in flowchart and pseudocode form along with your screen shots of the running program. 2) Create the algorithm in both...
FOR PYTHON Rewrite your pay computation with time-and-a-half for overtime and create a function called compute_pay...
FOR PYTHON Rewrite your pay computation with time-and-a-half for overtime and create a function called compute_pay which takes two parameters (hours and rate). Enter Hours: 45 Enter Rate: 10 Pay: 475.0 YOU WILL NEED THREE FUNCTIONS: the_hours, the_rate = get_input() the_pay = compute_pay(the_hours, the_rate) print_output(the_pay) Call the functions and passing the arguments in the "main" function. Example: def main(): the_hours, the_rate = get_input() the_pay = compute_pay(the_hours, the_rate) print_output(the_pay) main() ----- Testing the outputs of your code: 1 for the valid...
USE PYTHON LANGUAGE PLEASE FOCUS YOU SHOULD ENTER AN ARRAY AND THEN THE PROGRAM GIVE OUTPUT(...
USE PYTHON LANGUAGE PLEASE FOCUS YOU SHOULD ENTER AN ARRAY AND THEN THE PROGRAM GIVE OUTPUT( TRUE/ FALSE) QUIZ 8 Array Challenge Have the function ArrayChallenge(arr) take the array of numbers stored in arr and return the string true if any two numbers can be multiplied so that the answer is greater than double the sum of all the elements in the array. If not, return the string false. For example: if arr is [2, 5, 6, -6, 16, 2,...
PROGRAM PYHTON Write a function called "calculateInput" that when called, it asks the user to enter...
PROGRAM PYHTON Write a function called "calculateInput" that when called, it asks the user to enter an number. Then, it asks for a second number. These will use the "input" command. Store these as two separate variables. This function takes NO arguments and is also a VOID function, there is no return statement. The function should print the result of these two numbers multiplied together. The program should be able to multiply floats. For example: Test Input Result calculateInput() 5...
Write a C++ program that converts time of day from a 24-hour notation to a 12-hour...
Write a C++ program that converts time of day from a 24-hour notation to a 12-hour notation. For example, it should convert 14:25 to 2:25 PM. (A) The user provides input as two integers separated by ‘:’. The following function prototype should capture the user inputs as described below: void input(int& hours24, int& minutes); //Precondition: input(hours, minutes) is called with //arguments capable of being assigned values. //Postcondition: // user is prompted for time in 24 hour format: // HH:MM, where...
IN C++ AS SIMPLE AS POSSIBLE ______ Re-write the given function, printSeriesSquareFifth,  to use a while loop...
IN C++ AS SIMPLE AS POSSIBLE ______ Re-write the given function, printSeriesSquareFifth,  to use a while loop (instead of for). • The function takes a single integer n as a parameter • The function prints a series between 1 and that parameter, and also prints its result • The result is calculated by summing the numbers between 1 and n (inclusive). If a number is divisible by 5, its square gets added to the result instead. • The function does not...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT