参考链接: 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程序输入一个字符串并查找总数的大写和小写字母相关推荐

  1. Python程序输入一个字符串并查找总数的大写和小写字母

    Given a string str1 and we have to count the total numbers of uppercase and lowercase letters. 给定字符串 ...

  2. python输入一个字符一个数字_Python程序输入一个字符串并查找字母和数字的总数...

    给定一个字符串str1,我们必须计算字母和数字的总数. 示例 Input: "Hello World!" Output: Letters: 10 Digits: 0 Input: ...

  3. 从键盘上输入一个字符串并保存在str1中,并把str1中下表为偶数的字符保存到str2中

    从键盘上输入一个字符串并保存在str1中,并把str1中下表为偶数的字符保存到str2中 比如; dang str1 = "computer"时,str2 = "cmue ...

  4. 输入一个字符串并原样输出。

    标题 输入一个字符串并原样输出. 解题方法 定义好字符串的长度并输出. 熟练使用putchar语法结构. putchar语法结构为 int putchar(int char) ,其功能是把参数 cha ...

  5. 【汇编】奇校验程序:输入一个字符,编写一个程序判断这个字符中1的个数,如果是偶数个1,则校验位(字符最高位)为1,如果是奇数个1,则校验位为0。并显示加入校验位前后该字符的二进制代码。

    奇校验程序:输入一个字符,编写一个程序判断这个字符中1的个数,如果是偶数个1,则校验位(字符最高位)为1,如果是奇数个1,则校验位为0.并显示加入校验位前后该字符的二进制代码. 编译结果:字符'0'A ...

  6. 从键盘输入一个字符,判断其是不是大写字母,如果是则请输出这个大写字母,如果不是请输出“这不是一个大写字母”的英文信息(要求:能连续输出直到输出“#”结束)。

    从键盘输入一个字符,判断其是不是大写字母,如果是则请输出这个大写字母,如果不是请输出"这不是一个大写字母"的英文信息(要求:能连续输出直到输出"#"结束). P ...

  7. C语言程序设计第三版苏小红习题5.8输入一个字符判断是数字、大写字母、小写字母、空格、还是其他

    #include<stdio.h> int main() { char ch; printf("输入一个字符:\n"); ch=getchar(); if(ch> ...

  8. python依次输入输出字符串_Python练习:输入一个字符串并输出该字符串中所有字符的组合,python...

    题目 输入一个字符串,输出该字符串中字符的所有组合.例如abc,它的组合有a.b.c.ab.ac.bc.abc. 第一种思路 使用递归求解,可以考虑长度为n的字符串中m个字符的组合,设为C(n, m) ...

  9. python从键盘上输入一个字符串并输出该字符串_python练习:输入一个字符串,输出该字符串中字符的所有组合...

    题目 输入一个字符串,输出该字符串中字符的所有组合.例如abc,它的组合有a.b.c.ab.ac.bc.abc. 第一种思路 使用递归求解,可以考虑长度为n的字符串中m个字符的组合,设为C(n, m) ...

最新文章

  1. 基于ipfire的open***功能--client to net (Roadwarrior)配置(一)
  2. 西门子PLC学习笔记二-(工作记录)
  3. 程序员出身,身价340亿!没有他,可能我们刷不了B站
  4. opengl加载显示3DS模型3DS类型文件
  5. Git 初次学习笔记
  6. tfpose与openpose区别_人体姿态识别--Openpose+Tensorflow
  7. python3.5以上版本的保留字总数是_python函数之参数(python3.5)
  8. 为什么下雨天容易犯困
  9. RapidIOIP核的验证方法研究_王玉欢
  10. 网络扫描工具zmap
  11. python数据科学导论_R与Python手牵手:数据科学导论系列(包的载入)
  12. 中英文网站googleSEO优化技巧
  13. ERROR: Cannot uninstall 'xxx'. It is a distutils installed project and thus we cannot accurately
  14. 基于AM437x的FPGA与ARM通信测试
  15. 我们总是喜欢拿顺其自然来敷衍人生道路上的荆棘坎坷,却很少承认,真正的顺其自然是竭尽所能之后的不强求,而非两手一摊的不作为。
  16. 圣光机大学计算机专业,25位师生顺利完成圣光机大学实习项目
  17. 中学计算机论文题目,中学计算机相关论文题目 中学计算机论文标题如何定
  18. python ip地址转换_Python实现将IP地址转换为数字
  19. ES关键字查询-特殊符号
  20. Angular中的指令(Directives)

热门文章

  1. mysql url认证_Springboot+shiro基于url身份认证和授权认证
  2. 【搞事情】英文文档单词对比自动翻译
  3. 【NOIP1999】【Luogu1015】回文数(高精度,模拟)
  4. 【JSOI2008】【bzoj1012】最大数maxnumber
  5. 简述tcp协议三报文握手过程_TCP协议的3次握手与4次挥手过程详解
  6. 第五章 Windows基础控件
  7. matlab求临界稳定时的k,MATLAB自动控制原理仿真
  8. awk命令详解_python学习之利用urllib和urllib2访问http的GET/POST详解
  9. 学Python必看,Python中encode(),decode()的本质
  10. [蓝桥杯]试题 基础练习 Huffuman树