Question
use Python and please comments every step.
[25] 6. Write a program that reads from standard input, two times in military format and prints the number of hours and minut
0 0
Add a comment Improve this question Transcribed image text
Answer #1

CodeToCopy:

timediff.py

#python 2.7

# taking time1 from user

time1 = raw_input("Please enter the first time: ")

# taking time2 from user

time2 = raw_input("Please enter the second time: ")

# convertin them as integers

time1 = int(time1)

time2 = int(time2)

# fetching minutes from the time1

mins1 = time1 % 100

# fetching minutes from the time2

mins2 = time2 % 100

# fetching hours from the time1

hours1 = time1/100

# fetching hours from the time2

hours2 = time2/100

# calculating hour difference between time2 and time1

diff_hours = (hours2 - hours1) % 24

# minute difference between time2 and time1

diff_mins = (mins2 - mins1);

# if minute difference is less than 0, hours need to be reduced by 1 to

# get actual hour difference

diff_hours = (diff_hours, diff_hours-1) [ diff_mins < 0]

# finalizing the range of minute difference time2 and time1

diff_mins = diff_mins % 60

# printing difference between two times

print("Difference between the two times: " + str(diff_hours) + " hours and " + str(diff_mins) + " minutes.")

timediff.py

#python 3.x

# taking time1 from user

time1 = input("Please enter the first time: ")

# taking time2 from user

time2 = input("Please enter the second time: ")

# convertin them as integers

time1 = int(time1)

time2 = int(time2)

# fetching minutes from the time1

mins1 = time1 % 100

# fetching minutes from the time2

mins2 = time2 % 100

# fetching hours from the time1

hours1 = time1/100

# fetching hours from the time2

hours2 = time2/100

# calculating hour difference between time2 and time1

diff_hours = (hours2 - hours1) % 24

# minute difference between time2 and time1

diff_mins = (mins2 - mins1);

# get actual hour difference

diff_hours = (diff_hours, diff_hours-1) [ diff_mins < 0]

# finalizing the range of minute difference time2 and time1

diff_mins = diff_mins % 60

# printing difference between two times

print("Difference between the two times: " + str(diff_hours) + " hours and " + str(diff_mins) + " minutes.")

OutputScreenshot:

File Edit View Search Terminal Help ashok@ashok-VirtualBox:~/Desktop/personal/python$ python timediff.py Please enter the fir

File Edit View Search Terminal Help ashok@ashok-VirtualBox:~/Desktop/personal/python$ python timediff.py Please enter the first time: 0900 Please enter the second time: 1730 Difference between the two times: 8 hours and 30 minutes. ashok@ashok-VirtualBox:~/Desktop/personal/python$ python timediff.py Please enter the first time: 1730 Please enter the second time: 0900 Difference between the two times: 15 hours and 30 minutes. ashok@ashok-VirtualBox:~/Desktop/personal/python$

Add a comment
Know the answer?
Add Answer to:
use Python and please comments every step. [25] 6. Write a program that reads from standard...
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
  • Using the Design Recipe, write an algorithm for each of the following programming problems, showing all...

    Using the Design Recipe, write an algorithm for each of the following programming problems, showing all work (i.e., Contract, Purpose Statement, Examples and Algorithm): 5.Write a program that reads two times in military format (e.g., 0900, 1730) and prints the number of hours and minutes between the two times. Note that the first time can come before or after the second time. 6.An online bank wants you to create a program that shows prospective customers how their deposits will grow....

  • *Please use StdIn. not Scanner. Thanks Write a program that reads in lines from standard input...

    *Please use StdIn. not Scanner. Thanks Write a program that reads in lines from standard input with each line containing a name and two integers and then prints a table with a column of the names, the integers, and the result of dividing the first by the second, accurate to three decimal places. You could use a program like this to tabulate batting averages for baseball players or grades for students. Should see: Name 1 Name 2 Name 3 20...

  • (please write code in Python and provide output) Write a program that reads the records from...

    (please write code in Python and provide output) Write a program that reads the records from the golf.txt file written in the previous exercise and prints them in the following format: Name: Emily Score: 30 Name: Mike Score: 20 Name: Jonathan Score: 23 Sample Run Name:Jimmy↵ Score:30↵ ↵ Name:Carly↵ Score:20↵ ↵ Name:Marissa↵ Score:55↵ ↵ Name:Brett↵ Score:23↵ ↵

  • c language with comments please! Name this program one.c- This program reads integers from standard input...

    c language with comments please! Name this program one.c- This program reads integers from standard input until end-of-file (control-d) and writes them to either the file good or the file bad. Write the first number to the file good. After that, as long as the number is larger than the one it read before (the previous value, write that number to the file good. Otherwise, write that number to the file bad. Two sample executions are shown below good bad...

  • Need answer in Python 3.8, with indentation and comments shown, please. 16.4* (Pattern matching) Write a...

    Need answer in Python 3.8, with indentation and comments shown, please. 16.4* (Pattern matching) Write a program that prompts the user to enter two strings and tests whether the second string is a substring in the first string. (Don't use the find method in the str class.) Analyze the time complexity of your algorithm. Here is a sample run of the program <output> Enter a string s1: Mississippi Enter a string s2: sip matched at index 6 <End Output>

  • Problem 1: Write a program that reads a positive float number and displays the previous and...

    Problem 1: Write a program that reads a positive float number and displays the previous and next integers. Sample Run: Enter a float: 3.5 The previous and next integers are 3 and 4. Problem 2: Write a program that reads two integers and displays their sum, difference, product, and the result of their division. Sample Run: Enter two integers: 8 5 Sum: 8, Difference: 3, Product: 40, Division: 1.6 Problem 3: Write a program that reads a three-digit integer from...

  • Please write in Python language. Assignment 5 0 Write a program that reads in integers and...

    Please write in Python language. Assignment 5 0 Write a program that reads in integers and then determines whether input value is prime number or not(using for statement) • First input Input number: 18457 yes . Second input Input number: 52 no

  • In python Please type the code Question 4: Write a program that reads an English word...

    In python Please type the code Question 4: Write a program that reads an English word from the user, and prints how many vowels and how many consonants it contains. Note: You may assume the letter Y is not a vowel. Sample output (2 different executions) Enter a word: test test has 1 vowels and 3 consonants Enter a word: Apple Apple has 2 vowels and 3 consonants.

  • Please use Python to solve this problem: Write a loop that reads positive integers from standard...

    Please use Python to solve this problem: Write a loop that reads positive integers from standard input and that terminates when it reads an integer that is not positive. After the loop terminates, it prints out, on a single line and separated by a single space, the sum of all the even integers read and the sum of all the odd integers read.

  • Python 3 Write a program that reads a sequence of words and prints every word whose...

    Python 3 Write a program that reads a sequence of words and prints every word whose frequency is equal to its length. You can assume that there will always be a word that meets this condition. If more than one word have this condition, you must print first the most frequent one. If two or more words with equal frequencies meet this condition, print them from the smallest to the largest in alphabetical order. Sample Input lee john lee peter...

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
ADVERTISEMENT