代码如下: import random n = 0 sum = 0 while n < 10: num = random.randint(1, 100) sum = sum + num n += 1 print(num, end=",") print() print("10个数的和为:%d" % sum) print("10个数的平均值为:%.2f" % (sum / 10)) 运行结果:
#-*- coding:UTF-8 -*- #环境:python3 print("Enter the numbers between 1 and 100:") enterList=[] #记录输入的元素 while 1: a = int(input(">>>")) #将输入转换为int型 if a == 0: print ("Your input:",enterList) break #结束输入 if a<1 or a&g
#习题2:定义一个类:实现功能可以返回随机的10个数字,随机的10个字母, #随机的10个字母和数字的组合:字母和数字的范围可以指定 class RandomString(): #随机数选择的范围作为参数,如(1~100)字母 ('A'~'z'),大写字母在前 按ascii值排列先后 def __init__(self,start_num=0,end_num=100,start_alpha='A',end_alpha='z'): import string if not isinstance(s
总结;对于length()属性,还不是很熟悉.不会用它. package com.s.x; //随机产生10个随机数,并且显示出最大值,最小值 public class Love { public static void main(String[] args) { int a[] = new int[10]; int max, min; for (int i = 0; i < 10; i++) // 学会调整,这里的i<10.因为是输出10个数,不是100个数,取10个数,所以会出现数组越界
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><style type="text/css"&g
网吧充值系统namespace ConsoleApplication1 { class Program { struct huiyuan { public string name; public string password; public double yue; } static void Main(string[] aaa) { ArrayList Ul = new ArrayList(); while (true) { try { Console.WriteLine("请输入您要执行的操
/** *把1到100之间的数的偶数相加 */ class Demo{ public static void main(String[] args){ int i =1; int sum = 0; do{ if(i % 2 != 0){ sum += i; } //累加器需要在if语句外面 i++; }while(i <= 100); System.out.println(sum); } }
Math.random()随机生成(0,1)之间的float数,Random7随机生成[1,7]之间的整数,利用Random7构造Random10的步骤: 1.生成数a:a是两次Random7的结果,即a=(Random7()-1)*7+Random7()-1; 2.判断a是否小于40,如果小于40,则返回a/4+1,即为最后的结果:否则,继续执行Random10: public class B{ public static int Random7(){ return (int)(Math.ra