Q.Given a letter in Roman numeral, develop an algorithm and write the Python code to print the value of it. If some other letter other than Roman numeral is given as input then print ‘Enter a roman numeral’ and terminate.
Algorithm:
Step1.Get A Roman numeral from the user and store it as roman variable.
Step2.Check if roman is equal to 'I' then display 1
Step3. Else if roman is equal to 'V' then display 5
Step4. Else if roman is equal to 'X' then display 10
Step5. Else if roman is equal to 'L' then display 50
Step6. Else if roman is equal to 'C' then display 100
Step7. Else if roman is equal to 'D' then display 500
Step8. Else roman is equal to 'M' then display 1000
Step9. Else display Enter a Roman Numeral
Step10. End
Program:
roman = input()
if roman == 'I':
print(1)
elif roman == 'V':
print(5)
elif roman == 'X':
print(10)
elif roman == 'L':
print(50)
elif roman == 'C':
print(100)
elif roman == 'D':
print(500)
elif roman == 'M':
print(1000)
else:
print("Enter a roman numeral")
Flowchart:
to edit this flowchart click on this
Algorithm:
Step1.Get A Roman numeral from the user and store it as roman variable.
Step2.Check if roman is equal to 'I' then display 1
Step3. Else if roman is equal to 'V' then display 5
Step4. Else if roman is equal to 'X' then display 10
Step5. Else if roman is equal to 'L' then display 50
Step6. Else if roman is equal to 'C' then display 100
Step7. Else if roman is equal to 'D' then display 500
Step8. Else roman is equal to 'M' then display 1000
Step9. Else display Enter a Roman Numeral
Step10. End
Program:
roman = input()
if roman == 'I':
print(1)
elif roman == 'V':
print(5)
elif roman == 'X':
print(10)
elif roman == 'L':
print(50)
elif roman == 'C':
print(100)
elif roman == 'D':
print(500)
elif roman == 'M':
print(1000)
else:
print("Enter a roman numeral")
Flowchart:
to edit this flowchart click on this
No comments:
Post a Comment