python exercises with solutions

Read about python exercises with solutions, The latest news, videos, and discussion topics about python exercises with solutions from alibabacloud.com

Python Learning-Exercises (13)

) + Pow (int (s[1]), 3) + POW (int (s[2]), 3) = = I:print (i, end= ",") Answer3 () def answer4 (): "" "The collar uses the Divmod function to calculate : Return: "" " Print ("\ n Output four", end= ":") for I in range (+): M = i sumnum = 0 while m > 0: M, n = Divmod (M, ten) Sumnum + = n * * 3 if Sumnum = = I:print (i, end= ",") Answer4 () def answer5 ( ): "" is implemented using the list for if usage: return: "" "Print (" \ n Output five ", end=": ") L = [I for I in range (+) if (I//1 * *

Python File processing Exercises

1, Analog CP command Copy file (image, video) to other pathsWithopen (' a.txt ', ' RB ') asf,open (' B.txt ', ' WB ') aswrite: #选择rb模式, support all copies, the corresponding write mode is WB, directly processing is the bytes type for lineinf: #遍历源文件的每一行 write.write (line) #写入新文件write中 However, this does not support the user to pass parameters, so the final code is as follows:Import Sysif len (SYS.ARGV) 2, Python simulation tail command, displ

Python Learning-Exercises (8)

"" "Title: Output 9*9 multiplication table. "" "Def Answer1 ():" " in the most common double loop to output : return:" "" print ("Output One:") for I in range (1): For j in range (1, i + 1): print ("%d x%d =%2s"% (i, J, I * j), end= " ") print () answer1 () def answer2 (): The "" " while loop, with another formatting note for print percent (%) formatted output, sets the output format for the flag with%, and the fomate format is formatted with a colo

Brother Lian Learning python----form production exercises

Form ExerciseRegistration Information Form  Brother Lian Learning python----form production exercises

Python Data type Exercises

":"Mouse"," Price": 10}, {"name":"Yacht"," Price": 20}, {"name":"Beauty"," Price": 998},]Print("enter 0 to buy a computer, enter 1 to buy a mouse, enter 2 to buy a yacht, enter 3 to buy a beauty, enter another value, settle the cart") Li=[]total= Input ("Please enter the total amount:") whileTrue:num= Input ("Enter the serial number you want to purchase:") ifint (num) = =0:li.append (goods[0][' Price']) elifint (num) = = 1: Li.append (goods[1][' Price']) elifint (num) = = 2: Li.ap

Small exercises for lists and loops used in Python

#author devilfproduct_list= [ ('iphone',5800), ('Mac Pro',9800), ('Bike', -), ('Watch',10000), ('Coffee',123)]shop_list=[]salary= Input ('pls enter your salary:')ifsalary.isdigit (): #判断是否为整形, or exit salary=int(Salary) whileTrue: forIndex,infoinchEnumerate (product_list): #打印列表 # Print (Product_list.index (info), info) print (in Dex,info) User_choice= Input ('pls enter what buy\n>>>:') #输入要购买的商品 numberifuser_choice.isdigit (): #再判断下输入的是否是数字, otherwise quit User_choice=int(User_ch

Python Exercises (iii)

1. Sort a list of numbers from small to large, then write to the file, then read the contents of the file from the file,And then reversed, in the next line appended to the fileList = [67, 234, 35, 14, 18, 6, 9, 5]List.sort ()With open (' 20171030 ', ' W ') as F:F.write (str (list) + ' \ n ')With open (' 20171030 ', ' R ') as F:A=f.read ()List.reverse ()With open (' 20171030 ', ' a ') as F:F.write (str (list))2. Write the string, list, tuple, dict to the file, respectivelystring = ' Awen 'list=[1

Python Exercises (i)

1. Achieve 1-100 of all anddef qiuhe (x, y):return x + yhe = 0For I in Xrange (1, 101):He =qiuhe (he,i)Print (He)2. Achieve 1-500 of all odd anddef is_odd (x): return x% 2 = = 1def qiuhe (x, y): return x + yhe = 0For I in Filter (Is_odd,xrange (1,501)): Print (i) he = Qiuhe (He, I)Print (He)3. Ask for 1+ 2! + 3! + 4! + ... 20! and thedef qiuhe (x, y): return x + ydef Jiecheng (n): if (n Return 1 Else Return Jiecheng (n-1) *nhe = 0For I in Xrange (1, 21): He

Python download Wunda deep learning programming exercises

After registering deep learning on Cousera, you can download the after-class exercise.1. After entering the programming environment, click File-open in the upper left corner to enter the file management mode2. Click on the Red Circle folder to enter the root directory3. In the top right corner of the root directory, new one IPYNB4. Open the new IPYNB, enter and do the following, you can compress the files in the root directory into a zip format, download the zip file to get all the programming c

Python Basics Exercises

Python is a dynamic type language, and the language characteristic of a type language determines how complicated he is. #简单的输出打印 #coding=utf-8import time; # This was required to include time Module.word = ' word ' sentence = "This is a sentence." Paragraph = "" "This is a paragraph. It ismade up of multiple lines and sentences. "" " Print paragrapha,b,c=1,2, "aaa" #List类似数组list = [' ABCD ', 786, 2.23, ' John ', 70.2]if word== ' word ': print paragrap

Python Mini-Exercises

: nBsp;l2=list () l2+=l1 l2.remove (B) forCinl2: l3 =list () l3+=l2 l3.remove (C) NBSP;NBSP;NBSP;NBSP;NBSP;NBSP;NBSP;NBSP;NBSP;NBSP;NBSP;NBSP;NBSP;FORNBSP;DNBSP;INNBSP;L3: l4=list () l4+=l3 l4.remove (D) forEinl4: l5=list () l5+=l4 l5.remove (E) forFinl5: l6=list () l6+=l5 l6.remove (F) forginl6 : l7 =list () l7+=l6 l7.remove (G) forHinl7: l8=list () l8+=l7 l8.remove (H) forIinl8: ifa+b+c==d+e+f==g+h+i==a+d+g ==B+E+H==C+F+I==A+E+I==C+E+G==15: print (" __________

999-python-Procedure Exercises

assigned to two variables respectively . Wu          ifuser = = Username andPWD = =Password: -            Print("Welcome to%s login System. "%(Username.title ()) AboutFlag =True $            Break #Jump out of the current for loop -      -Whiltelists.close ()#Close File - A      ifFlag =True: +        Break #Jump out while loop the      Else: -        ifRetry #the message is not printed after the third attempt error $          Print("user name or password input error, please re-e

Python third day file operation exercises

"type= "Org.apache.catalina.UserDatabase"Description= "User database that can be updated and saved"Factory= "Org.apache.catalina.users.MemoryUserDatabaseFactory"Pathname= "Conf/tomcat-users.xml" /> globalnamingresources> Servicename= "Catalina"> ConnectorPort= "8099"Protocol= "http/1.1"ConnectionTimeout= "20000"Redirectport= "8443" /> ConnectorPort= "8089"Protocol= "ajp/1.3"Redirectport= "8443" /> Enginename= "Catalina"Defaulthost= "localhost"> RealmClassName= "Org.apache.catal

Python Exercises _ Easy Shopping cart

), ("Starbark", 60), ("Bike", 1000)]shopping_car= [] whiletrue:balance= Input ("Input your balance:") ifBalance.isdigit ():#Check if it's plastic.balance = Int (balance)#type conversion Shaping Break Else: ifBalance = ='Q': Sys.exit (0)Else: Print("----->invalied Input!!!") whileTrue: forIndex, CLinchEnumerate (commodity):#for list, the function converts it to an index sequence Print("\ n", index, CL) UC= Input ("Input your choice:")#Input Selection

Python Basics Exercises

("Student's score is 0-100")elif yinlu>90: #判断条件print ("Student's score: A")elif yinlu>80:print ("Student's score: B")elif yinlu>70:print ("Student's score: C")elif yinlu>60:print ("Student's score: D")Else:print ("unqualified, can not graduate in the back to learn it!!!")#比较三个数大小#先定义三个数NUM1 = input ("NUM1:")num2 = input ("num2:")num3 = input ("num3:")if num1>num2:max_num = num1 #把num1的值赋给max_num is holding to judge Num3 if max_num>num3:print ("Max is:", max_num)Else:print ("Sparring is:", num3

Python file Operation exercises

=falsedel_info1= Input ("Please enter the employee name to delete:"). Strip (). Upper () withopen ("Info.txt", ' R ', encoding= ' utf-8 ') asf1,open (' Info_new ', ' W ', encoding= ' utf-8 ') asf2:forlineinf1: ifline.split () [0]NBSP;==NBSP;DEL_INFO1: flag=true continue else: f2.write (line) ifos.path.exists (' Info_bak.txt '): Os.remove ("info _bak.txt ") #如果存在则删除 os.rename (" Info.txt "," Info_bak.txt ") Os.rename ("Info_new", "Info.txt") ifflag: print ("Delete succeeded!! ") else:print (" E

Python tuples, lists, dictionary exercises

#coding = Utf-8goods_data = (["Iphone7", 8000],["Mac Pro", 12000],["bike", +]) buyed_goods =[]def display_menu (): mes = "' ****** shopping mall system ****** 1.%s%d 2.%s%d 3.%s%d 4. Exit System ************************ "% (Goods_data[0][0],goods_data[0][1],goods_data[1][0],goods_data[1][1],goods_data[2][0],goods_data[2][1]) Print (MES) def showbought (buyed_goods): length = Len (buyed_goods) mes = '---shopping list---' Print (MES) for I in (buyed_goods): Print (i) def toselect (): Displa

Python Exercises (i)

description:> Input data has multiple groups, one row for each group, including a sentence (sentence length less than 1000 characters)-Output Description:> For each test example, it is required to output sentences that are formed after the word reversal in the sentence-Example 1:```-InputHello Xiao mi-OutputMi Xiao Hello4. # (2017-Good future-written test programming questions)--list practice-Title Description:Enter two strings, removing all the characters from the second string from the first

Python Learning-Exercises (7)

output four: ") a = [[1, 2], [3, 4]] B = a[:] Validate (A, B) answer4 () def ANSWER5 (): "" "Deep copy Copy.deepcopy:return:" "" Print ("\ n output five:") a = [[1, 2], [3, 4]] B = Copy.dee Pcopy (a) validate (a, B) Answer5 () def ANSWER6 (): "" "Shallow copy copy.copy, with Answer3:return:" "" Print ("\ n output six:") A = [[1, 2], [3, 4]] B = copy.copy (a) validate (a, B) Answer6 () def answer7 (): "" "Use list generation using a list of for processing, as if the generator : Return: ""

6 common python errors and solutions for beginners and 6 python reports for beginners

6 common python errors and solutions for beginners and 6 python reports for beginners This article lists some common errors for new users to write code. Some errors are careless. However, for new users, it takes a long time to solve them. So I will summarize some of the problems I encountered here. I hope to help my new friends. 1. The NameError variable name is

Total Pages: 15 1 .... 11 12 13 14 15 Go to: Go

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.