python第5章IF语句课后习题答案
- 格式:docx
- 大小:30.93 KB
- 文档页数:9
第五章答案5.2:实现i s o d d()函数,参数为整数,如果参数为奇数,返回t r u e,否则返回f a l s e。
def isodd(s):x=eval(s)if(x%2==0):return Falseelse:return Truex=input("请输入一个整数:")print(isodd(x))请输入一个整数:5True5.3:实现i s n u m()函数,参数为一个字符串,如果这个字符串属于整数、浮点数或复数的表示,则返回t r u e,否则返回f a l s e。
def isnum(s):try:x=eval(s)if((type(x)==int)|(type(x)==float)|(type(x)==complex)):return Trueelse:return Falseexcept NameError:return Falsex=input("请输入一个字符串:")print(isnum(x))请输入一个字符串:5True题5.4:实现m u l t i()函数,参数个数不限,返回所有参数的乘积。
def multi(x):xlist=x.split(",")xlist = [int(xlist[i]) for i in range(len(xlist))] #for循环,把每个字符转成int值num=1for i in xlist:num=num*iprint(num)s=input("请输入数字,并用,号隔开:")multi(s)请输入数字,并用,号隔开:5,420题5.5:实现i s p r i m e()函数,参数为整数,要有异常处理,如果整数是质数返回t u r e,否则返回f a l s e。
try:def isprime(s):i=2m=0for i in range(2,s-1):if(s%i==0):i+=1m+=1else:i+=1if(m>0):return Falseelse:return Trueexcept NameError:print("请输入一个整数!")s=eval(input("请输入任意一个整数:")) print(isprime(s))请输入任意一个整数:9False。
Python第5章if语句编程时经常需要检查一系列条件,并据此决定采取什么措施。
在Python中,if语句让你能够检查程序的当前状态,并据此采取相应的措施。
在本章中,你将学习条件测试,以检查感兴趣的任何条件。
你将学习简单的if语句,以及创建一系列复杂的if语句来确定当前到底处于什么情形。
接下来,你将把学到的知识应用于列表,以编写for循环,以一种方式处理列表中的大多数元素,并以另一种不同的方式处理包含特定值的元素。
5.1:一个简单示例下面是一个简短的示例,演示了如何使用if语句来正确地处理特殊情形。
假设你有一个汽车列表,并想将其中每辆汽车的名称打印出来。
对于大多数汽车,都应以首字母大写的方式打印其名称,但对于汽车名'bmw',应以全大写的方式打印。
下面的代码遍历一个列表,并以首字母大写的方式打印其中的汽车名,但对于汽车名'bmw',以全大写的方式打印:这个示例中的循环首先检查当前的汽车名是否是'bmw'。
如果是,就以全大写的方式打印它;否则就以首字母大写的方式打印;这个示例涵盖了本章将介绍的很多概念。
下面先来介绍可用来在程序中检查条件的测试。
5.2:条件测试每条if语句的核心都是一个值为True或False的表达式,这种表达式被称为条件测试。
Python根据条件测试的值为True还是False来决定是否执行if语句中的代码。
如果条件测试的值为True,Python就执行紧跟在if语句后面的代码;如果为False,Python就忽略这些代码。
5.2.1:检查是否相等大多数条件测试都将一个变量的当前值同特定值进行比较。
最简单的条件测试检查变量的值是否与特定值相等:我们首先使用一个等号将car的值设置为'bmw',这种做法你已见过很多次。
接下来,使用两个等号(==)检查car的值是否为'bmw'。
这个相等运算符在它两边的值相等时返回True,否则返回False。
第5章函数和代码复用5.1 函数的基本使用[5.1]: A[5.2]: D[5.3]: 错误。
[5.4]: 合法,因为Python语言是解释执行,即只要在真正调用函数之前定义函数,都可以进行合法调用。
5.2 函数的参数传递[5.5]: 在函数定义时,直接为可选参数指定默认值。
可选参数必须定义在非可选参数后面,可选参数可以有多个。
[5.6]: 在函数定义时,可变参数通过在参数前增加星号(*)实现。
可变数量参数只能在参数列表最后,即它只能有一个。
[5.7]: 返回值是元组类型。
[5.8]: 位置传递:支持可变数量参数,但容易忘记实参的含义;名称传递:不易忘记实参的含义,但不支持可变数量参数。
[5.9]: 如果函数里没有创建同名变量,则可以直接使用,不需global声明。
5.3 模块3:datetime库的使用[5.10]:print( "现在是{0:%Y}年{0:%m}月{0:%d}日{0:%I}:{0:%M}".format(datetime.now()))[5.11]: 答案不限。
举一个例子,输出美式日期格式:print("{0:%I}:{0:%M} {0:%b} {0:%d} {0:%Y}".format(datetime.now()))[5.12]: datetime对象可以直接做加减运算,所以可以用这样的方式给程序计时:1 2 Start = datetime.now() ... # 要计时的代码4 5 6 End = datetime.now() Cost = End – Start Print(Cost)5.4 实例7:七段数码管绘制[5.13]: 相当于C语言中的三目运算符。
[5.14]: 隐藏画笔的turtle形状。
[5.15]: 对应相应的年月日文字输出。
5.5 代码复用和模块化设计[5.16]: 错误,因为”使用函数“是“模块化设计“的必要条件。
Chapter 5 Loops1. count < 100 is always True at Point A. count < 100 isalways False at Point C. count < 100 is sometimes True orsometimes False at Point B.2.It would be wrong if it is initialized to a value between 0 and 100, because it could be the number you attempt to guess.When the initial guess value and random number are equal, the loop will never be executed.3. (a) Infinite number of times.(b) Infinite number of times.(c) The loop body is executed nine times. The printout is 2, 4, 6, 8 onseparate lines.4. (a) and (b) are infinite loops, (c) has an indentation error.5.max is 5number 06.sum is 14count is 47.Yes. The advantages of for loops are simplicity and readability. Compilers canproduce more efficient code for the for loop than for the corresponding whileloop.8. while loop:sum = 0i= 0while i <= 1000:sum += ii += 19. Can you always convert a while loop into a for loop?Not in Python. For example, you cannot convert the while loop in Listing 5.3,GuessNumber.py, to a for loop.sum = 0for i in range(1, 10000):if sum < 10000:sum = sum + i10.(A)n times(B)n times(C)n-5 times(D)The ceiling of (n-5)/3 times11.Tip for tracing programs:Draw a table to see how variables change in the program. Consider (a) for example.i j output1 0 01 12 0 02 1 12 23 0 03 1 13 2 23 34 0 04 1 14 2 24 3 34 4(A).0 0 1 0 1 2 0 1 2 3(B).********2 ****3 2 ****4 3 2 ****(C).1xxx2xxx4xxx8xxx16xxx1xxx2xxx4xxx8xxx1xxx2xxx4xxx1xxx2xxx1xxx(D).1G1G3G1G3G5G1G3G5G7G1G3G5G7G9G12.No. Try n1 = 3 and n2 =3.13. The keyword break is used to exit the current loop. The program in (A) willterminate. The output is Balance is 1.The keyword continue causes the rest of the loop body to be skipped for the current iteration. The while loop will not terminate in (B).14. If a continue statement is executed inside a for loop, the rest of the iteration is skipped, then the action-after-each-iteration is performed and the loop-continuation-condition is checked. If a continue statement is executed inside a while loop, the rest of the iteration is skipped, then the loop-continuation-condition is checked.Here is the fix:i = 0while i < 4:if i % 3 == 0:i += 1continuesum += ii += 115.TestBreak.pysum = 0number = 0while number < 20 and sum < 100:number += 1sum += numberprint("The number is " + str(number))print("The sum is " + str(sum))TestContinue.pysum = 0number = 0while (number < 20):number += 1if (number != 10 and number != 11): sum += numberprint("The sum is " + str(sum))16.(A)print(j)121223(B)for j in range (1,4):121223。
python语⾔程序设计基础课后答案-第五章(嵩天)教材: 1.七段数码管绘制 2.函数的递归 3.科赫曲线绘制习题:1. 输出⽥字格。
2. 实现isOdd()函数。
3. 实现isNum()函数。
4. 实现multi()函数。
5. 实现isPrime()函数。
6. 使⽤datetime库,对⾃⼰的⽣⽇输出不少于10种⽇期格式。
7. 输⼊汉诺塔层数,输出整个移动流程。
1.七段数码管绘制import turtle, datetimedef drawLine(draw): #绘制单段数码管turtle.pendown() if draw else turtle.penup()turtle.fd(40)turtle.right(90)def drawDigit(d):drawLine(True) if d in [2,3,4,5,6,8,9] else drawLine(False)drawLine(True) if d in [0,1,3,4,5,6,7,8,9] else drawLine(False)drawLine(True) if d in [0,2,3,5,6,8,9] else drawLine(False)drawLine(True) if d in [0,2,6,8] else drawLine(False)turtle.left(90)drawLine(True) if d in [0,4,5,6,8,9] else drawLine(False)drawLine(True) if d in [0,2,3,5,6,7,8,9] else drawLine(False)drawLine(True) if d in [0,1,2,3,4,7,8,9] else drawLine(False)turtle.left(180)turtle.penup()turtle.fd(20)def drawDate(date): #获得要输出的数字for i in date:drawDigit(eval(i)) #注意: 通过eval()函数将数字变为整数def main():turtle.setup(800, 350, 200, 200)turtle.penup()turtle.fd(-300)turtle.pensize(5)drawDate(datetime.datetime.now().strftime('%Y%m%d'))turtle.hideturtle()main()import turtle, datetimedef drawGap():#绘制数码管间隔turtle.penup()turtle.fd(5)def drawLine(draw): #绘制单段数码管drawGap()turtle.pendown() if draw else turtle.penup()turtle.fd(40)drawGap()turtle.right(90)def drawDigit(d):drawLine(True) if d in [2,3,4,5,6,8,9] else drawLine(False)drawLine(True) if d in [0,1,3,4,5,6,7,8,9] else drawLine(False)drawLine(True) if d in [0,2,3,5,6,8,9] else drawLine(False)drawLine(True) if d in [0,2,6,8] else drawLine(False)turtle.left(90)drawLine(True) if d in [0,4,5,6,8,9] else drawLine(False)drawLine(True) if d in [0,2,3,5,6,7,8,9] else drawLine(False)drawLine(True) if d in [0,1,2,3,4,7,8,9] else drawLine(False)turtle.left(180)turtle.penup()turtle.fd(20)def drawDate(date): #获得要输出的数字turtle.pencolor("red")for i in date:if i=='-':turtle.write('年',font=("Arial",18,"normal"))turtle.pencolor("green")turtle.fd(40)elif i=='=':turtle.write('⽉',font=("Arial",18,"normal"))turtle.pencolor("blue")turtle.fd(40)elif i=='+':turtle.write('⽇',font=("Arial",18,"normal"))else:drawDigit(eval(i)) #注意: 通过eval()函数将数字变为整数def main():turtle.setup(800, 350, 200, 200)turtle.penup()turtle.fd(-300)turtle.pensize(5)drawDate(datetime.datetime.now().strftime('%Y-%m=%d+'))turtle.hideturtle()main()(数码管绘制10进制变为16进制,作为字符串输⼊)import turtle, datetimea=input('')def drawGap():#绘制数码管间隔turtle.penup()turtle.fd(5)def drawLine(draw): #绘制单段数码管drawGap()turtle.pendown() if draw else turtle.penup()turtle.fd(40)drawGap()turtle.right(90)def drawDigit(d):drawLine(True) if d in ['2','3','4','5','6','8','9','a','b','d','e','f'] else drawLine(False) drawLine(True) if d in ['0','1','3','4','5','6','7','8','9','a','b','d'] else drawLine(False) drawLine(True) if d in ['0','2','3','5','6','8','9','b','c','d','e'] else drawLine(False) drawLine(True) if d in ['0','2','6','8','a','b','c','d','e','f'] else drawLine(False)turtle.left(90)drawLine(True) if d in ['0','4','5','6','8','9','a','b','c','e','f'] else drawLine(False)drawLine(True) if d in ['0','2','3','5','6','7','8','9','a','c','e','f'] else drawLine(False) drawLine(True) if d in ['0','1','2','3','4','7','8','9','a','d'] else drawLine(False)turtle.left(180)turtle.penup()turtle.fd(20)def drawDate(date): #获得要输出的数字turtle.pencolor("red")for i in date:drawDigit(i)def drawDate1(date): #获得要输出的数字turtle.pencolor("red")count=0for i in date:count+=1if count>2:drawDigit(i)def main():turtle.setup(800, 350, 200, 200)turtle.penup()turtle.fd(-300)turtle.pensize(5)drawDate(a)turtle.fd(20)turtle.pendown()turtle.fd(145)turtle.penup()turtle.fd(20)b=hex(int(a))print(b)drawDate1(str(b))turtle.hideturtle()main()2.科赫曲线绘制import turtledef koch(size,n):if n==0:turtle.fd(size)else:for angle in [0,60,-120,60]:turtle.left(angle)koch(size/3,n-1)def main():turtle.setup(800,400)turtle.speed(0)#控制绘制速度turtle.penup()turtle.goto(-300,-50)turtle.pendown()turtle.pensize(2)koch(600,3)#0阶科赫曲线长度,阶数 turtle.hideturtle()main()import turtledef koch(size,n):if n==0:turtle.fd(size)else:for angle in [0,60,-120,60]:turtle.left(angle)koch(size/3,n-1)def main():turtle.setup(400,400)turtle.speed(0)#控制绘制速度turtle.penup()turtle.goto(-200,-100)turtle.pendown()turtle.pensize(2)turtle.pencolor("green")level=5koch(300,4)turtle.right(120)turtle.pencolor("blue")koch(300,4)turtle.right(120)turtle.pencolor("red")koch(300,4)turtle.hideturtle()main()输出⽥字格。
《Python程序设计》习题与参考答案第1章基础知识1。
1 简单说明如何选择正确的Python版本。
答:在选择Python的时候,一定要先考虑清楚自己学习Python的目的是什么,打算做哪方面的开发,有哪些扩展库可用,这些扩展库最高支持哪个版本的Python,是Python 2.x还是Python 3。
x,最高支持到Python 2.7。
6还是Python 2。
7.9。
这些问题都确定以后,再做出自己的选择,这样才能事半功倍,而不至于把大量时间浪费在Python的反复安装和卸载上。
同时还应该注意,当更新的Python版本推出之后,不要急于更新,而是应该等确定自己所必须使用的扩展库也推出了较新版本之后再进行更新。
尽管如此,Python 3毕竟是大势所趋,如果您暂时还没想到要做什么行业领域的应用开发,或者仅仅是为了尝试一种新的、好玩的语言,那么请毫不犹豫地选择Python 3.x系列的最高版本(目前是Python 3.4。
3).1.2 为什么说Python采用的是基于值的内存管理模式?答:Python采用的是基于值的内存管理方式,如果为不同变量赋值相同值,则在内存中只有一份该值,多个变量指向同一块内存地址,例如下面的代码。
〉〉〉x = 3〉>〉id(x)10417624>>> y = 3>>〉id(y)10417624〉>> y = 5>〉> id(y)10417600>〉〉id(x)104176241.3 在Python中导入模块中的对象有哪几种方式?答:常用的有三种方式,分别为import 模块名[as 别名]●from 模块名import 对象名[as 别名]●from math import *1.4 使用pip命令安装numpy、scipy模块。
答:在命令提示符环境下执行下面的命令:pip install numpypip install scipy1。
XX医学院本科各专业《Python》第五章习题与答案一、选择题1.Python中定义函数的关键字是(A)A.defB.defineC.functionD.defunc2. 下列不是使用函数的优点的是(D)A.减少代码重复 B.使程序更加模块化C.使程序便于阅读 D.为了展现智力优势3.关于函数参数传递中,形参与实参的描述错误的是( D)。
A.python实行按值传递参数。
值传递指调用函数时将常量或变量的值(实参)传递给函数的参数(形参)B.实参与形参存储在各自的内存空间中,是两个不相关的独立变量C.在参数内部改变形参的值,实参的值一般是不会改变的D.实参与形参的名字必须相同4. 关于Python的lambda函数,以下选项中描述错误的是(B )mbda函数将函数名作为函数结果返回B.f = lambda x,y:x+y 执行后,f的类型为数字类型mbda用于定义简单的、能够在一行内表示的函数D.可以使用lambda函数定义列表的排序原则:以下选项不是函数作用的是(A5.)A.提高代码执行速度B.增强代码可读性C.降低编程复杂度D.复用代码以下关于函数说法错误的是(D)6.:A.函数可以看做是一段具有名字的子程序B.函数通过函数名来调用C.函数是一段具有特定功能的、可重用的语句组D.对函数的使用必须了解其内部实现原理7. 以下关于函数调用描述正确的是:(A)A.自定义函数调用前必须定义B.函数在调用前不需要定义,拿来即用就好C.Python内置函数调用前需要引用相应的库D.函数和调用只能发生在同一个文件中8. 关于return语句,以下选项描述正确的是:(D)A.函数中最多只有一个return语句B.函数必须有一个return语句C.return只能返回一个值D.函数可以没有return语句9.下面说法正确的是:(B)def f(a,b):a = 4return a + bdef main():m = 5n = 6print(f(m,n),m + n)main()A.m、n为形式参数B.程序的输出结果为10 11C.a、b为实际参数D.以上说法均不正确10.以下关于Python函数说法错误的是:(B)def func(a,b):c = a ** 2 + bb = areturn ca = 10b = 100c = func(a,b) + aA.该函数名称为funcB.执行该函数后,变量c的值为200C.执行该函数后,变量a的值为10D.执行该函数后,变量b的值为10011.max()函数的作用是(C)A.求两个数的最大值B.求三个数的最大值C.返回若干数的最大值D.返回若干数的最小值()12. 哪个选项对于函数的定义是错误的?CA.def vfunc(a,*b):B.def vfunc(a,b=2):C.def vfunc(*a,b):D.def vfunc(a,b):13.下列说法错误的是(D)A.在函数内部直接修改形参的值并不影响外部实参的值。
if考试题库及答案1. 阅读以下代码段,并选择正确的输出结果。
```pythonx = 10if x > 5:print("x is greater than 5")else:print("x is not greater than 5")```A. x is greater than 5B. x is not greater than 5C. NoneD. Syntax Error正确答案:A2. 考虑以下Python函数,确定它将返回什么值。
```pythondef check_value(value):if value > 0:return "Positive"elif value == 0:return "Zero"else:return "Negative"```当调用`check_value(-5)`时,函数将返回:A. PositiveB. ZeroC. NegativeD. None正确答案:C3. 以下代码段将打印什么?```pythony = 20if y % 2 == 0:print("Even")else:print("Odd")```A. EvenB. OddC. Even OddD. None正确答案:A4. 完成以下代码,使其能够正确地根据输入值打印出“High”,“Medium”或“Low”。
```pythonscore = float(input("Enter a score between 0 and 100: ")) if score >= 90:print("High")elif score >= 70:print("Medium")else:print("Low")该代码段缺少的部分是:A. score的类型转换B. 条件判断C. 输入提示D. 打印语句正确答案:A5. 以下代码段的输出是什么?```pythonz = 15if z > 10:print("z is greater than 10") if z < 20:print("z is less than 20")```A. z is greater than 10B. z is less than 20C. z is greater than 10z is less than 20D. None正确答案:C6. 以下代码段将执行多少次循环?```pythoncounter = 0while counter < 5:counter += 1```B. 5C. 6D. Infinite Loop正确答案:B7. 以下代码段将打印什么?```pythona = 5b = 10if a < b:print("a is less than b") elif a == b:print("a is equal to b") else:print("a is greater than b") ```A. a is less than bB. a is equal to bC. a is greater than bD. None正确答案:A8. 以下代码段将打印什么?```pythonc = 0d = 0if c == d:print("c and d are equal")elif c > d:print("c is greater than d") else:print("c is less than d")```A. c and d are equalB. c is greater than dC. c is less than dD. None正确答案:A9. 以下代码段将打印什么?```pythone = 8f = 2if e % f == 0:print("e is divisible by f") else:print("e is not divisible by f") ```A. e is divisible by fB. e is not divisible by fC. e is divisible by fe is not divisible by fD. None正确答案:A10. 以下代码段将打印什么?```pythong = -3h = -7if g > h:print("g is greater than h") elif g == h:print("g is equal to h") else:print("g is less than h")```A. g is greater than hB. g is equal to hC. g is less than hD. None正确答案:A。
python从⼊门到实践课后习题第五章"""5-1 条件测试:编写⼀系列条件测试;将每个测试以及你对其结果的预测和实际结果都打印出来。
你编写的代码应类似于下⾯这样:car = 'subaru'print("Is car == 'subaru'? I predict True.")print(car == 'subaru')print("\nIs car == 'audi'? I predict False.")print(car == 'audi')详细研究实际结果,直到你明⽩了它为何为 True 或 False 。
创建⾄少 10 个测试,且其中结果分别为 True 和 False 的测试都⾄少有 5 个。
"""car = 'audi'print(car == 'subaru')print(car == 'audi')name = 'Louie'print(name == 'link')print(name == 'louie')print(name.lower() == 'louie')"""5-2 更多的条件测试:你并⾮只能创建 10 个测试。
如果你想尝试做更多的⽐较,可再编写⼀些测试,并将它们加⼊到 conditional_tests.py 中。
对于下⾯列出的各种测试,⾄少编写⼀个结果为 True 和 False 的测试。
检查两个字符串相等和不等。
使⽤函数 lower() 的测试。
检查两个数字相等、不等、⼤于、⼩于、⼤于等于和⼩于等于。
使⽤关键字 and 和 or 的测试。
5-1.整型。
讲讲Python普通整型和长整型的区别。
答案:Python的标准整数类型是最通用的数字类型。
在大多数32位机器上,标准整数类型的取值范围是-2**31到2**31-1.Python的长整数类型能表达的数值仅仅与你的机器支持的(虚拟)内存大小有关,换句话说,Python能轻松表达很大的整数。
长整型类型是标准整数类型的超集,当程序需要使用比标准整型更大的整型时,可以使用长整型类型。
在一个整型值后面加个L,表示这个整型是长整型。
这两种整数类型正在逐渐统一为一种。
剩下的一种整型类型是布尔类型。
即布尔True和布尔False。
5-2.操作符。
(a)写一个函数,计算并返回两个数的乘积。
(b)写一段代码调用这个函数,并显示它的结果。
答案:def multiply(x,y):return x*ya = raw_input('input number 1: ')b = raw_input('input number 2: ')print multiply(float(a),float(b))5-3.标准类型操作符。
写一段脚本,输入一个测验成绩,根据下面的标准,输出他的评分成绩(A-F)。
A:90~100 B:80~89 C:70~79 D:60~69 F:<60答案:score = int(raw_input('input your score: '))if score > 100:print "your score is wrong!!"elif score >= 90:print 'A'elif score >= 80:print 'B'elif score >= 70:print 'C'elif score >= 60:print 'D'else:print 'F'5-4.取余。
Solutions - Chapter 55-3: Alien Colors #1Imagine an alien was just shot down in a game. Create a variable called alien_color and assign it a value of 'green', 'yellow',or 'red'.∙Write an if statement to test whether the alien’s color is green.If it is, print a message that the player just earned 5 points.∙Write one version of this program that passes the if test and another tha fails. (The version that fails will have no output.) Passing version:Output:Failing version:(no output)5-4: Alien Colors #2Choose a color for an alien as you did in Exercise 5-3, and writean if-else chain.∙If the alien’s color is green, print a statement that the player just earned 5 points for shooting the alien.∙If the alien’s coor isn’t green, print a statement that the player just earned 10 points.∙Write one version of this program that runs the if block and another that runs the else block.if block runs:Output:else block runs:Output:5-5: Alien Colors #3Turn your if-else chain from Exercise 5-4 intoan if-elif-else cahin.∙If the alien is green, print a message that the player earned 5 points.∙If the alien is yellow, print a message that the player earned 10 points.∙If the alien is red, print a message that the player earned 15 points.∙Write three versions of this program, making sure each message is printed for the appropriate color alien.Output for 'red' alien:5-6: Stages of LifeWrite an if-elif-else cahin that determines a person’s stage of life. Set a value for the variable age, and then:∙If the person is less than 2 years old, print a message that the person is a baby.∙If the person is at least 2 years old but less than 4, print a message that the person is a toddler.∙If the person is at least 4 years old but less than 13, print a message that the person is a toddler.∙If the person is at least 13 years old but less than 20, print a message that the person is a toddler.∙If the person is at least 20 years old but less than 65, print a message that the person is a toddler.∙If the person is age 65 or older, print a message that the person is an elder.Output:5-7: Favorite FruitMake a list of your favorite fruits, and then write a series of independent if statements that check for certain fruits in your list.∙Make a list of your three favorite fruits and callit favorite_fruits.∙Write five if statements. Each should check whether a certainkind of fruit is in your list. If the fruit is in your list, the if blockshould print a statement, such as You really like bananas!Output:5-8: Hello AdminMake a list of five or more usernnames, including the name 'admin'.Imagine you are writing code that will print a greeting to each user after they log in to a website. Loop through the list, and print a greeting to each user:∙If the username is 'admin', print a special greeting, such as Hello admin, would you like to see a status report?∙Otherwise, print a generic greeting, such as Hello Eric, thank you for loggin in again.Output:5-9: No UsersAdd an if test to hello_admin.py to make sure the list of users is not empty.∙If the list is emtpy, print the message We need to find some users!∙Remove all of the usernames from your list, and make sure the correct message is printed.Output:5-10: Checking UsernamesDo the following to create a program that simulates how websites ensure that everyone has a unique username.∙Make a list of five or more usernames called current_users.Make another list of five usernames called new_users. Makesure one or two of the new usernames are also inthe current_users list.∙Loop through the new_users list to see if each new username has already been used. If it has, print a message that theperson will need to enter a new username. If a username has not been used, print a message saying that the username isavailable.∙Make sure your comparison is case insensitive. If 'John' has been used, 'JOHN' should not be accepted.Output:Note: If you’re not comfortable with list comprehensions yet, thelist current_users_lower can be generated using a loop:5-11: Ordinal NumbersOrdinal numbers indicate their position in a list, such as 1st or 2nd. Most ordinal numbers end in th, except 1, 2, and 3.∙Store the numbers 1 through 9 in a list.∙Loop through the list.∙Use an if-elif-else chain inside the loop to print the proper ordinal ending for each number. Your output should read "1st2nd 3rd 4th 5th 6th 7th 8th 9th", and each result should be ona separate line.Output:。