zoukankan      html  css  js  c++  java
  • python 基础应用3

    1、使用while 、for循环分别打印字符串s = 'fsufhjshh3hf'中每一个元素。

    #使用while 、for循环分别打印字符串s = 'fsufhjshh3hf'中每一个元素。
    s = 'fsufhjshh3hf'
    for i in s:
        print(i)
    或
    index = 0
    while 1:
        print(s[index])
        index += 1
        if index == len(s):
            break# f s u f h j s h h 3 h f

    2、如:content = input('请输入内容:') #如用户输入:5+9或5 +9或 5 + 9,然后进行分割再进行计算·。

    #如:content = input('请输入内容:')   #如用户输入:5+9或5  +9或  5  +  9,然后进行分割再进行计算·。
    content = input('请输入内容:')
    index = content.split('+')
    a = index[0].strip()
    b = index[1].strip()
    sum = int(a)+int(b)#      5    +   9
    print(sum) #14

    #如:content = input('请输入内容:')   #如用户输入:5+9或5  +9或  5  +  9,然后进行分割再进行计算·。
    content = input('请输入内容:').strip()
    index = content.find("+")
    a = int(content[0:index])
    b = int(content[index+1:]) #      5    +   9
    print(a+b)   #14

    #n个数叠加
    content = input('请输入内容:').strip()
    index = content.split('+')
    sum = 0
    for i in index:
        sum+=int(i)  #  2  + 8  +  7   
    print(sum)#17

     3、任意输入一串文字+数字 统计数字个数。

    #任意输入一串文字+数字 统计数字个数。
    s = input('请输入:')
    count = 0
    for i in s:
        if i.isdigit():
            count += 1#d2qgqtr76768yduqgdy3
    print(count)#7
  • 相关阅读:
    【Linux】- 文件基本属性
    【Linux】- mv命令
    【Linux】- 守护进程supervisor安装使用
    【Linux】- rm命令
    【Linux】- 开启远程连接
    【Redis】- 安装为windows服务
    Apache2.4 与 php7.1.6的链接
    apache2.4 的安装
    MySQL v5.7.18 版本解压安装
    网站系统消息表设计
  • 原文地址:https://www.cnblogs.com/2584808136-qq-com/p/12788638.html
Copyright © 2011-2022 走看看