-1

So I'm making a code that accepts a number with only 8 or 7 digits and then if the user enters an 8 digit number then it should add all 8 digits together then divide by 10 and print out the answer. I have been trying to change the user's input into a list but it hasn't been working out.
My current code (not working):

NumGiven=''
while not NumGiven.isnumeric():
    NumGiven=(input('Please enter a 7 or 8 digit number:'))
while len(NumGiven)<7 or len(NumGiven)>8:
    NumGiven=(input('Please enter a 7 or 8 digit number:'))
if len(NumGiven)==8:
    list=[int(i) for i in NumGiven.split()]

I think there is something wrong with the last line, I looked at many other topics but they never seemed to work. Can some one help me tweak this code.

bereal
  • 32,519
  • 6
  • 58
  • 104
wdwdwdw
  • 11

2 Answers2

2

NumGiven.split() splits on whitespace, but there probably isn't any. Since you want to iterate over characters, you can just eliminate the .split().

list=[int(i) for i in NumGiven]
recursive
  • 83,943
  • 34
  • 151
  • 241
0

OP asked for the sum - it should be:

 print(sum([int(i) for i in NumGiven])/10.0)
domoarigato
  • 2,802
  • 4
  • 24
  • 41