-3

Here are few example input & outputs to understand the question

example 1

  • input = 555
  • output should be = 55

example 2

  • input = 5455
  • output should be = 545

example 3

  • input = 6555
  • output should be = 655

example 4

  • input = 3675
  • output should be = 367

Kindly help me with code in python

James Z
  • 12,209
  • 10
  • 24
  • 44

2 Answers2

1

If those are proper numbers, then x // 10 (integer division by 10) should do the trick. If they are strings, then x[:-1] gets rid of the last character. In both cases x is the variable holding the original value.

Orius
  • 1,093
  • 5
  • 11
0

You may simply divide by 10 and then cast to integer:

inp = [555, 5455, 6555, 3675]
output = [int(x / 10) for x in inp]
print(output)  # [55, 545, 655, 367]

The above works if your inputs are actual numbers, and not strings. If the inputs are not strings, then you certainly should not convert them to string first, since the above will perform much faster than a bulky string operation.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • Can we only remove only a single number like 5 from the end if given random number as input? like x=input() x=34567 and output should be 3467 – Akhil Raj n Feb 15 '22 at 08:55
  • You are totally changing your original question, which you should not after 2 users have already given answers. I suggest sticking with your current question, and if you have follow-ups, ask another question later. – Tim Biegeleisen Feb 15 '22 at 08:57