python 第一天

循环打印

        while循环

languages = ["Regional Assembly Language","Autocode","FORTRAN","IPL (LISP的先驱)","FLOW-MATIC (COBOL的先驱)","COMTRAN (COBOL的先驱)","LISP","ALGOL 58","FACT (COBOL的先驱)","COBOL","APL","Simula","SNOBOL","CPL (C的先驱)","BASIC","PL/I","BCPL (C的先驱)","Logo","Pascal","Forth","C语言","Smalltalk","Prolog","ML","Scheme","SQL","Ada","C++","Common Lisp","MATLAB","Eiffel","Objective-C","Erlang","Perl","Tcl","FL (Backus)","Haskell","Python","Visual Basic","HTML","Ruby","Lua","CLOS (part of ANSI Common Lisp)","Java","Delphi (Object Pascal)","JavaScript","PHP","REBOL","D","C#","Visual Basic .NET","F#","Scala","Factor","Windows PowerShell","Rust","Clojure","Go"]
years = [1951, 1952, 1954, 1954, 1955, 1957, 1958, 1958, 1959, 1959, 1962, 1962, 1962, 1963, 1964, 1964, 1967 ,1968 ,1970 ,1970 ,1972 ,1972 ,1972 ,1973 ,1975 ,1978 ,1980 ,1983 ,1984 ,1984 ,1985 ,1986 ,1986 ,1987 ,1988 ,1989 ,1990 ,1991 ,1991 ,1991 ,1993 ,1993 ,1994 ,1995 ,1995 ,1995 ,1995 ,1997 ,1999 ,2001 ,2001 ,2002 ,2003 ,2003 ,2006 ,2006 ,2007 ,2009]
i = 0
while i < len(years):language = languages[i]year = years[i]print(language, ':', year)i += 1

        for循环

languages = ["Regional Assembly Language","Autocode","FORTRAN","IPL (LISP的先驱)","FLOW-MATIC (COBOL的先驱)","COMTRAN (COBOL的先驱)","LISP","ALGOL 58","FACT (COBOL的先驱)","COBOL","APL","Simula","SNOBOL","CPL (C的先驱)","BASIC","PL/I","BCPL (C的先驱)","Logo","Pascal","Forth","C语言","Smalltalk","Prolog","ML","Scheme","SQL","Ada","C++","Common Lisp","MATLAB","Eiffel","Objective-C","Erlang","Perl","Tcl","FL (Backus)","Haskell","Python","Visual Basic","HTML","Ruby","Lua","CLOS (part of ANSI Common Lisp)","Java","Delphi (Object Pascal)","JavaScript","PHP","REBOL","D","C#","Visual Basic .NET","F#","Scala","Factor","Windows PowerShell","Rust","Clojure","Go"]
years = [1951, 1952, 1954, 1954, 1955, 1957, 1958, 1958, 1959, 1959, 1962, 1962, 1962, 1963, 1964, 1964, 1967 ,1968 ,1970 ,1970 ,1972 ,1972 ,1972 ,1973 ,1975 ,1978 ,1980 ,1983 ,1984 ,1984 ,1985 ,1986 ,1986 ,1987 ,1988 ,1989 ,1990 ,1991 ,1991 ,1991 ,1993 ,1993 ,1994 ,1995 ,1995 ,1995 ,1995 ,1997 ,1999 ,2001 ,2001 ,2002 ,2003 ,2003 ,2006 ,2006 ,2007 ,2009]
i = 0
for i in range(0, len(languages)):language = languages[i]year = years[i]print(language, ':',year)i += 1

        陌生语法:把for循环套在print函数里

languages = ["Regional Assembly Language","Autocode","FORTRAN","IPL (LISP的先驱)","FLOW-MATIC (COBOL的先驱)","COMTRAN (COBOL的先驱)","LISP","ALGOL 58","FACT (COBOL的先驱)","COBOL","APL","Simula","SNOBOL","CPL (C的先驱)","BASIC","PL/I","BCPL (C的先驱)","Logo","Pascal","Forth","C语言","Smalltalk","Prolog","ML","Scheme","SQL","Ada","C++","Common Lisp","MATLAB","Eiffel","Objective-C","Erlang","Perl","Tcl","FL (Backus)","Haskell","Python","Visual Basic","HTML","Ruby","Lua","CLOS (part of ANSI Common Lisp)","Java","Delphi (Object Pascal)","JavaScript","PHP","REBOL","D","C#","Visual Basic .NET","F#","Scala","Factor","Windows PowerShell","Rust","Clojure","Go"]
years = [1951, 1952, 1954, 1954, 1955, 1957, 1958, 1958, 1959, 1959, 1962, 1962, 1962, 1963, 1964, 1964, 1967 ,1968 ,1970 ,1970 ,1972 ,1972 ,1972 ,1973 ,1975 ,1978 ,1980 ,1983 ,1984 ,1984 ,1985 ,1986 ,1986 ,1987 ,1988 ,1989 ,1990 ,1991 ,1991 ,1991 ,1993 ,1993 ,1994 ,1995 ,1995 ,1995 ,1995 ,1997 ,1999 ,2001 ,2001 ,2002 ,2003 ,2003 ,2006 ,2006 ,2007 ,2009][print(languages[i], ':', years[i]) for i in range(0, len(languages))]

问题:编写一个程序,它将找到所有这些数字,可被7整除,但不是5的倍数,2000年至3200年(包括在内)。得到的数字应按逗号分隔的顺序打印在一行上。
提示:考虑使用range(#begin, #end)方法

l = []
for i in range(2000 , 3201):if (i%7==0) and (i%5!=0):l.append(str(i))print(','.join(l))

join的使用:将容器之中的各个元素之间用指定符号连接。

问题:编写一个可以计算给定数的阶乘的程序。结果应该以逗号分隔的顺序打印在一行上。假设向程序提供以下输入:8
则输出为:40320
提示:在为问题提供输入数据的情况下,应该假设它是控制台输入。

def fact(x):if x == 0:return 1return x * fact(x - 1)
x = int(input('请输入一个数字:'))
print(fact(x))

问题:使用给定的整数n,编写一个程序生成一个包含(i, i*i)的字典,该字典包含1到n之间的整数(两者都包含)。然后程序应该打印字典。
假设向程序提供以下输入:8
则输出为:
{1:1,2:4,3:9,4:16,5:25,6:36,,7:49,8:64}
提示:在为问题提供输入数据的情况下,应该假设它是控制台输入。考虑使用dict类型()

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/20855.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【Vulhub】Fastjson 1.2.24_rce复现

文章目录 一&#xff0c;Fastjson是什么&#xff1f;二&#xff0c;fastjson漏洞原理三&#xff0c;判断是否有fastjson反序列化四&#xff0c;复现Fastjson 1.2.24_rce(vulhub)环境配置1.判断是否存在Fastjson反序列化2.反弹shell3.启动RMI服务器4.构造恶意POST请求 一&#x…

[数据集][目标检测]老鼠检测数据集VOC+YOLO格式4107张1类别

数据集格式&#xff1a;Pascal VOC格式YOLO格式(不包含分割路径的txt文件&#xff0c;仅仅包含jpg图片以及对应的VOC格式xml文件和yolo格式txt文件) 图片数量(jpg文件个数)&#xff1a;4107 标注数量(xml文件个数)&#xff1a;4107 标注数量(txt文件个数)&#xff1a;4107 标注…

linux tomcat版本漏洞升级

Tomcat Session 反序列化代码执行漏洞(CVE-2020-9484) Tomcat 安全限制绕过漏洞(CVE-2018-8034) Tomcat远程代码执行漏洞(CVE-2017-12615) 以上均可以升级版本处理&#xff0c;小版本升级方法 tomcat安装请查看https://blog.csdn.net/qq_42250832/article/details/139015573 1、…

制作ChatPDF之Elasticsearch8.13.4搭建(一)

Elasticsearch8.x搭建 在Windows系统上本地安装Elasticsearch的详细步骤如下&#xff1a; 1. 下载Elasticsearch 访问 Elasticsearch下载页面。选择适用于Windows的版本8.13.4&#xff0c;并下载ZIP文件。 2. 解压文件 下载完成后&#xff0c;找到ZIP文件&#xff08;例如…

AI预测体彩排3采取888=3策略+和值012路一缩定乾坤测试6月1日预测第8弹

今天继续基于8883的大底进行测试&#xff0c;今天继续测试&#xff0c;好了&#xff0c;直接上结果吧~ 首先&#xff0c;888定位如下&#xff1a; 百位&#xff1a;8,9,7,6,4,3,2,0 十位&#xff1a;4,5,3,2,7,8,0,9 个位&#xff1a;3,4,5,2,…

Centos 7部署NTP

介绍 NTP是Network Time Protocol&#xff08;网络时间协议&#xff09;的简称&#xff0c;它是用来通过互联网或局域网将计算机时钟同步到世界协调时间&#xff08;UTC&#xff09;的协议。 安装 # yum安装 yum install -y ntp# 离线安装 #下载地址&#xff1a;https://mir…

Golang | Leetcode Golang题解之第126题单词接龙II

题目&#xff1a; 题解&#xff1a; //bfsdfs(如果是双向bfs&#xff0c;效果会更好) func findLadders(beginWord string, endWord string, wordList []string) [][]string {//字典表&#xff08;将wordList中的单词放入hash表中&#xff0c;方便查找&#xff09;dict:make(m…

golang结构体struct递归引用异常解决办法: invalid recursive type: xxx refers to itself

异常信息&#xff1a; person.go:13:6: invalid recursive type: Person refers to itself 异常代码&#xff1a; type Person struct{Name stringAge intChild Person // 错误&#xff01; } 原因&#xff1a; 编译器无法确定一个包含自己的字段类型的类型的大小&#xff0c…

Android 安卓通过bindService ServiceConnection 没有响应的问题

bindService 失败且 ServiceConnection 没有响应可能由多种原因造成。以下是一些可能的原因和相应的解决方法&#xff1a; Service未正确声明或注册&#xff1a; 如果Service没有在AndroidManifest.xml文件中正确声明或注册&#xff0c;bindService将会失败。解决方法&#xf…

基于SpringBoot3和JDK17,集成H2数据库和jpa

基于SpringBoot3和JDK17&#xff0c;集成H2数据库和jpa 学会用H2数据库&#xff0c;为了快速写出需要处理数据关系的demo。 文章目录 基于SpringBoot3和JDK17&#xff0c;集成H2数据库和jpa工程配置pom.xml文件application.properties文件 练习H2数据库的操作h2数据库的建表自…

接口测试之XML响应断言

目录 XPath 基本语法XML 响应结果解析XML 响应结果断言 XML 响应数据 如何提取 AddResult 中的值&#xff1f; <soap:Body><AddResponse xmlns"http://tempuri.org/"><AddResult>4</AddResult></AddResponse> </soap:Body> …

【创作活动】如何让大模型更聪明:提升智能的技术策略

&#x1f604; 19年之后由于某些原因断更了三年&#xff0c;23年重新扬帆起航&#xff0c;推出更多优质博文&#xff0c;希望大家多多支持&#xff5e; &#x1f337; 古之立大事者&#xff0c;不惟有超世之才&#xff0c;亦必有坚忍不拔之志 &#x1f390; 个人CSND主页——Mi…

Java基础入门day62

day62 AJAX 概念 AJAX&#xff1a; Asynchronous Javascript And XML AJAX是一种无需重新加载整个网页的情况下&#xff0c;能够更新部分网页的技术 AJAX是一种用于创建快速动态网页的技术 通过在后台与服务器进行少量数据交换&#xff0c;AJAX可以使网页实现异步更新 传统…

Hbase 面试题(三)

1. 请表述Hbase 实时查询的原理和方式 &#xff1f; HBase支持实时查询&#xff0c;这意味着用户可以即时地访问和检索存储在HBase中的数据。HBase的实时查询原理和方式涉及以下几个关键方面&#xff1a; 内存存储&#xff08;MemStore&#xff09;&#xff1a; 当数据被写入H…

11.3 冒泡排序

目录 11.3 冒泡排序 11.3.1 算法流程 11.3.2 效率优化 11.3.3 算法特性 11.3 冒泡排序 冒泡排序&#xff08;bubble sort&#xff09;通过连续地比较与交换相邻元素实现排序。这个过程就像气泡从底部升到顶部一样&#xff0c;因此得名冒泡排序。 如图 11-4 所示…

【TIPs】 Visual Stadio 2019 中本地误使用“git的重置 - 删除更改 -- hard”后,如何恢复?

环境&#xff1a; VS 2019Windows10本地版本管理&#xff08;非远程&#xff09; 前言&#xff1a; git 在Visual Stadio 2019中集成了git的版本管理&#xff0c;在本地用来做版本管理&#xff0c;本来比较好用。 不过有一次&#xff0c;由于拿最初始的版本的时候&#xf…

JsonCpp源码跨平台编译

1.macos编译jsoncpp: https://github.com/open-source-parsers/jsoncpp.git 克隆jsoncpp源码 使用CMake进行编译 生成makefile mkdir build cd build cmake ../ 编译: make编译并运行测试成功:

数据的表示和运算

目录 一.各进制间的相互转换 1.各进制转化为10进制 2.二进制和八进制&#xff0c;十六进制之间地相互转化 3.十进制转换为其他进制 二.BCD码&#xff08;Binary-Coded Decimal&#xff0c;用二进制编码的十进制&#xff09; 1.8421码 2.余3码 3.2421码 三.无符号整数 …

Pytorch的学习

1.基本数据&#xff1a;Tensor Tensor&#xff0c;即张量&#xff0c;是PyTorch中的基本操作对象&#xff0c;可以看做是包含单一数据类型元素的多维矩阵。从使用角度来看&#xff0c;Tensor与NumPy的ndarrays非常类似&#xff0c;相互之间也可以自由转换&#xff0c;只不过Te…