Advertisement
DrAungWinHtut

tikyikhant_python.py

Dec 6th, 2022 (edited)
1,006
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.55 KB | None | 0 0
  1. def recreate(mystr):
  2.     mystr = mystr.replace("-", "")
  3.     mystr = mystr.replace("+", "")
  4.     testnum = mystr
  5.     startnum = 0
  6.     endnum = 0
  7.     ans = ""
  8.     for i in range(len(testnum)):
  9.         if testnum[i] != "0":
  10.             startnum = i
  11.             break
  12.  
  13.     ans = testnum[startnum:]
  14.  
  15.     for z in range(len(ans) - 1, 0, -1):
  16.         if ans[z] != "0":
  17.             endnum = z
  18.             break
  19.  
  20.     ans1 = ans[:endnum + 1]
  21.     return ans1
  22.  
  23. usrin1 = input("Enter your num: ")
  24. usrin = str(usrin1)
  25. expopt = 0
  26. newstr1 = ""
  27. if "+" in usrin and "." not in usrin:
  28.     usrin = usrin.replace("+","")
  29.     numstr = recreate(usrin)
  30.     expopt = len(usrin) - 1
  31.     for x in range(len(numstr)):
  32.         if x == 1:
  33.             newstr1 += "."
  34.         newstr1 += numstr[x]
  35. elif "-" in usrin and "." not in usrin:
  36.     usrin = usrin.replace("-", "")
  37.     numstr = recreate(usrin)
  38.     expopt = len(usrin) - 1
  39.     for x in range(len(numstr)):
  40.         if x == 0:
  41.             newstr1 += "-"
  42.         if x == 1:
  43.             newstr1 += "."
  44.         newstr1 += numstr[x]
  45. elif "." not in usrin:
  46.     numstr = recreate(usrin)
  47.     expopt = len(usrin) - 1
  48.     for x in range(len(numstr)):
  49.         if x == 1:
  50.             newstr1 += "."
  51.         newstr1 += numstr[x]
  52.  
  53.  
  54. def recreate(mystr):
  55.     mystr = mystr.replace("-", "")
  56.     mystr = mystr.replace("+", "")
  57.     testnum = mystr
  58.     startnum = 0
  59.     endnum = 0
  60.     ans = ""
  61.     for i in range(len(testnum)):
  62.         if testnum[i] != "0":
  63.             startnum = i
  64.             break
  65.  
  66.     ans = testnum[startnum:]
  67.  
  68.     for z in range(len(ans) - 1, 0, -1):
  69.         if ans[z] != "0":
  70.             endnum = z
  71.             break
  72.  
  73.     ans1 = ans[:endnum + 1]
  74.     return ans1
  75.  
  76. if "." in usrin:
  77.     numstr = recreate(usrin)
  78.     for i in range(len(numstr)):
  79.         if numstr[i] == ".":
  80.             expopt = i - 1
  81.     newstr = numstr.replace(".", "")
  82.     if "+" in usrin1:
  83.         for z in range(len(newstr)):
  84.             if z == 0:
  85.                 newstr1 += "+"
  86.             if z == 1:
  87.                 newstr1 += "."
  88.             newstr1 += newstr[z]
  89.     elif "-" in usrin1:
  90.         for z in range(len(newstr)):
  91.             if z == 0:
  92.                 newstr1 += "-"
  93.             if z == 1:
  94.                 newstr1 += "."
  95.             newstr1 += newstr[z]
  96.     elif "+" not in usrin1 and "-" not in usrin1:
  97.         for z in range(len(newstr)):
  98.             if z == 1:
  99.                 newstr1 += "."
  100.             newstr1 += newstr[z]
  101.  
  102.  
  103. #print(newstr1)
  104. #print(expopt)
  105. print(f"{newstr1}({expopt})")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement