repl.it
Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
run = True
while run:
    while True:
        try:
            userNum = int(input("Enter a positive integer.\n> "))
            position = int(input("Enter the position around which the transformations will be centered.\n> "))
            transition = int(input("Enter the transition integer.\n> "))

            if userNum <= 0 or position <= 0 or transition <= 0:
                deny = int("oops")
        except:
            print("Make sure everything is positive.\n")
            continue
        break

    stringedInteger = str(userNum)
    integerList = []
    integerList[:0] = stringedInteger
    newInteger = ""
    pFromRight = len(integerList) - position
    
    if int(integerList[pFromRight]) < 5:
        sumDP = int(integerList[pFromRight]) + transition
        while sumDP >= 10:
            sumDP -= 10
        final = sumDP
    else:
        difDP = abs(int(integerList[pFromRight]) - transition)
        tempList = []
        tempList[:0] = str(difDP)
        difDP = tempList[0]
        final = difDP

    integerList[pFromRight] = str(final)
    for count in range(pFromRight+1, len(integerList)):
        integerList[count] = "0"
    
    for i in integerList:
        newInteger += str(i)

    print("Your new, transformed integer is: " + newInteger)
    exit = input("Exit? y/n\n> ")
    if exit == "y" or exit == "Y":
        run = False
        
                 
?