Python程序输入一个字符串并查找总数的大写和小写字母
Given a string str1 and we have to count the total numbers of uppercase and lowercase letters.
给定字符串str1 ,我们必须计算大写和小写字母的总数。
Example:
例:
Input:
"Hello World!"
Output:
Uppercase letters: 2
Lowercase letters: 8
Input:
"[email protected]"
Output:
Uppercase letters: 1
Lowercase letters: 4
Method 1:
方法1:
(Manual) By checking each character of the string with a range of uppercase and lowercase letters using the conditional statement.
(手动)通过使用条件语句检查字符串中每个字符的大小写范围。
print("Input a string: ")
str1 = input()
no_of_ucase, no_of_lcase = 0,0
for c in str1:
if c>='A' and c<='Z':
no_of_ucase += 1
if c>='a' and c<='z':
no_of_lcase += 1
print("Input string is: ", str1)
print("Total number of uppercase letters: ", no_of_ucase)
print("Total number of lowercase letters: ", no_of_lcase)
Output
输出量
RUN 1:
Input a string:
Hello World!
Input string is: Hello World!
Total number of uppercase letters: 2
Total number of lowercase letters: 8
RUN 2:
nput a string:
[email protected]
Input string is: [email protected]
Total number of uppercase letters: 1
Total number of lowercase letters: 4
Method 2:
方法2:
By using islower() and isupper() methods
通过使用islower()和isupper()方法
print("Input a string: ")
str1 = input()
no_of_ucase, no_of_lcase = 0,0
for c in str1:
no_of_ucase += c.isupper()
no_of_lcase += c.islower()
print("Input string is: ", str1)
print("Total number of uppercase letters: ", no_of_ucase)
print("Total number of lowercase letters: ", no_of_lcase)
Output
输出量
RUN 1:
Input a string:
Hello World!
Input string is: Hello World!
Total number of uppercase letters: 2
Total number of lowercase letters: 8
RUN 2:
nput a string:
[email protected]
Input string is: [email protected]
Total number of uppercase letters: 1
Total number of lowercase letters: 4
翻译自: https://www.includehelp.com/python/program-to-input-a-string-and-find-total-number-of- uppercase-and-lowercase-letters.aspx
Python程序输入一个字符串并查找总数的大写和小写字母相关推荐
- [转载] Python程序输入一个字符串并查找总数的大写和小写字母
参考链接: Python程序可大写字符串中每个单词的第一个和最后一个字符 Given a string str1 and we have to count the total numbers of u ...
- python输入一个字符一个数字_Python程序输入一个字符串并查找字母和数字的总数...
给定一个字符串str1,我们必须计算字母和数字的总数. 示例 Input: "Hello World!" Output: Letters: 10 Digits: 0 Input: ...
- 从键盘上输入一个字符串并保存在str1中,并把str1中下表为偶数的字符保存到str2中
从键盘上输入一个字符串并保存在str1中,并把str1中下表为偶数的字符保存到str2中 比如; dang str1 = "computer"时,str2 = "cmue ...
- 输入一个字符串并原样输出。
标题 输入一个字符串并原样输出. 解题方法 定义好字符串的长度并输出. 熟练使用putchar语法结构. putchar语法结构为 int putchar(int char) ,其功能是把参数 cha ...
- 【汇编】奇校验程序:输入一个字符,编写一个程序判断这个字符中1的个数,如果是偶数个1,则校验位(字符最高位)为1,如果是奇数个1,则校验位为0。并显示加入校验位前后该字符的二进制代码。
奇校验程序:输入一个字符,编写一个程序判断这个字符中1的个数,如果是偶数个1,则校验位(字符最高位)为1,如果是奇数个1,则校验位为0.并显示加入校验位前后该字符的二进制代码. 编译结果:字符'0'A ...
- 从键盘输入一个字符,判断其是不是大写字母,如果是则请输出这个大写字母,如果不是请输出“这不是一个大写字母”的英文信息(要求:能连续输出直到输出“#”结束)。
从键盘输入一个字符,判断其是不是大写字母,如果是则请输出这个大写字母,如果不是请输出"这不是一个大写字母"的英文信息(要求:能连续输出直到输出"#"结束). P ...
- C语言程序设计第三版苏小红习题5.8输入一个字符判断是数字、大写字母、小写字母、空格、还是其他
#include<stdio.h> int main() { char ch; printf("输入一个字符:\n"); ch=getchar(); if(ch> ...
- python依次输入输出字符串_Python练习:输入一个字符串并输出该字符串中所有字符的组合,python...
题目 输入一个字符串,输出该字符串中字符的所有组合.例如abc,它的组合有a.b.c.ab.ac.bc.abc. 第一种思路 使用递归求解,可以考虑长度为n的字符串中m个字符的组合,设为C(n, m) ...
- python从键盘上输入一个字符串并输出该字符串_python练习:输入一个字符串,输出该字符串中字符的所有组合...
题目 输入一个字符串,输出该字符串中字符的所有组合.例如abc,它的组合有a.b.c.ab.ac.bc.abc. 第一种思路 使用递归求解,可以考虑长度为n的字符串中m个字符的组合,设为C(n, m) ...
最新文章
- bat脚本登陆ftp服务器
- SDO_GEOMETRY结构说明
- Jeson nano + 思岚激光雷达rplidar_s1 + ubuntu18.04
- Apache Druid Console 远程命令执行漏洞
- 软件开发有哪些规范和标准_车辆,机械专业如何从事汽车电子软件开发
- SQL数据库被置疑后的恢复步骤(附详细图解)-虽然转载但是亲自实现过
- 思科CISCO ASA 5521 防火墙 Ipsec 配置详解
- latex如何实现单元格内文字的换行
- C语言----整钱换零钱问题。把1元兑换成1分,2分,5分的硬币,共有多少种不同的兑换方法?(同理n元硬币的兑换方法呢?n元由用户输入)
- 全国2016年实施不动产登记 潘石屹预言房价下跌
- TensorRT - 扩展TensorRT C++API的模型输入维度,增加Dims5,Dims6,Dims7,Dims8
- 计算机双工模式,小熊教你电脑设置连接速度和双工模式
- Android 抛弃原生MediaPlayer 使用音频框架 StarrySky
- 【报错】Cannot mix different versions of joi schemas(Postman)
- 《C Primer Plus》学习笔记—第9章
- step7和wincc联合仿真_过路老熊_新浪博客
- Spark的任务调度
- 微信小程序高度自适应布局
- 《MLB棒球创造营》:棒球团建·一球成名
- Windows下控制鼠标移动和点击的C语言实现
热门文章
- c语言 socket 报文解析,C语言实现Socket简单通信
- java 抽象类 final_final/抽象类/interface
- 刷网络课_网络营销实践心得—刘荟萌
- MySQL管理工具MySQL Utilities — 如何连接MySQL服务器
- innobackupex远程备份脚本
- vertex 3.0 与SpringBoot混合开发之初探
- 马凯军201771010116《面向对象程序设计(java)》第二周学习总结
- 机器学习(一)梯度下降算法的实现及过程分析
- [.Net线程处理系列]专题五:线程同步——事件构造
- CentOS7入门_安装并配置mysql5.7.18