# 统计字符串以及打印乘法口诀表

+关注继续查看

1、统计字符串中有多少个数字、字母、空格以及其他字符

#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time    : 2018/1/24 21:29
# @Author  : zhouyuyao
# @File    : countnums.py
# PyCharm 2017.3.2 (Community Edition)
# Build #PC-173.4127.16, built on December 19, 2017
# JRE: 1.8.0_152-release-1024-b8 amd64
# JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
# Windows 10 10.0
# Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36)
# [MSC v.1900 64 bit (AMD64)] on win32

status=1
while status:
strings = input("Please input a string('quit' will exit):")
if strings == "quit":
exit(1)
digit = pha = space = other = 0
for i in strings:
if i.isdigit():
digit +=1
elif i.isalpha():
pha +=1
elif i.isspace():
space +=1
else:
other +=1
print("该字符串中数字有{0}个，字母有{1}个，空格有{2}个，其他{3}个。".format(digit,pha,space,other))


2、打印乘法口诀表

for i in range(1,10):
for j in range(1,i+1):
print("{0} x {1} = {2}".format(j,i,i*j),end="")
if i ==j:
print("")

1 x 1 = 1
1 x 2 = 22 x 2 = 4
1 x 3 = 32 x 3 = 63 x 3 = 9
1 x 4 = 42 x 4 = 83 x 4 = 124 x 4 = 16
1 x 5 = 52 x 5 = 103 x 5 = 154 x 5 = 205 x 5 = 25
1 x 6 = 62 x 6 = 123 x 6 = 184 x 6 = 245 x 6 = 306 x 6 = 36
1 x 7 = 72 x 7 = 143 x 7 = 214 x 7 = 285 x 7 = 356 x 7 = 427 x 7 = 49
1 x 8 = 82 x 8 = 163 x 8 = 244 x 8 = 325 x 8 = 406 x 8 = 487 x 8 = 568 x 8 = 64
1 x 9 = 92 x 9 = 183 x 9 = 274 x 9 = 365 x 9 = 456 x 9 = 547 x 9 = 638 x 9 = 729 x 9 = 81

14285 0

19983 0

29364 0

22618 0

16609 0

20823 0

23607 0
+关注

91

0

JS零基础入门教程（上册）