2.求1-100的所有数的和 x=0for y in range (1,101): x=x+yprint(x)#Python for循环中可以循环一个列表或者某一个字符串下面是for的基本格式,英文是格式不变的:for 变量 in 列表: 过程else: #cla= ["a", "b", "c", "Python"]cla是我们自己命名的之后带等于号这个是列表的意思[ ],在[ ]放入需要循环的值 #除了自定义的列表,我们还能
用while语句求1~100之和 public class Ex3_5 { public static void main(String[] args){ int n=1,sum=0; while(n<=100) { sum+=n; n++; } System.out.println("sum="+sum); }}
package com.swift; public class String_To_Integer_Test { public static void main(String[] args) { /* * 编程求字符串“100”和“150”按十进制数值做差后的结果以字符串形式输出. */ String str1="100"; String str2="150"; int i1=Integer.valueOf(str1); int i2=Integer.valueOf
<span style="color:#FF0000;">第一步:把输入的数字转为字符串n.ToString() 第二步:求出字符串的长度即为正整数的位数 第三步:从后向前逆序输出</span> 附代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; //给一个正整数, //要求:一.求它是几位数,二.逆序打印出各位数字. namespa
1.判断下列逻辑语句的True,False. 1) 1 > 1 or 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6 False or True or False and True and True or False True 2) not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6 False and True or False
今日目录: 一.流程控制 1. if 2. while 3. for 4. 后期补充内容 一.流程控制--if 1.if判断: # if判断 age = 21 weight = 50 if age > 18 and age < 25 and weight >40 and weight < 60: print("表白...") 2.if+else: # 语法二:if - else age = 21 weight = 50 if age > 18 and ag