My task is to make a program.
In the code there is variable called num1, num1 has to be digits only and with the length of 5.
The code should print every digit in num1 and their sum.
The problem here is that if num1's length is not 5 it's not working, as well if there is chars in num1 that aren't digits.
It seems like the problem is in the condition.
Please tell me what is not good in my program (I'm still a beginner in python) EDIT : Thanks for the help! i appreciate it, i got along with it, the new code is the right one. :D
max_value = 5
def main():
global max_value
#This line requests from you to put an input with 5 digits
num1 = raw_input("Please enter a number with 5 digits\n")
bol = check_everything(num1)
if bol is False:
while (len(num1) != max_value) or (num1.isdigit() == False):
num1 = raw_input("Please enter a number with 5 digits and with
digits only\n")
num1 = int(num1)
printer(num1)
def check_everything(num1):
if (len(num1) == max_value) and (num1.isdigit() == True):
return True
else:
return False
def printer(num1):
summ = 0
s1 = ''
for x in xrange(max_value):
s1 += str(num1)[x] + ','
print s1[:-1:]
while num1 != 0:
summ += num1 % 10
num1 /= 10
print(str(summ))
if __name__ == '__main__':
main()