Q. Write a program using Dictionary and Text files to store roman numbers and find their equivalents.
Answer =
import pickle numerals = {1:'I', 4:'IV', 5:'V', 9:'IX', 10:'X', 40: 'XL', 50: 'L', 90: 'XC', 100: 'C', 400: 'CD', 500:'D',900: 'CM', 1000:'M'} file1 = open ("roman.log", "wb") pickle.dump (numerals, file1) file1.close() file2 = open ("roman.log", "rb") num = pickle.load (file2) file2.close() n = 0 while n != -1 : print ("Enter 1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000: ") print ("or enter -1 to exit") n = int(input ("Enter number: ")) if n != -1 : print ("Equivalent roman number of this numeral is: ", num[n]) else : print ("Thank You")
Output :-
Enter 1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000:
or enter -1 to exit
Enter number: 9
Equivalent roman number of this numeral is: IX
Enter 1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000:
or enter -1 to exit
Enter number: 4
Equivalent roman number of this numeral is: IV
Enter 1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000:
or enter -1 to exit
Enter number: 50
Equivalent roman number of this numeral is: L
Enter 1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000:
or enter -1 to exit
Enter number: 100
Equivalent roman number of this numeral is: C
Enter 1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000:
or enter -1 to exit
Enter number: 1000
Equivalent roman number of this numeral is: M
Enter 1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000:
or enter -1 to exit
Enter number: -1
Thank You
>>>
In roman.log file :
€•] }”(KÅ’I”KÅ’IV”KÅ’V”K Å’IX”K
Å’X”K(Å’XL”K2Å’L”KZÅ’XC”KdÅ’C”MÅ’CD”MôŒD”M„Å’CM”MèŒM”u.
Output?
ReplyDeleteOk
Deletebruh
Deleteroman.log ??? cn u plz send thi part too!
ReplyDeleteI can not understand what you want to say please tell me again.
DeleteThere is Error in line 5
ReplyDeleteGiven Line= file.close()
But Correct line is = file1.close()
Sorry, I have corrected it.
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )