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
var arr = [10,20,30]; //计数器思想 var sum = 0; for(var i=0;i<arr.length;i++){ sum += arr[i]; } console.log(sum); var avg = sum/arr.length; console.log(avg);
1使用while 循环输入1,2,3,4,5,6,,8,9,10 count = 0 while count<10: count+=1 if count ==7: continue print(count) count = 0 while count<10: count+=1 if count ==7: pass else: print(count) 2.求1——100的所有数的和 sum =0 count = 0 while count<=100: count+=1 sum = sum
1.使用while循环输入1234568910 n = 1 while n < 11: if n == 7: pass else: print(n) n = n + 1 2.求1 - 100的所有数的和 n = 1 s = 0 while n < 101: s = s + n n = n + 1 print(s) 3.输出1 - 100内的所有奇数 n = 1 while n < 101: temp = n % 2 if temp == 0: pass else: print(n) n
1.判断下列逻辑语句的True, False 1) 1 > 1 or 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6 2) not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6 2.求出下列逻辑语句的值 1) 8 or 3 and 4 or 2 and 0 or 9 and 7 2) 0 or 2 and 3 and 4 or 6 a