Discover python textbook with exercises, include the articles, news, trends, analysis and practical advice about python textbook with exercises on alibabacloud.com
=str (Li[i]) v = " _ " .join (LI) print (v) li=["aa","bb", 123] for in (0,len (LI)-1): li[i]=str (li[i]) v="_". Join (LI) Print (v)6. A list is known to use enumrate output elements and sequence numbers starting from 100li=["aa","bb", 123] for in Enumerate (li,100): print(i,q)Enumerate(sequence, [start=0]) Start-the subscript start position.7. Make a 301-length list and implement paging function page 10 dataLi=[] forIteminchRange (1,302): Temp={id:"
For the first time on the weekend, try writing code exercises"Stupid way to learn Python"--author Zed A.shaw, translation Wang Dingweiex1.pyPrint (' Hello World ')---------------------------------------ex2.py#A comment, this was so you can read the your program later.#Anything after the # are ignored by Python.Print (' I could has code like this ') # and the comment are ignored.#you can also use a comment t
Chapter three function exercises and their answers 1. Why is it good to add a function to a program?A: The function reduces the duplicated code. This makes the program shorter, easier to read, and easier to modify.2. When does the code in the function execute: When the function is defined, or when the function is invoked?A: The code in the function executes when the function is invoked, not when the function is defined.3. What statement creates a func
all the odd bit indexes of an incoming list or tuple object and returns it as a new list to the caller Def func1 (P,Q): result = [] for i1 in range (Len (P)): if i1% 2 = = 1: result.append (P[i1]) for i2 in range (len (q)):
if i2% 2 = = 1: result.append (P[i2]) print (result) R = func1 ([11,22,33], (11,22,33)) Result: [22,22]Write functions, check the length of each value passed in the dictionary, and if it is greater than 2, retain only the first tw
#encoding =utf-8Import Random#dict. Update (DICT2) a adds the key-value pairs of the dictionary dict2 to the dictionary dict# 7–1. Dictionary method. Which dictionary method can be used to merge two dictionaries together?Dict1 = {1: ' W ', 2: ' Y '}Dict2 = {3: ' t '}Dict1.update (DICT2)Print Dict1# 7–2. The key for the dictionary. We know that the value of the dictionary can be any Python object, what about the key of the dictionary? Please try# with
classes. Provides an interface to a time module that allows the user to format their own given times, such as:# "Mm/dd/yy," "Mm/dd/yyyy," "Dd/mm/yy," "Dd/mm/yyyy," "Mon DD, YYYY," or standard# Unix Date format: "Day Mon DD, HH:MM:SS YYYY" to see the date. Your class should maintain a date value, and# Create an instance with the given time. If no time value is given, the current system time is taken by default when the program executes. Also package# includes some other methods:# Update () modif
How many vowel letters are there?There is a string "I learn Python from Maya", we want to find out the vowel (aeiou) in it (actually find out these lowercase letters), and count the number of its vowel characters. At this point we can combine the conditional statement and the Loop statement to process the string.#sentence is a string that you need to count the number of vowels in this stringSentence ="I Learn Pyth
absolute value of the coefficients is required, and the increment or decrement function has been determined by the coefficient symbol.Since the coefficients have been determined, the following need to solve is the intercept problem (according to the geometrical meaning I understand the term), if according to the concept of geometrical intercept is very well understood, if x=0, y>=0, then the symbol of intercept is "+", and vice versa is "-", since the symbol is determined, Then the value can on
fromFunctoolsImportReducedefStr2Int (s):defChar2int (c):return{"0": 0,"1": 1,"2": 2,"3": 3,"4": 4, "5": 5,"6": 6,"7": 7,"8": 8,"9": 9}[c]returnReduceLambdaX, Y:x * 10 +y, Map (Char2int, s))Print(Str2Int ("98986553"))Title, change the string to int1.# using the map () function, the user entered an irregular English name, the first letter capitalized, the other lowercase canonical name.# input: [' Adam ', ' Lisa ', ' Bart '], output: [' Adam ', ' Lisa ', ' Bart ']:m = map (Lambda s:
numbers, ranging from large to small. (b) is the same as a, but it is arranged in a dictionary order from large to small. " # (a) Defget_num (): globalnum_listnum_list= []num= ' whilenum!= '! ': num=raw_input (' Enter some numbers to '! "End"). Strip () ifnum!= '! ': try: num=float (num) except: print ' input is wrong, please re-enter ' get_num () else: num_list.append (num) else: breakreturnnum_listdefsort_descending (): get_num () printsorted (num_list,reverse=true) print '---------------
Deepen your understanding of Python character encoding with the following exercises#\x00-\xff 256 character (S )>>>A = range (256)>>>b = Bytes (a)#No parameter encoding>>>bB ' \x00\x01\x02 ... \xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff '>>>B.decode ('Utf-8')#Error Traceback (most recent): File "", line 1, in >>>B.decode ('Unicode-escape')#Normal' \x00\x01\x02 ... \xf6÷\xf8ùú\xfbü\xfd\xfe\xff '# out of the que
1 Exercises
Describe the differences between compiled and interpreted languages, and list which languages you know are compiled and which are interpreted
Compiled language: Fast execution, Debug trouble Interpreting language: Slow execution, easy commissioning
What are the two ways to execute a Python script
Enter the interpreter's interactive mode, but cannot permanently save th
false.Finally, find and or to determine whether it is true or false.After completing these steps, you can solve the problem.Let's take a look at the above 20th questions:3! = 4 and not ("testing "! = "Test" or "Python" = "Python ")Now we install the above steps and then write the results of each step:Search for = and! = Symbol, which becomes True and not (True or True) after judgment)True and false in brac
the parameter is Ganso:In [41]: random.choice((1,3,7,4))Out[41]: 1In [42]: random.choice((1,3,7,4))Out[42]: 7
Random.shuffle: If you want to shuffle an element in a sequence (excluding Ganso and strings), you can use this function method
In [49]: list = [1,2,3,4]In [50]: random.shuffle(list)In [51]: listOut[51]: [4, 2, 1, 3]
Random.sample (A, B): A fragment of the specified length B is intercepted randomly and independently from sequence a.
In [58]: b = (9,9,9,1,2)In
Count : if count = = 8: pass Else : Print(count) = Count +12. Ask for 1-100 and.n = 1= 0 while n : = s + n Print (s) = n + 13, ask 1-100 all the oddn = 1 while n : = n%2 if temp = = 0: pass else: print(n) = n + 14. Ask for 1-100 all evenn = 1 while n : = n%2 if temp = = 0: Print (n) Else : Pass = n + 15, 1-2+3-4+5-6+7...99 all the numbers andn = 1= 0 while n := n 2 if temp = = 0: = s-
interactive interpreter? Try it and write the results.The interactive interpreter can calculate the result directlye) How can you improve the script so that it works as you think?6. Variable Assignment:1). assignment statement x, y, z = 1, 2, 3 What values will be assigned in X, Y, z respectively?2). What values do z, x, y = y, z, x, x, Y, z contain?7. The identifier. Which of the following are the valid Python identifiers? If not, please explain why
Python programming Quick Start-making tedious work automated-chapter two exercises and their answers 1, what are the two values of the Boolean data type? How do I spell it?A: True and false, use uppercase T and uppercase F, and the other letters are lowercase.What are the 2, 3 Boolean operators?Answer: And, or, and not.3. Write the truth table for each boolean operator (i.e., each possible combination of op
Exercises Vamei Source: http://www.cnblogs.com/vameihttp://www.cnblogs.com/vamei/archive/2012/07/19/2600135.html#undefined"Implement" #!/usr/bin/python#-*-coding:utf-8-*-#-------Calculate date difference ' Import datetimefrom datetime import dated1= Date (2008,1,1) d2=date (2008,10,1) t=abs (d2-d1) n=t.days+1print n#----Determine if 2008 is a leap year, Def leapyear (year): #判断year是否为闰年, ture for leap year
that the fetch starts at index 0 until index 3, but does not include index 3. That is, index 0,1,2, which is exactly 3 elements. #If the first index is 0, you can also omit:Print(L[:3])#[' Michael ', ' Sarah ', ' Tracy ']#slice backwards.Print(l[-2:])#2 to 0 does not include 0 (of course, it is not possible to include 0, the index of the first element of the countdown is-1, notice that 0 is not written, otherwise it will output [])Print(L[-2:-1])#2 to-1 does not include-1, that is, the second-l
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.