Input a number and check it is one digit, two digit or three digit number.
Answers
Answered by
0
Write a function named containsDigit that determines if a number contains a particular digit. The header should look like: bool containsDigit(int number, int digit); If number contains digit, then the function should return true .
Isy
Answered by
1
Answer:
number = float(input('enter your number'))
if number > 0:
print("Positive number")
num = str(number)
num = num[:-2]
leng = len(num)
elif number < 0:
print("Negative number")
num = str(number)
num = num[1:]
num = num[:2]
leng = len(num)
else:
print("the number is zero")
if leng ==1:
print('the entered number is one digit')
elif leng ==2:
print('the entered number is two digit')
elif leng ==3:
print('the entered number is three digit')
Explanation:
i tried with this question where input a number which check the number is negative or positive and check the number digits in number
i basically used simple logic like converting the float input to str and indexing float to string part,
Similar questions