mikolajmki

python_lab1

May 27th, 2022
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.58 KB | None | 0 0
  1. # This is a sample Python script.
  2.  
  3. # Press Shift+F10 to execute it or replace it with your code.
  4. # Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
  5.  
  6.  
  7. def print_hi(name):
  8.     # Use a breakpoint in the code line below to debug your script.
  9.     print(f'Hi, {name}')  # Press Ctrl+F8 to toggle the breakpoint.
  10.  
  11.  
  12. # Press the green button in the gutter to run the script.
  13. if __name__ == '__main__':
  14.     print_hi('PyCharm')
  15.  
  16. # See PyCharm help at https://www.jetbrains.com/help/pycharm/
  17. def fizzBuzz():
  18.     for i in range(1, 101):
  19.         if (i % 5 == 0):
  20.             print("Buzz")
  21.         elif (i % 3 == 0):
  22.             print("Fizz")
  23.         else:
  24.             print(i)
  25.  
  26. def wyswietlCyfreSlownie():
  27.     liczba = str(input("Podaj dowolna liczbe: "))
  28.     nazwyCyfr = ["zero", "jeden", "dwa", "trzy", "cztery", "piec", "szesc", "siedem", "osiem", "dziewiec"]
  29.     for i in range(len(liczba)):
  30.         print(nazwyCyfr[int(liczba[i])])
  31.  
  32. def zamianaNaRzymskie():
  33.     rzymskie = {"1" : "I", "2" : "II", "3" : "III", "4" : "IV", "5" : "V",
  34.                 "6" : "VI", "7" : "VII", "8" : "VIII", "9" : "IX", "10" : "X",
  35.                 "50" : "L", "100" : "C", "500" : "D", "1000" : "M"}
  36.     liczbaRzymska = ''
  37.     liczbaArabska = str(input("Podaj liczbe w systemie arabskim: "))
  38.     liczbaArabskaDlugosc = len(liczbaArabska)
  39.     liczbaArabskaInt = int(liczbaArabska)
  40.  
  41.     while liczbaArabskaInt > 0:
  42.         if liczbaArabskaInt > 1000:
  43.             for i in range (liczbaArabskaInt // 1000):
  44.                 liczbaRzymska += rzymskie["1000"]
  45.             liczbaArabskaInt -= liczbaArabskaInt // 1000 * 1000
  46.         if liczbaArabskaInt > 500:
  47.             for i in range (liczbaArabskaInt // 500):
  48.                 liczbaRzymska += rzymskie["500"]
  49.             liczbaArabskaInt -= liczbaArabskaInt // 500 * 500
  50.         if liczbaArabskaInt > 100:
  51.             for i in range(liczbaArabskaInt // 100):
  52.                 liczbaRzymska += rzymskie["100"]
  53.             liczbaArabskaInt -= (liczbaArabskaInt // 1000) * 100
  54.         if liczbaArabskaInt > 50:
  55.             for i in range(liczbaArabskaInt // 50):
  56.                 liczbaRzymska += rzymskie["50"]
  57.             liczbaArabskaInt -= (liczbaArabskaInt // 50) * 50
  58.         if liczbaArabskaInt > 10:
  59.             for i in range(liczbaArabskaInt // 10):
  60.                 liczbaRzymska += rzymskie["10"]
  61.             liczbaArabskaInt -= (liczbaArabskaInt // 10) * 10
  62.             liczbaRzymska += rzymskie[str(liczbaArabskaInt)]
  63.     print(liczbaRzymska)
  64.  
  65.  
  66. #fizzBuzz()
  67. #wyswietlCyfreSlownie()
  68. zamianaNaRzymskie()
Add Comment
Please, Sign In to add comment