首页 > 编程知识 正文

趣学python第8章练习题(python第二章题库)

时间:2023-12-13 14:15:36 阅读:315197 作者:DEKX

本文目录一览:

python练习题求助

chars=[chr(i+ord('a')) for i in range(26)]

print(chars)

result=[]

index=0

count=0

order=1

while True:

    if count==26:

        break

    if chars[index].isalpha():

        if order%5==0:

            result.append(chars[index])

            chars[index]='0'

            count+=1

        order+=1

    index=(index+1)%26

print(result)

python练习题

#!/usr/bin/env/python

# coding: utf-8

#

def fibonacci(n):

    """

    This question is about Fibonacci number. For your information, the Fibonacci sequence is as follows:

    0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, ...

    That is, the first two Fibonacci numbers are 0 and 1, each Fibonacci number after that is equal to the sum of the

    two numbers that precede it. For example, the third Fibonacci number is equal to the sum of the first and

    second number, the fourth number is equal to the sum of the second and third number, and so on ...

    Write a program that asks the user to enter a positive integer n, then your program should print/output in one

    line the Fibonacci sequence up to n.

    For example, if n is 100, your program should output 0,1,1,2,3,5,8,13,21,34,55,89,

    If n is 8, your program should output 0,1,1,2,3,5,8,

    """

    def __iter__(n):

        a, b = 0, 1

        

        yield a

        if n == 0:

            return

        yield b

        if n == 1:

            return

            

        while a + b = n:

            a, b = b, a+b

            yield b

    return list(__iter__(n))

if __name__ == "__main__":

    print fibonacci(35)

Python中基础练习题?

法一:利用set()函数的去重功能,去重后再使用list()函数将集合转换为我们想要的列表

list1 = [11,22,33]

list2 = [22,33,44]

list3 = list(set(list1 + list2))

list3.sort()

print(list3)

-------------

法二:利用if和for,先遍历list1所有元素追加到list3中,然后遍历list2,条件判断list2中当前元素是否在list3中,如果不在则追加到list3中

list1 = [11,22,33]

list2 = [22,33,44]

list3 = []

for ele1 in list1:

list3.append(ele1)

for ele2 in list2:

if ele2 not in list3:

list3.append(ele2)

print(list3)

《python从入门到实践》练习题有答案吗

找不到,只找到找到几道题目的答案

8-9  魔术师:创建一个包含魔术师名字的列表,并将其传递给一个名为show_magicians() 的函数,这个函数打印列表中每个魔术师的名字。8-10  了不起的魔术师:在你为完成练习 8-9 而编写的程序中,编写一个名为make_great() 的函数,对魔术师列表进行修改,在每个魔术师的名字中都加入字样“theGreat”。调用函数 show_magicians() ,确认魔术师列表确实变了。想问下大神怎么对魔术师列表进行修改同时又不使用新的列表,我修改了一次但是用了一个新列表的方法和原习题不符。

关于python 语言基础的练习题?

一、Python语言的简述

Python语言是一种解释型、面向对象的编程语言,是一种开源语言。

Python属于动态类定义语言,也是一种强调类型语言。

二、Python语言的特点

1、简单、高级

2、面向对象

3、可扩展性、免费和开源的

4、可移植型、可嵌入型、丰富的库

三、Python语言的应用范围

1、操作系统管理

2、科学计算

3、Web应用

4、图形用户界面(GUI)开发

5、其他,例如游戏开发等

优点

简单:Python是一种代表简单主义思想的语言。阅读一个良好的Python程序就感觉像是在读英语一样。它使你能够专注于解决问题而不是去搞明白语言本身。

易学:Python极其容易上手,因为Python有极其简单的说明文档。

易读、易维护:风格清晰划一、强制缩进。

用途广泛。

速度快:Python的底层是用C语言写的,很多标准库和第三方库也都是用C写的,运行速度非常快。

免费、开源:Python是FLOSS(自由/开放源码软件)之一。使用者可以自由地发布这个软件的拷贝、阅读它的源代码、对它做改动、把它的一部分用于新的自由软件中。FLOSS是基于一个团体分享知识的概念。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。