added m!roman [int]; returns error string or a number in roman numerals
This commit is contained in:
parent
b3c045664b
commit
9aea2cf9dc
59
roman.py
Normal file
59
roman.py
Normal file
|
@ -0,0 +1,59 @@
|
|||
from random import *
|
||||
from math import *
|
||||
|
||||
int_dict = { 1 : "I", 5 : "V", 10 : "X", 50 : "L", 100 : "C", 500 : "D", 1000 : "M", 5000 : "V̄", 10000 : "X̄", 50000 : "L̄", 100000 : "C̄", 500000 : "D̄", 1000000 : "M̄"}
|
||||
int_list = [1000000,500000,100000,50000,10000,5000,1000,500,100,50,10,5,1]
|
||||
int_in = 0
|
||||
string_out = ""
|
||||
|
||||
|
||||
def roman_convert(int_in_string):
|
||||
global string_out
|
||||
global int_in
|
||||
string_out = ""
|
||||
int_in = int(int_in_string)
|
||||
if int_in >= 4000000:
|
||||
return "Please keep it less than 4,000,000, we don't know how to write 2 macrons."
|
||||
for poss_int in int_list:
|
||||
if str(poss_int)[0] == "1":
|
||||
addstring1(poss_int)
|
||||
addstring9(poss_int)
|
||||
else:
|
||||
addstring5(poss_int)
|
||||
addstring4(poss_int)
|
||||
return string_out
|
||||
|
||||
|
||||
def addstring1(num):
|
||||
global string_out
|
||||
global int_in
|
||||
while int_in >= num:
|
||||
string_out += int_dict[num]
|
||||
int_in = int_in - num
|
||||
|
||||
def addstring4(num5):
|
||||
global string_out
|
||||
global int_in
|
||||
if int_in >= num5 * 4 / 5:
|
||||
string_out += int_dict[int(num5/5)] + int_dict[num5]
|
||||
int_in = int_in - (num5 * 4 / 5)
|
||||
|
||||
def addstring5(num5):
|
||||
global string_out
|
||||
global int_in
|
||||
if int_in >= num5:
|
||||
string_out += int_dict[num5]
|
||||
int_in = int_in - num5
|
||||
|
||||
def addstring9(num10):
|
||||
global string_out
|
||||
global int_in
|
||||
if num10 == 1:
|
||||
return
|
||||
if int_in >= num10 * 9 / 10:
|
||||
string_out += int_dict[int(num10/10)] + int_dict[num10]
|
||||
int_in = int_in - num10 * 9 / 10
|
||||
|
||||
|
||||
def randbool():
|
||||
return (randint(0,1) == 1)
|
|
@ -28,6 +28,7 @@
|
|||
<Compile Include="onomancer.py">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="roman.py" />
|
||||
<Compile Include="the_prestige.py" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import discord, json, os
|
||||
import discord, json, os, roman
|
||||
import database as db
|
||||
import onomancer as ono
|
||||
|
||||
|
@ -49,6 +49,13 @@ async def on_message(msg):
|
|||
except AttributeError:
|
||||
await msg.channel.send(ono.get_stats(msg.author.name))
|
||||
|
||||
elif command.startswith("roman "):
|
||||
possible_int_string = command.split(" ",1)[1]
|
||||
try:
|
||||
await msg.channel.send(roman.roman_convert(possible_int_string))
|
||||
except ValueError:
|
||||
await msg.channel.send(f"\"{possible_int_string}\" isn't an integer in Arabic numerals.")
|
||||
|
||||
elif command == "credit":
|
||||
await msg.channel.send("Our avatar was graciously provided to us, with permission, by @HetreaSky on Twitter.")
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user