Computer Science, asked by shubham31031991, 6 months ago

Accept 8 digit number. Separate 8 digits into 4 parts. Display appropriate message in case of
number with less digits. Two digits starting from left in one variable.
For example : Input: 31245690, a=31, b=24,c=56,d=90. Print which number is largest. Divide
each number by 2, take integer part and create a new number again as abcd.

Answers

Answered by valeriy69
2

\small\mathsf\color{pink}{Solution\: using\: python\: 3}

def num_splitter(n, interval=2):

n = str(n)

newList = []

for x in range(0, len(n), interval):

newList.append(int(n[x:x + interval]))

return newList

while True:

n = int(input("number: "))

if 8 <= len(str(n)) <= 8:

pairs = num_splitter(n)

print(f"largest num: {max(pairs)}")

new_pairs = [x // 2 for x in pairs]

a, b, c, d = new_pairs

print(f"{a}{b}{c}{d}")

break

else:

print("enter a number with 8 digits")

continue

\small\mathsf\color{lightgreen}useful?\: \color{white}\longrightarrow\: \color{orange}brainliest!

Answered by Aaditya12Vyas
1

Answer:

num = input("Enter a number : ")

if len(num) != 8:

   print("Please enter a 8 digit number !!")

else:

   a,b,c,d = int(num[0:2]),int(num[2:4]),int(num[4:6]),int(num[6:])

   print(max(a,b,c,d))

   a,b,c,d = str(a//2),str(b//2),str(c//2),str(d//2)

Explanation:

Please refer to the file linked with the answer for more understanding.

Regards.

Attachments:
Similar questions