validTime.py
def validTime(time):
"""
function to validate time
:param time:
:return:
"""
# valid time must have length of 8 , 6 digit and 2 :
if len(time) != 8:
return False
# valid time must have the two :
data = time.strip().split(':')
if len(data) < 3:
return False
try:
# valid time must be integer
hr = int(data[0])
mnt = int(data[1])
sec = int(data[2])
# checking the limit
if hr < 0 or hr > 23:
raise
elif mnt < 0 or mnt > 59:
raise
elif sec < 0 or sec > 59:
raise
except:
return False
return True
def main():
t1 = "22:59:59"
t2 = "21:0:56"
t3 = "24:02:34"
print("Is %s valid time %s " % (t1, validTime(t1)))
print("Is %s valid time %s " % (t2, validTime(t2)))
print("Is %s valid time %s " % (t3, validTime(t3)))
if __name__ == '__main__':
main()
# OUT
Is 22:59:59 valid time True
Is 21:0:56 valid time False
Is 24:02:34 valid time False
Python Program 5. Write a Python program in a file named validTime.py. Include a function named...
Write a Python program which defines a function named "divide_two_numbers" that accepts two numeric parameters and divides the first parameter by the second. Your divide_two_numbers function must check the second parameter before dividing; if it is zero, raise an ZeroDivisionError exception which includes the string "second parameter was zero!" as a parameter instead of processing the division. Your main function must call your divide_two_numbers function at least twice; one call must use two normal parameters to verify normal operation, the...
Write a python function named displayFizzBuzz that takes a number as a parameter and DISPLAYS the appropriate FizzBuzz value for that number. Test this function on all of the numbers between 1 and 100000. Submit the code and a screenshot of the program running in Linux
PYTHON 3!!!!! Write a function: class Solution { public String solution(String T); } that, given a string T, returns the latest valid time that can be obtained from T, as a string in the format "HH:MM", where HH denotes a two-digit value for hours and MM denotes a two-digit value for minutes. Examples: 1. Given T = "2?:?8", the function should return "23:58". 2. Given T = "?8:4?", the function should return "18:49". 3. Given T = "??:??", the function...
PYTHON Write a program that converts a total number of seconds to hours, minutes, and seconds. It should (1) prompt the user for input, (2) read an integer from the keyboard, (3) and calculate the result. For example, "5000 seconds = 1 hours, 23 minutes, and 20 seconds". Hint: Use the modulus operator.
(I would like this to be in five parts.) Write a program (Python module) that includes a function named studentrecords. This function must support execution of two loops. The first loop is to query the user whether they wish to enter additional records or not. It must accept responses of either yes or no as input, regardless of the letter-cases used for individual letters in the response. If the response is not recognized ( it isn’t yes or no) it...
INSTRUCTION AND PROBLEMS Write a Python program for each of the problems in this lab. Please use PyCharm to type and test your programs. Submit the Python files to Blackboard for credit. In this lab, you should submit 4 Python files, one for each problem PROBLEM I Energy consumption is measured in units of kilowatt hours (kWh). The more kWh a household use in a month, the higher the energy bll. A power company charges customers $0.12 per kWh for...
Can someone solve it with C plz Write a program that inputs a time from the console. The time should be in the format “HH:MM AM” or “HH:MM PM”. Hours may be one or two digits, for example, “1:10 AM” or “11:30 PM”. Your program should include a function that takes a string parameter containing the time. This function should convert the time into a four digit military time based on a 24 hour clock. For example, “1:10 AM” would...
python In a program, write a function named roll that accepts an integer argument number_of_throws. The function should generate and return a sorted list of number_of_throws random numbers between 1 and 6. The program should prompt the user to enter a positive integer that is sent to the function, and then print the returned list.
USING PYTHON - Write a program that calls a function that prompts the user to enter a real number. The function should verify that the user entered a valid real number, and should prompt the user to re-enter any invalid input. After a valid real number has been entered, the function should return the number as a number. To test your function, from a main function, call the function two separate times and print the sum of the two numbers...
using python, Write a function named displayReverse that takes a list as a parameter and DISPLAYS the contents of the list to the screen in reverse. Submit the code and a screenshot of the program running in Linux