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

Python list Exercises

Python in Shopping cart practiceRequirements: You can enter a salary, select a commodity, and as long as the user has enough money to buy the goods, until the balance is insufficient, after the purchase is completed format the printing user's balance and merchandise.#_ *_coding:utf-8_*_importsysshopping_car=[]product_list_title= ' Productlist ' welcome= ' welcometotheshopping ' product_list=[ (' iphone ', 3888), (' ThinkPad ', 4888), (' Coffee ', , (

Python one-day training 103 ---- Django template exercises, pythondjango

Python one-day training 103 ---- Django template exercises, pythondjango Requirements Request. META is a Python dictionary that contains all the Header information of this HTTP request, such as the user IP address and user Agent. You can obtain this dictionary through request. META. items. You must output the META information to the webpage. Output result Sour

Several exercises in Python

) print (" A and B "file contents have been ordered to merge!) ") F.close ()3) count the number of occurrences of a string's substring. For example, aaa=www.163.net, search net, display 1 times. AAA=STR (Input ("Enter a string:")) Bbb=str (Input ("Enter the field to query:")) Num=aaa.count (BBB) num=str (num) print ("substring occurrences are" +num)4) read the integer value of 7 numbers (1-50), each reading a value, the program prints out the number of *. For example, enter 4, return to * * *, e

Python core Programming Chapter 11 function exercises

)Print Len (Eachline.split ())Print map (func,eachline)str1 = ' 12345 'str2 = ' Efghi 'Print map (NONE,STR1)def chuli (line):return Line.strip ('/n ')Filename= ' 2.txt 'F=open (filename, ' R ')Lines=f.readlines ()F.close ()Choosen=0While not choosen:File_choose=raw_input ("Which file would you save? Choose:(N) EW file(O) LD file‘‘‘)Choose=file_choose.strip () [0].lower ()If choose not in ' no ':print ' Choose Invalid 'Elif choose== ' n ':File=raw_input (' Enter your new file name: ')Choosen=1Els

Python file Exercises

se_list:Print SEPrint Self.cfg.items (SE)Print "================="def delete_item (Self,section,key):Self.cfg.remove_option (Setion,key)def delete_section (self, section):Self.cfg.remove_section (section)def add_section (self,section):Self.cfg.add_section (section)def set_item (Self,section,key,value):Self.cfg.set (Section,key,value)def save (self):fp = Oopen (' Test.txt ', ' W ')Self.cfg.write (FP)Dp.close ()if __name__ = = ' __main__ ':info = student_info (' test.txt ')Info.cfg_load ()Info.cf

Python Regular expression Re/re learning notes and simple exercises

)/(16-3*2)) '"# new_content = Re.split (' \* ', content)# Print (new_content)# # [' ' 1-2 ', ' ((60-30+1 ', ' (9-2 ', ' 5/3+7/3 ', ' 99/4 ', ' 2998+10 ', ' 568/14 ') ')-(-4 ', ' 3 ')/(16-3 ', ' 2 ') ' "]# New_content2 = Re.split (' \* ', content,1)# Print (New_content2)# # ["' 1-2", "((60-30+1* (9-2*5/3+7/3*99/4*2998+10*568/14)-( -4*3)/(16-3*2)) ']## New_content3 = Re.split (' \* ', content,3)# Print (NEW_CONTENT3)# # [' ' 1-2 ', ' ((60-30+1 ', ' (9-2 ', ' 5/3+7/3*99/4*2998+10*568/14 ')-( -4*3)/

Python Exercises-Element classification

The following values are set v1 = [11,22,33,44,55,66,77,88,99,90],Save all values greater than 66 to the first key in the dictionary and save the value less than 66 to the value of the second key.That is: {' K1 ': All values greater than 66, ' K2 ': All values less than 66}V2 = {' K1 ': [], ' K2 ': []}#!/usr/bin/python#-*-Coding:utf-8-*-V1 = [11,22,33,44,55,66,77,88,99,90]Dict = {} #声明集合For items in V1: #遍历vi列表 If items > : #判断是否大于66 If ' K

Python exercises 4-the day of the year is judged

Title: Enter a certain day of the year, judging the day is the first of the year?Program Analysis: take March 5 as an example, should first add up the first two months, and then add 5 days the first day of the year, special cases, leap years and enter the month greater than 2 o'clock need to consider adding a day:Program Source code:#!/usr/bin/python#-*-Coding:utf-8-*-Year=int (Input ("Year: \ n"))Month=int (Input ("Month: \ n"))Day=int (Input ("Day:

"Two" just learn a few simple exercises of Python

Python Friends Entertainment club: 6131763981. Use while loop input 1 2 3 4 5 6 8 9 102. For all numbers of 1-1003. All odd numbers in output 1-1004. All even numbers in output 1-1005, Beg 1-2+3-4+5 ... 99 of all numbers of the and6. User Login (three chance retry)First question:A = 0 while a :+=1 if a = = 7: continue Print (a)The second question:The first method:A == 1 while B := a + b + = 1print(a)The second method:A = 0

Getting started with Python-simple basic questions exercises

)Count = Count + 1""""""13. Output all the even numbers within 1-100.Count = 1While Count If count% 2 = = 0:Print (count)Count = Count + 1""""""14. Ask for the 1-2+3-4+5...99 of all the numbers.Number = 1connt = 0While number If number%2 = = 0:Connt = Connt-numberelif number%2 = = 1:Connt = connt + numberNumber + = 1Print (CONNT)"""#以下是作业题"""Job: User Login1. Three Retry opportunities2. The number of errors left on the line each time the error is enteredname = ' Lisongyang 'Password = ' lsy123 '

python-Dictionary Exercises

][2].get (' K1 ') [1] = ' # ' # (2)print (LIS)#10.3 Change the list from ' 1 ' to Digital 101 (two ways)#lis [0][1][2][' k1 '] = [' TT ', ' 3 ', 101] (1)lis[0][1][2].get (' K1 ') [2] = ' 101 ' # (2)print (LIS)#11, there is now a list of li = [All-in-one, ' a ', ' B ', ' 4 ', ' C '], there is a dictionary (this dictionary is#动态生成的, do not know how many key-value pairs inside, so use dic = {} to emulate this dictionary);#现在需要完成这样的操作: If the dictionary does not have the ' K1 ' key, then create this

Python programming quickly get started with tedious work-6.6 exercises

', ' Moose ', ' goose '] Your printtable () function will print out: Apples Alice dogs oranges Bob catscherries Carol moose Banana David Goose"""Tabledata= [['Apples','oranges','Cherries','Banana'], ['Alice','Bob','Carol','David'], ['Dogs','Cats','Moose','Goose']]defprinttable (tabledata): Len_list=[0,0,0] forIndex, iteminchEnumerate (tabledata): forStrinchItem:ifLen (str) >Len_list[index]: Len_list[index]=len (str)#print (len_list) forSeqinchRange (len (tabledata)

Python Series exercises (1)

Beautiful Soup is a python library that extracts data from HTML or XML files. It is able to use your favorite converter to achieve idiomatic document navigation, find, modify the way the document. Beautiful Soup will save you hours or even days of working hours.Beautiful Soup3 documentation, Beautiful Soup 3 has now stopped development, now recommended in the current project using Beautiful Soup 4, transplanted to BS4, now Python2 version will gradual

The first chapter of Python exercises

(' Login successful ') Break Else:Print(' Login failed ') Count+= 1 ifUsername_is_exit:ifCount== 3:Print(' Locked ... ' .)# Write lock information to fileF_new= Open(' Lock.txt ',' r+ ') New_line=F_new.read () forIinchLock_list:ifUsernameinchI:new_str=I.replace (' 0 ',' Locked ') New_line=New_line.replace (i, NEW_STR)Else: New_line=New_line f_new.write (New_line) f_new.close () F.close () Os.remove (' Lock.txt ') F_new2= Open(' Lock.txt ',' W ') F_new2.write (New_line) f_new2.close () Brea

Python core programming-exercises-chapter II

Ps:pdf Online Address: http://bcmi.sjtu.edu.cn/~zhaohai/ptm2012/data/Python-kernel.programming.v2.pdf2-1 variables, print, and string formatting operators. Start the interactive interpreter, assign values to variables (strings, values, and so on) and display their values by entering variable names. Then do the same thing with the print statement. What is the difference between the two? Also try to use the string format operator%, do a few more times,

Python exercises 046:project Euler 019:1st per month is Sunday

Topic from Project Euler 19th: https://projecteuler.net/problem=19"How many Sundays fell on the first of the Monthduring the Twentieth Century (1 Jan 1901 to Dec 2000)? answer:171 ' from datetime import *firstday = Date (1901,1,1) Lastday = Date (2000,12,31) delta1 = Timedelta (Days=1) Firstsunday = Date (1900,1,1) while firstsunday = = Date (1900,1,1): if firstday.isoweekday () = = 7: firstsunday = FirstDay #找出第1个星期天 break Else: firstday + = Delta1delta7 = Timedelta

Python exercises 048:project The sum of all affinity numbers within Euler 021:10,000

factors are: 1, 2, 3, 4, 6 Affinity numbers (amicable number): First of all the sum of the true factors of the number of words N, and then the sum of all true factors of the numbers a and B. If a! = b and N = = B, then a, B, n are both pro-and-numeric The concept is clear, and then it's done. The sum of all affinity numbers within 10000 is the first to find out all affinity numbers (aggregated to list lst). To find affinity numbers, you first have to define the function d (n), which is

Python core programming version 2, 308th page, Chapter 2 exercises

The answer in this blog is not from official resources, but from my own exercises. If you have any questions or errors, please discuss them. 11-1.Parameters. Compare the following three functions:Def countToFour1 ():For eachNum in range (5 ):Print eachNum Def countToFour2 (n ):For eachNum in range (n, 5 ):Print eachNum Def countToFour3 (n = 1 ):For eachNum in range (n, 5 ):Print eachNum What do you think will happen if the following input is given unt

Python core Programming The answer to the second edition of the exercises

()Choice=input ("Please choice One:")If choice==1:Sum=sum ()Print "sum is%d"%sumElif choice==2:Ave=ave ()Print "average is%f"%aveElif choice== ' x ':BreakElsePrint "Wrong choice,please choose again!"2-15#让用户输入3个数值并将分别将他们保存到3个不同的变量中, do not use a list or sorting algorithm#从小到大While True:Num1=int (raw_input ("Please input NUM1:"))Num2=int (raw_input ("Please input num2:"))Num3=int (raw_input ("Please input num3:"))If num1>num2:Tmp=num1Num1=num2Num2=tmpIf num2>num3:Tmp=num2Num2=num3Num3=tmpIf num1

Python exercises 034:project Euler 006: The difference between peace square and squared sum

Topic from Project Euler 6th: https://projecteuler.net/problem=6# Project Euler:problem 6:sum Square difference# The Sum of the squares of the first ten natural numbers is,# 1**2 + 2** 2 + ... + 10**2 = 385# The square of the sum of the first ten natural numbers is,# (1 + 2 + ... +) **2 = 552 = 3025# Hen Ce the difference between the sum of the squares of the first ten natural numbers# and the square of the sum is 3025? 385 = 2640.# Find The difference between the sum of the squares# of the firs

Total Pages: 15 1 .... 10 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.