Battle Between Adjacent Digits
HomePython

Battle Between Adjacent Digits

""" Starting from the left side of a string that consists only of digits, adjacent digits pair up in 'battle' and the...

Remove Consecutive Non Vowel From String
Django Password Reset Email in PythonAnywhere
Vowel Count

"""

Starting from the left side of a string that consists only of digits, adjacent digits pair up in 'battle' and the larger digit wins. If two digits are the same, they both lose. A lone digit automatically wins.


Write a program that takes a string of digits and returns the victorious digits. If all the numbers lose, return 'total carnage'.


Example

Sample Input 1:

578921445


Sample Output 1:

7925


Sample Input 2:

558899


Sample Output 2:

total carnage

"""


Program

import time

input_string = input("Enter a numbers only...\n")

start_time = time.time()

count = 0

output = []

if input_string.isnumeric():

    for i in range(0, len(input_string) - 1, 2):

        if not input_string[i] == input_string[i + 1]:

            if input_string[i] > input_string[i + 1]:

                output.append(input_string[i])

                count += 1

            else:

                output.append(input_string[i + 1])

                count += 1

    if len(input_string) % 2 != 0:

        output.append(input_string[-1:])

    if count > 0:

        print("Output : ", ''.join(output))

    else:

        print('Output : total carnage')

else:

    print("Wrong input. Try again")

print("Time taken : ", time.time() - start_time) 



Output




Name

Accident Alert,1,AI,2,Array,1,Aurdino,1,C,2,Computer Graphics,9,Data Science,3,Dataset,1,Decoratot,1,Django,1,ESP32,1,Fixed point/iteration method,1,Greater or smaller,1,html,1,Image Processing,1,JAVA,1,Javascript,22,Machine Learning,1,Matlab,3,Numerical Method,13,OOP,1,Other,3,PHP,1,Point operation,1,Python,11,Raspberry pi,1,Recommendation System,1,Regression,1,Reservation System,1,Robotics,1,Simulation,2,sine wave,1,String Handling Function,1,Web scrap,1,Webpage,1,
ltr
item
COMPUTER PROGRAMMING: Battle Between Adjacent Digits
Battle Between Adjacent Digits
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgkEgKM7IAyv_9h4zIj19PD-0zGiYDCtiGcE6_SPlKRtDI_NMD_Hap4OjY9VCAD3T9mHU9IHqtcGbfBYNnVHWQtnWe6h1PkpoO-ba3dN0y8XUaGBRCEvsMWuJglQXUU-FHUKjQv7zqa96c/w640-h222/Screenshot+from+2020-12-19+08-41-37.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgkEgKM7IAyv_9h4zIj19PD-0zGiYDCtiGcE6_SPlKRtDI_NMD_Hap4OjY9VCAD3T9mHU9IHqtcGbfBYNnVHWQtnWe6h1PkpoO-ba3dN0y8XUaGBRCEvsMWuJglQXUU-FHUKjQv7zqa96c/s72-w640-c-h222/Screenshot+from+2020-12-19+08-41-37.png
COMPUTER PROGRAMMING
https://computerprogram4ru.blogspot.com/2020/12/battle-between-adjacent-digits.html
https://computerprogram4ru.blogspot.com/
https://computerprogram4ru.blogspot.com/
https://computerprogram4ru.blogspot.com/2020/12/battle-between-adjacent-digits.html
true
8672391763020279633
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy