Portál AbcLinuxu, 4. listopadu 2025 05:05
import sys def count_digits(filename): n = 0 for line in open(filename): for c in line: if c.isdigit(): n += 1 return n print(count_digits(sys.argv[1]))
import sys
def count_digits(filename):
	n = 0
	for line in open(filename):
		for c in line:
			if c.isdigit():
				n += 1
	return n
if len(sys.argv) == 1:
	print('Missing file argument!')
else:
	print(count_digits(sys.argv[1]))
Takže budeš mít soubor data s nějakým textem, který bude obsahovat čísla, napíšeš na příkazovou řádku python3 count.py data a měl by se ti zobrazit počet písmen v onom souboru.     
            ... Jenže nevím jaké příkazy použít.Pyta prst, a vy mu dobrovolne date celu ruku? Chlapec sa chcel ucit a vy robite z neho copy-paste writera.
foo 123 456 bar
impor re text = '10 foo 123 456 bar18' # počet číslic - digits print(len(re.findall(r'\d', text))) # počet čísel - numbers print(len(re.findall(r'\d+', text)))
a = input('Enter text:')
print (len([x for x in a if x.isdigit()]))
            
        Tiskni
            
                Sdílej:
                
                
                
                
                
                
            
    
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.