Python(30)_统计输入的字符串有多少数字

#-*-coding:utf-8-*-
‘‘‘
统计用户输入的字符串中有几个数字
‘‘‘
#
numList = [‘0‘,‘1‘,‘2‘,‘3‘,‘4‘,‘5‘,‘6‘,‘7‘,‘8‘,‘9‘]
s = input(‘请输入字符串:‘)
count = 0
for i in  s:
    if i in numList:
        count +=1
print(count)



Python(30)_统计输入的字符串有多少数字

原文地址:https://www.cnblogs.com/sunnybowen/p/10201149.html

时间: 2024-08-10 19:13:52

Python(30)_统计输入的字符串有多少数字的相关文章

统计输入任意字符串中字符的个数

1 import java.util.ArrayList; 2 import java.util.HashSet; 3 import java.util.Iterator; 4 import java.util.List; 5 import java.util.Set; 6 7 /** 8 * 9 * @author trfizeng 10 */ 11 public class CountStr { 12 13 //统计任意字符串出现的次数 14 public static List<Strin

Python(51)_统计用户输入内容,索引为奇数,并且对于的索引的是数字的个数

#-*-coding:utf-8-*- ''' 统计用户输入内容,索引为奇数,并且对于的索引的是数字的个数 ''' count = 0 content = input(">>>") for i in range(len(content)): if i%2 == 1 and content[i].isdigit(): content +=1 print(count) 原文地址:https://www.cnblogs.com/sunnybowen/p/10230964.h

C++ 统计输入的句子有多少英文字母

// ConsoleApplication1.cpp: 定义控制台应用程序的入口点.//#include "stdafx.h"#include <iostream>#include <string>using namespace std; int countnubstr(string str){ int returnnum = 0; for (int i = 0; i<str.length(); i++) { if ((str[i] >= 'a' &

Java正则表达式获得字符串中数字

下面通过一个小范例来学习如何获得一个字符串中的数字 import java.util.regex.Matcher; import java.util.regex.Pattern; public class test { public static void main(String[] args) { String strInput = "[email protected];33"; String regEx = "[^0-9]";//匹配指定范围内的数字 //Pat

编写一个Python程序,从控制台输入一个字符串(保存在变量S中),然后通过while循坏不断输入字符串(保存在变量substr中),并统计substr在s中出现的次数,然后利用format方法格式化统计结果。

s = input("请输入一个字符串:") while True: subStr = input("请输入另一个字符串") if subStr == "exit": break; i = 0 count = 0 while i < len(s): j = s.find(subStr,i) if j > -1: count +=1 i = j + len(subStr) else: break; print("''{}'在'

10.16输入一个字符串,内有数字和非数字字符,如: a123x456 17960? 302tab5876 将其中连续的数字作为一个整数,依次存放到一数组num中。例如123放在num[0]中,456放在num[1]中……统计共有多少个整数,并输出这些数。

10.16输入一个字符串,内有数字和非数字字符,如: a123x456 17960? 302tab5876 将其中连续的数字作为一个整数,依次存放到一数组num中.例如123放在num[0]中,456放在num[1]中--统计共有多少个整数,并输出这些数. #include <stdio.h> int main(){ void search(char * parr, int * pnum); char arr[100],* parr; int num[30],* pnum; parr=arr;

Python(27)_字符串的常用的方法2

#-*-coding:utf-8-*- ''' 字符串操作 ''' s = " bowen " # 从右边删 s1 = s.rstrip() print(len(s1)) s2 = s1.lstrip() print(len(s2)) 从右边删除元素,从左边删除元素,这个在以后项目中经常用到 · 计算个数 #-*-coding:utf-8-*- ''' 字符串操作 ''' s = " boaaweushvaan " s1 = s.count('a') print(s

java循环练习:输入一个字符串,统计该字符串中分别包含多少个数字,多少个字母,多少个其他字符

package practiceGO; import java.util.Scanner; /*  * 3.输入一个字符串,统计该字符串中分别包含多少个数字,多少个字母,多少个其他字符  */ public class Cto { public static void main(String[] args) {         int englishCount = 0;// 英文字母个数         int spaceCount = 0;// 空格个数         int numCoun

编写一个程序,统计输入字符串中每一个小写英文字母出现的次数

import java.util.Scanner; /** * @author:(LiberHome) * @date:Created in 2019/3/1 22:18 * @description: * @version:$ */ /*编写一个程序,统计输入字符串中每一个小写英文字母出现的次数*/ public class page0901 { public static void main(String[] args) { /*首先,输入一段字符串作为字符数组*/ System.out.p