python tutorial with exercises

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

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: ""

The Python function and data structure exercises one

]#your solution here forNameinchnames:ifLen (name) >Len (longest): Longest=name?Print(Longest)#Output ResultsJoshua ZhaoA singer of a singing contest scores, we design a program to help remove a minimum and a maximum score, and then calculate an average scoreFor example, the score is: [8,9,5,10,9.5,8,7,9,9.5] minus the lowest score [8,9,5,10,9.5,8,9,9.5]#idea: Traverse to find the minimum and maximum values respectively, then remove () and then divide the sum of the array by Len (values) .values

Brush question--Python calculator exercises

.]*] \) ', S_MATCH_STR). Group (1) s = S.replace (S_match_str, S_match_str_match) print (s) Else:print ("Call processing%s"%s_match_str) S_match_str_str=re.search (' \ ([+\-*/0-9.] *) \) ', s). Group (1)Ret=handler_expression (s_match_str_str) s = s.replace (S_match_str, str (ret)) print (s) Else:flag=false return s# no_braces_result=hadler_braces (' ( -1+ (2-5* ( -1)) * (2-5)) # Result=handler_expressi On (no_braces_result) # print (result) if __name__ = = ' __main__ ': While tru

Python crawler Exercises (ii) crawl the public interest src vendor domain name URL (November 22, 2017)

. Only the top three pages of the crawl, 30 vendors per page are shown here.3. Using the regular Fetch URL4. Crawl results saved in the Script sibling directory ' butian_company_url.txt ' file, if not enough 90 URLs, may be some vendors did not fill out (ie empty)Import Requests,re,json,timehead = {' user-agent ': ' mozilla/5.0 (Windows NT 6.3; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/43.0.2357.130 safari/537.36 '}cook = {"Cookie": "Write here your cookie for the day you log in"} ur

Python lots of the most basic exercises

This article is based on the 0 basics of Python, the most basic exercise, not including functions and object-oriented.Are I collected on the Internet some of the exercise materials, not much nonsense on the topic1. Use three lines of print to complete the display of the following information: ================================== = 欢迎进入到身份认证系统V1.0 = 1. 登录 = 2. 退出 = 3. 认证 = 4. 修改密码 ==================================代码:Print ("=

"Python Exercises" program 5

#题目: Enter three integers x, y, Z, please put these three numbers from small to large output.#a = input (' Please enter an integer: \ n ')##B = input (' Please enter an integer: \ n ')##c = input (' Please enter an integer: \ n ')##L = [A,b,c]##L.sort ()##For i in L:#print (i)Method 2:l= [] forIinchRange (3): I= Input ('Please enter a number: \ n') l.append (i) l.sort ()Print(l)Use a list to express what you can do at once."Python

python--Exercises--list sort Sort,sorted,reverse=true,reverse

L=[]For I in range (3):X=int (Input ("Shuru:"))L.append (x)Print (L)Print (sorted (l))Print (sorted (l,reverse=true)L.sort ()Print (L)L.reverse ()Print (L) #!/usr/bin/python3L=[]For I in range (5):X=int (Input ("Shuru:"))L.append (x)Print ("Chushi Xulie", L)Print ("Linshi Xulie Print ("Linshi daoxu >", Sorted (l,reverse=true))L.sort ()Print ("You Xiaodao da", L)L.sort (Reverse=true)Print ("Youda Daoxiao", L)L.reverse ()Print ("Dao Xu Xian Shi", l)python

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.