0
can someone help me code this one in python
1. Ask the user to enter a 6-digit number. Ex. 123456 2. Remove the last digit of the entered number. Ex. Removing the last digit from 123456 returns 12345. 3. Divide the new 5-digit number by 7 and check if its remainder is equivalent to the removed digit in Step 2. Ex. The remainder from dividing 12345 by 7 is 4. The removed digit is 6. Hence, they are not equal. 4. Display the result.
4 odpowiedzi
+ 2
Done...
I would only share it if you provide your code attempt, as you must first try by yourself for receiving help to complete your own code before ;P
+ 2
JMC
Here are some steps you need to follow to solve this problem:
1 - write code properly with proper indentation
2 - Take input as string
3 - You have to remove last digit, you can use a[:len(a) - 1]
4 - take last digit from number, you can use a[len(a) - 1::]
5 - get reminder from new 5 digit number using % 7
6 - compare reminder value with removed digit
7 - print valid if both are same otherwise print invalid
+ 1
1) you should format correctly your code (new lines and indentation)... write/paste it in a (python) code playground project could help (you can then share the link) ^^
2) however, your code seems good, except that you stopped after the first validation step (check if only 6 digits)... where is the part of 2nd and 3rd points from your description?
0
visph
while True: num = input("Enter a Number: ")
try:
numbers = [int(i) for i in num]
if len(numbers) == 6: print('valid') numbers = numbers[:5] print(numbers) else:
print('invalid')
except ValueError: print('only numbers')