🔒 Closed Number to Roman Numeral using only if-else

Status
Not open for further replies.

Dyan

Journeyman
doable poba ito? Ayaw papagamitin ng prof namen ng loop eh and if magagawa man mukang parang YandereDev yung code. Mahabang if-else 😂

ps. Nakagawa napo ng code but used loops and function
 
Python:
number = 2959
roman_numerals = ""


def calc(value,symbol,stop_at, stop_symbol):
    global number
    global roman_numerals
   
    x = number // value
    if x  > 0:
        for i in range(x):
            roman_numerals += symbol
        number = number % value
    break_point(stop_at,stop_symbol)
       
def break_point(value,symbol):
    global number
    global roman_numerals
   
    if number >= value:
        roman_numerals += symbol
        number -= value
   

calc(1000,"M",900,"CM")
calc(500,"D",400,"CD")
calc(100,"C",90,"XC")
calc(50,"L",40,"XL")
calc(10,"X",9,"IX")
calc(5,"V",4,"IV")
calc(1,"I",0,"")

print(roman_numerals)

translate mo nalang di ako familiar sa java

check mo nadin kung tama
Bawal daw yata gumamit ng loop
 
Bawal daw yata gumamit ng loop
Python:
number = 2959
roman_numerals = ""


def calc(value,symbol,stop_at, stop_symbol):
    global number
    global roman_numerals
   
    x = number // value
    if x  > 0:
        for i in range(x):
            roman_numerals += symbol
        number = number % value
    break_point(stop_at,stop_symbol)
       
def break_point(value,symbol):
    global number
    global roman_numerals
   
    if number >= value:
        roman_numerals += symbol
        number -= value
   

calc(1000,"M",900,"CM")
calc(500,"D",400,"CD")
calc(100,"C",90,"XC")
calc(50,"L",40,"XL")
calc(10,"X",9,"IX")
calc(5,"V",4,"IV")
calc(1,"I",0,"")

print(roman_numerals)

translate mo nalang di ako familiar sa java

check mo nadin kung tama
Hmmmm paano mo in-approach bukod sa looping? Tama si sir jayvee baka p'wede mo gamitan ng function TS.
salamat po sa response mga mamser. Bali pupursue ko na po yung gagamit ng loops. De defend nalang po sagot pag nag kita ulit kami ni prof😂 . Hirap lutasan kasi kung fofollow lang yung if-else hahah
 
Status
Not open for further replies.

About this Thread

  • 8
    Replies
  • 825
    Views
  • 4
    Participants
Last reply from:
PHC_Jayvee

Trending Topics

Online now

Members online
375
Guests online
1,064
Total visitors
1,439

Forum statistics

Threads
2,273,592
Posts
28,950,482
Members
1,235,846
Latest member
viscahm16
Back
Top