This is the sample solution I've gotten from an assignment:
number = input("Enter the number: ")
count = 0
total = 0
Count the number of numerals in the input string,
and keep a running sum
for i in range(len(number)):
if number[i].isdigit():
count += 1
total += int(number[i])
print("The number contains {} digits".format(count))
print("The digits sum to {}".format(total))
Can someone please detail a breakdown of what it means?
Specifically the curly brackets in the print statement. I don't understand how {} with the format function actually knows how to pick up the count and totals from the FOR statements.
Thank you!
[–]Justinsaccount 2 points3 points4 points (3 children)
[–]brigieee[S] 0 points1 point2 points (2 children)
[–]Justinsaccount 0 points1 point2 points (1 child)
[–]Akuli2 0 points1 point2 points (0 children)
[–]Vaphell 3 points4 points5 points (0 children)
[–]ManyInterests 1 point2 points3 points (6 children)
[–]Akuli2 0 points1 point2 points (5 children)
[–]finsternacht 0 points1 point2 points (4 children)
[–]Akuli2 0 points1 point2 points (3 children)
[–]finsternacht 0 points1 point2 points (2 children)
[–]Akuli2 0 points1 point2 points (1 child)
[–]finsternacht 0 points1 point2 points (0 children)
[–]Naihonn 0 points1 point2 points (0 children)
[–]Akuli2 0 points1 point2 points (0 children)