0

Variable python

is it possible to declare a variable counter that keeps the count inside it of all the numbers inserted by input in python?

25th Jan 2021, 6:42 AM
Nicola
Nicola  - avatar
5 Answers
25th Jan 2021, 7:20 AM
Baspberry
+ 1
If you are talking about the number of digits, then you may want to use "len" string method to get the number of characters (digits) then assign to "counter" variable but make sure you get the input as string. Or if you are talking about the count of each digits in the input, then you may want to iterate and count each digit and store it to a dictionary named "counter", with digits as keys, and their frequency are their value.
25th Jan 2021, 6:45 AM
noteve
noteve - avatar
0
Yes, you can do it. Say, you want to count how many even numbers are there up to 20. In python, the logic would be like count=0 for i in range (21): if i%2==0: count+=1 print(count) Or another approach list=[] for i in range (21): if i%2==0: list.append(i) print(len(list))
25th Jan 2021, 7:05 AM
Farzana01
Farzana01 - avatar
0
I would like to create a calculator that keeps track of all operations before printing the result
25th Jan 2021, 7:13 AM
Nicola
Nicola  - avatar
0
in c a = 0 b counter = 0 scanf(“%d”, & a), counter = counter + a, a = 0,
25th Jan 2021, 7:26 AM
Nicola
Nicola  - avatar