首页 > 编程知识 正文

python百例练习之第八例(python的例题)

时间:2023-12-18 17:21:47 阅读:317178 作者:ATXG

本文目录一览:

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练习题请教?

脚本从左向右执行:

ls[2] = [10, "LIST"]

ls[2][-1] = "LIST" 就是 [10, "LIST"][-1] 就是 "LIST"

ls[2][-1][1] 就是 "LIST"[1] 就是 "LIST" 的第二个字符,就是 I

所以 ls[2][-1][1] = "I"

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练习题怎么做?

stds_list= [

{"id": 1, "name": "小明", "c_s": 85, "python_s": 78},

{"id": 2, "name": "小花", "c_s": 69, "python_s": 88},

{"id": 3, "name": "小东", "c_s": 79, "python_s": 83},

]

# 1) 显示学生信息:“学生id:学生姓名:小明,C语言成绩:85, Python成绩:78”。

for ind in range(len(stds_list)):

if stds_list[ind]['name'] == '小明':

print('学生id:{id},学生姓名:{name},C语言成绩:{c_s}, Python成绩:{python_s}'.format(**stds_list[ind]))

# 2) 修改“小明”的Python成绩为90

for ind in range(len(stds_list)):

if stds_list[ind]['name'] == '小明':

stds_list[ind]['python_s'] = 90

break

# 3) 删除“小东”的信息

for ind in range(len(stds_list)):

if stds_list[ind]['name'] == '小东':

del stds_list[ind]

break

# 2. 定义一个空列表,用于保存5个学生信息,一个学生信息包括三个属性:id、姓名、年龄

# 提示:列表元素是字典、向列表中添加数据用append()

stds_list2 = []

for i in range(5):

print('第{}个学生信息:')

stds_list2.append({})

for j in ['id','姓名','年龄']:

stds_list2[-1][j] = input('{}:'.format(j))

print(stds_list2)

代码缩进

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