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
Python: Write a function that takes in a number as a parameter and calculates the square...
Python: Write a function that takes in a number as a parameter and calculates the square of the number up to and including the value of the parameter. Please use a while or for loop.
1) In Python Use a while loop to ask the user to enter a series of...
1) In Python Use a while loop to ask the user to enter a series of alphabets. The loop terminates when the user presses enter. Once the loop terminates, display the number of vowels and consonants entered by the user. Hint: keep a running count of the number of characters entered by the user. Keep a running count of the number of vowels. Total number of consonants = total number of characters - total number of vowels. Assume that the...
use python Write a program that uses a for loop to display all prime numbers within...
use python Write a program that uses a for loop to display all prime numbers within the range [500, 800] (hint: prime numbers are numbers that have only 2 factors: 1 and themselves. You can use a loop function to check if a number has a factor other than 1 or itself using % operation)
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...
Python: Write a function called sum_odd that takes two parameters, then calculates and returns the sum...
Python: Write a function called sum_odd that takes two parameters, then calculates and returns the sum of the odd numbers between the two given integers. The sum should include the two given integers, if they are odd. You can assume the arguments will always be positive integers, and the first smaller than or equal to the second. To get full credit on this problem, you must define at least 1 function, use at least 1 loop, and use at least...
Python 3 Conversion and exception handling Create a function that asks the user to enter a...
Python 3 Conversion and exception handling Create a function that asks the user to enter a number and returns the number. * function name: get_int * parameters: prompt (string) * returns: int * operation: Use the "prompt" parameter as the parameter to an input() call in order to ask the user for a number. Convert the number to a int using the int() function and return this number from the function. but - If the user enters something that cannot...
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...
python problem: ( use a loop to read each character from the string and insert into...
python problem: ( use a loop to read each character from the string and insert into the stack) 1. The function main a5.py continually asks the user for a string, and calls isPalindrome to check whether each string is a palindrome. A palindrome is a word or sequence that reads the same backward as forward, e.g., noon, madam or nurses run. 2. Your function must ignore spaces: when the user enters 'nurses run', the function returns True, to indicate that...
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...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT