首页 > 编程知识 正文

python编程题,python编程课后题答案

时间:2023-05-04 10:08:34 阅读:146288 作者:4229

快到春节了,怎么能不让自己在假期里掉队呢? 今天,营长给大家准备项目。 100编程练习。 如果你能坚持每天至少完成一个这些问题,你一定能帮助你的简单get Python编程技能。 目前,该项目获得2924 Stars、2468 Forks。

首先,这100道习题根据难度分为1级、2级和3级三个等级。 介绍了如何界定这三个层次,大家可以根据自己的学习能力和实践经验进行选择。

级别1 :初级。 刚进入Python,正在学习基础课程的学生们。 通常,包含1到2个类或函数的问题是可以解决的。 另外,在一些教材中可能会找到答案。

第2级:中级。 在系统中学习Python,已经有一定编程背景的学生们,可以解决包含三个以上班级和函数的问题,但是在教材中找不到这些答案。

可以使用Level 3(高级) Python上非常丰富的各种库、标准软件包或更高的技术,结合数据结构和算法来解决复杂的问题。

其次,有问题的说明、提示和解决方案。 请大家一定要独立完成,然后再看参考回答哦~

在前25个问题中,Q1~5、22~25均为1级难度,Q6~17为2级,Q18~22为3级。 大家正好利用这五个问题学习基础,巩固基础,然后开始准备挑战自己。

首先提出前五个问题,其他问题大家都可以在Github上看到~

Question 1 Level 1 Question:

writeaprogramwhichwillfindallsuchnumberswhicharedivisibleby7butarenotamultipleof 5,

between 2000 and 3200 (已封装)。

thenumbersobtainedshouldbeprintedinacomma-separatedsequenceonasingleline。

Hints:

consideruserange(#begin,#end )方法

question 2第1级question :

writeaprogramwhichcancomputethefactorialofagivennumbers。

theresultsshouldbeprintedinacomma-separatedsequenceonasingleline。

supposethefollowinginputissuppliedtotheprogram 33608 then,theoutputshouldbe :40320 hints :

incaseofinputdatabeingsuppliedtothequestion,itshouldbeassumedtobeaconsoleinput。

question 3第1级question :

With a given integral number n,writeaprogramtogenerateadictionarythatcontains (I * I ) suchthatisanintegralnumberbetween1and (I * I )

supposethefollowinginputissuppliedtotheprogram 33608 then,the output should be:

{ 1:1、2:4、9、4:16、5:25、6336036、7336049、8:64 }

Hints:

incaseofinputdatabeingsuppliedtothequestion,itshouldbeassumedtobeaconsoleinput。

康赛德用户目录(

question 4第1级question :

writeaprogramwhichacceptsasequenceofcomma-separatednumbersfromconsoleandgeneratealistandatuplewhichcontainseverynumber。

supposethefollowinginputissuppliedtotheprogram 336034、67、55、33、12、98 then,the output should be:

['34 '、' 67 '、' 55 '、' 33 '、' 12 '、' 98']

(34、67、55、33、12、98 ) )

Hints:

incaseofinputdatabeingsuppliedtothequestion,itshouldbeassumedtobeaconsoleinput。

tuple ) )方法can convert list to tuple

答案要点:

question 5第1级question :

defineaclasswhichhasatleasttwomethods 3360 getstring 3360 togetastringfromconsoleinput

printstring : toprintthestringinuppercase。

alsopleaseincludesimpletestfunctiontotesttheclassmethods.hints 3360

*解决方案1 *

l=[ ] foriinrange (2000,3201 ) :

if(I%7==0) and ) I%5!=0) :

L.append(str(I ) ) print ','.join(l ) l ) ) ) ) )。

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

*解决方案2 * def fact (x ) : if x==0:

返回1返回*传真(x-1 ) )

x=int(raw_input ) ) print fact(x ) x ) ) ) ) ) ) ) )。

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

*解决方案3 *

n=int(raw_input ) )

d=dict(forIinrange ) 1,n 1) :

d [ I ]=I * I打印d

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

*解决方案4 *

values=raw_input ()

l=values.split (,) )

t=tuple(l )打印l打印t

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

*解决方案5 * classinputoutstring (object ) : def _ _ init _ (self ) : self.s=' ' '

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