首页 > 编程知识 正文

包含关于python的十一道练习的词条

时间:2023-12-15 00:36:34 阅读:315859 作者:IVWC

本文目录一览:

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中基础练习题?

法一:利用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练习题

#!/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 语言基础的练习题?

一、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是基于一个团体分享知识的概念。

求解 python 练习题

import string

def makeWordList(input_file, output_file):

    

    table = string.maketrans("", "")

    try:

        word_list = dict()

        for line in open(input_file, 'r'):

            line = line.translate(table, string.punctuation).rstrip('rn').split(' ')

            for word in line:

                if not word in word_list:

                    word_list[word] = 1

                else:

                    word_list[word] += 1

        f = open(output_file, 'w')

        for k,v in word_list.items():

            line = '%s %srn' % (k,v)

            f.write(line)

    except:

        print input_file,'not exist'

            

            

    

makeWordList('input.txt', 'output.txt')

Python练习题?

1

print("hi, “”“how are you”””, I’m fine and you")

2

a, b= map(int, input().split())

r=a//b

m=a%b

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