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

简介: 1、统计字符串中有多少个数字、字母、空格以及其他字符#!/usr/bin/env python# -*- coding:utf-8 -*-# @Time : 2018/1/24 21:29# @Author : zhouyuyao# @File : countnums.

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
目录
相关文章
|
6月前
根据用户输入的行数,打印出相应行数的直角三角形
根据用户输入的行数,打印出相应行数的直角三角形
42 1
|
1月前
|
人工智能
打印出杨辉三角形
打印出杨辉三角形。
58 17
|
6月前
|
弹性计算 运维 Shell
打印9*9 乘法表
【4月更文挑战第29天】
51 1
if的三种形式,运算符的使用,99乘法表的打印
一、访问[(1, 10), (2, 20), (3, 30)]列表中元组的每个元素
72 0
|
人工智能 Python
打印完全数
打印完全数
76 0
7-164 打印杨辉三角
7-164 打印杨辉三角
55 0
AcWing 815. 打印字符串
AcWing 815. 打印字符串
120 0
AcWing 815. 打印字符串
|
存储 算法
组合数打印
方法1:【思路】1)将1,2,3,4存入数组中,然后从4个数中选出1个数,即为selVal;2)接下来的工作即是从剩余的3个数中选取2个数,需要存储除selVal外的剩余3个数;3)选取后打印selVal和选的2个数即可。
186 0
习题 9: 打印,打印,打印
# Here's some new strange stuff, remember type it exactly. days = "Mon Tue Wed Thu Fri Sat Sun" months = "Jan\n Feb\n Mar\n Apr\n May\n Jun\n Jul\n ...
1022 0
习题 8: 打印,打印
formatter = "%r %r %r %r" print (formatter % (1, 2, 3, 4)) print (formatter % ("one", "two", "three", "four")) print (formatter % (True, False, False...
715 0