If you want to convert time from minutes to hours using Python code then you need to apply the below pseudo-code,
Example 1: Using Hardcoded minutes
'''
Python Program:
Convert Minutes into Hours
Author: Code2care.org
Version: v1.0
Date: Fri 11 Aug 2023
'''
input_minutes = 115
# Conversion min to hours
hours = input_minutes // 60
left_minutes = input_minutes % 60
print(f"{input_minutes} minutes = {hours} hours and {left_minutes} minutes.")
Output:
115 minutes = 1 hours and 55 minutes.
75 minutes = 1 hours and 15 minutes.
135 minutes = 2 hours and 15 minutes.

Example 2: User Inputs the Minutes
'''
Python Program:
Convert Minutes into Hours
from user input
Author: Code2care.org
Version: v1.0
Date: Fri 11 Aug 2023
'''
while True:
user_input = input("Enter the time in minutes ('e' to exit): ")
if user_input.lower() == 'e':
print("Program Exited.")
break
try:
input_minutes = int(user_input)
hours = input_minutes // 60
left_minutes = input_minutes % 60
print(f"{input_minutes} minutes = {hours} hours and {left_minutes} minutes.\n")
except ValueError:
print("Invalid input.\n")
Output:
Enter the time in minutes ('e' to exit): 99
98 minutes = 1 hours and 39 minutes.
Enter the time in minutes ('e' to exit): 110
110 minutes = 1 hours and 50 minutes.
Enter the time in minutes ('e' to exit): 245
245 minutes = 4 hours and 5 minutes.
Enter the time in minutes ('e' to exit): e
Exiting the program.
-
Facing issues? Have Questions? Post them here! I am happy to answer!
More Posts related to Python,
- Python: Convert Date to DateTime
- How to sort a List using Lambda in Python
- Python matplotlib segmentation fault: 11 macOS Big Sur
- What is Terminal Velocity and its Formula? How to calculate it programmatically?
- How to install Python 3.11 on Mac
- How to flatten a nested list in Python
- Python: Pandas Merge DataFrames on Index Example
- How to Run all Cells at Once Jupyter Notebook
- Python - Convert float to String
- How to add borders to tkinter label text
- How to Exit a Loop in Python Code
- [Python] Fix: ValueError: All arrays must be of the same length
- Sorting an array using Bubble Sort in Python Programming
- How to Unzip a file using Python
- Python: Merge DataFrames Pandas Outer Join Example
- Change label (text) color in tkinter
- Convert Float to String in Python
- Fix: fatal error: No such file or directory compilation terminated
- Python: Access index/counter of a for loop iteration
- Import Other Python Files Examples
- How to install Anaconda on Mac (M1/M2 Mac)
- Python Regular Expression to Find All Matches in List
- How to Read a binary File with Python
- How to disable warnings while Python file execution
- Know current Python Version
More Posts:
- Android : Accidental Octal Lint Warning - Android
- Fix: Spring Boot + Caching: DefaultSerializer requires a Serializable payload - Java
- osascript wants to make changes while Android Studio Installation on Mac OS X - Mac-OS-X
- Java Code to check if Twitter app is installed on Android device - Android
- Remove items from JavaScript array - JavaScript
- [Fix] MySQL No database selected - ERROR 1046 (3D000) - MySQL
- How to show or hide columns in SharePoint Online List Library from - SharePoint
- Installing Native Chrome Browser App on M1 Mac Device - Chrome