#🔒 Converting a date stamp to Roman numerals
9 messages · Page 1 of 1 (latest)
@neat forge
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
import time
ts = time.strftime("%Y-%m-%d %H:%M:%S") # Get the current timestamp
# Opening file for output
f = open("C:\\Temp\\calcs.txt", "w")
def isValidMenuOption(num, minV, maxV):
if (num < minV) or (num > maxV):
return False
return True
# Function to output detail
def outputDetail(num1, num2, result):
file_writing_example = ["Timestamp " + str(result) + " at " + ts + "\n"]
f.writelines(file_writing_example)
def menu():
print("Menu")
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
print("")
menu_option = int(input("Please input a valid menu number: "))
while not isValidMenuOption(menu_option, 1, 4):
menu_option = int(input("Please input a valid menu number: "))
num1 = int(input("Please input the first number: "))
num2 = int(input("Please input the second number: "))
if menu_option == 1:
addition(num1, num2)
elif menu_option == 2:
subtraction(num1, num2)
elif menu_option == 3:
multiplication(num1, num2)
elif menu_option == 4:
division(num1, num2)
def addition(num1, num2):
sum = num1 + num2
print("Calculation", num1, " + ", num2, " = ", sum)
outputDetail(num1, num2, sum)
def subtraction(num1, num2):
sub = num1 - num2
print("Calculation", num1, " - ", num2, " = ", sub)
outputDetail(num1, num2, sub)
def multiplication(num1, num2):
times = num1 * num2
print("Calculation", num1, " x ", num2, " = ", times)
outputDetail(num1, num2, times)
def division(num1, num2):
if num2 != 0:
divide = num1 / num2
print("Calculation", num1, " ÷ ", num2, " = ", divide)
outputDetail(num1, num2, divide)
menu()
And my file output is
Timestamp 9 at 2024-03-12 19:03:02
I need to make is so the date is roman numerals.
You would have to add another function that checks for the roman numerals every time you pass another calculation to your file
yea, I tried making ones but the never seemed to work
def int_to_Roman(num):
"""Converts an integer to its Roman numeral representation.
Args:
num: The integer to convert.
Returns:
The Roman numeral representation of the integer.
"""
roman_numerals = {
1000: 'M',
900: 'CM',
500: 'D',
400: 'CD',
100: 'C',
90: 'XC',
50: 'L',
40: 'XL',
10: 'X',
9: 'IX',
5: 'V',
4: 'IV',
1: 'I'
}
result = ''
for value, numeral in roman_numerals.items():
while num >= value:
result += numeral
num -= value
return result
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.