1. Hello world!2. Simple Interactive (interactive, file-style) textbook P193, the user input two numbers, calculate and output two numbers of the sum:4, the user input triangle three-side length, and calculate the area of the triangle: (Helen Formula)A=input ("Edge length of triangle a:") b=input ("side length B of the triangle:") C=input ("The edge length of the triangle C:") s=1/2*(float(a) +float(b) +float(c) area= (s* (float(s)-float(a)) *(float(s)-float(b)) *(float(s)-float(c))) **0.5Print
characters): ', end= ') comp = input () Count = 0 i = 0 For I in range (len (temp)): If temp[i] = = Comp[0] and temp[i+1] = = Comp[1]: Count + = 1 i + = 1 Else i + = 1 count = Int (count) Print (' substring total%d occurrences in target string '%count)Findstr ()Little Turtle:def findStr (Desstr, SUBSTR): Count = 0 length = Len (desstr) If SubStr not in Desstr: Print (' string not found in target string! ') Else
First, the output Hello WorldPrint ("Hello Word")Second, summation operationA1 = Input ("A1:") a2 = Input ("A2:") sum = float (A1) +float (A2) print ("The sum of the first number {0} plus the second number {1} is {2}". Format (a1,a2,sum))Three sides of the input triangle to seek the areaImport MATHA1 = Input ("A1:") a2 = Input ("A2:") a3 = Input ("A3:") p = (float (A1) +float (A2) +float (A3))/2d=float (p) area = d* ( D-float (A1)) * (D-float (A2)) * (D-float (A3)) B=float (area) c=math.sqrt (b)
1. VariablesIn other programming languages, when a variable is assigned a value to a name, the value is stored in memory, and the name is called a variable.In Python, it's a bit different, it's more like putting a name on top of a value, so you can say that Python has no variables.34= a + bprint (c)2. Places to note when using variables:You need to assign a value to the its first before using the variable.V
1. What is BIFBif is a built-in function, English is all called build-in-function3. Is there a difference between "FISHC" and "FISHC"?There's a difference, he's two different strings.The difference between 4.= and = == Assign a value in Python, that is, assign a value to the variable. = = represents equal to5 What is the meaning of stitching?Stitching can be easily understood in Python as a concatenation of
! ‘) Return FuninFunout () ()6. Below is an example of a "closure", so what do you print out visually?Def funx (): x = 5 Def funy (): nonlocal x x + = 1 return x Return FunyA = Funx ()Print (A ())Print (A ())Print (A ())678Some fish oil may be more confused, this ... What is the same as a global variable? The local variable x should not be reinitialized every time it is called?!In fact, we have a closer look to understand that when a = Funx (), as long as the A v
1. Note the differences between the two codes3=4print (b)3=4(in Python, variables are simply labeled)2.str = r"c:\\w\e\we\weee""\ \"print (" str")3. (Version 2.7)month =int(Raw_input ("Please enter the number of months:")) Day=int(Raw_input ("Please enter the number of days:")) Hour=int(Raw_input ("Please enter the number of hours:")) minute=int(Raw_input ("Please enter the number of minutes:")) Second=int(Raw_input ("Please enter the number of seco
1. Use of flowchart.In the early stages of writing a program, you can try to write a flowchart, understand the logical sequence, realize the function, judge the condition, etc.2. Built-in functionsBIF = = Built-in-function, querying the built-in functions in Python, you can use code:Dir (__builtins__)3. For a function that is not clear, you can learn about functions by using Help (function).4. The game source code in the classroom:Print(".............
The GUI class library (Easygui) for Python's third-party simple graphical interface is downloaded and installedDownload : Easygui official website http://easygui.sourceforge.net Download Easygui compression pack Install : Copy the extracted easygui.py to Python under the Lib\site-packages folder under the installation directory Test : Bring up Python's idle, enter>>>import Easygui>>>easygui.msgbox ("This is test!")If a dialog box appears, i
.del Love[3] The position of the element in parenthesesDel love parentheses followed by list name, list will be deleted8.love.pop (position ordinal, can be omitted, default delete last) The return value is the deleted element9. List copy love[1 (if omitted, viewable as 0): 5 (does not include this position; if omitted, always included to the last element)]10.dir ()11..count () detects the number of occurrences of elements in parentheses in the list12..index (element, range) detects the position
tables, translation tables are converted through the Maketrans method. Deletechars--a list of characters to filter in the string.Translate is a one by one mapping of characters. Each character will be replaced with the corresponding character as soon as it appears.Replace is a string substitution, and the string is replaced as a whole. The two string parameter lengths of replace can be different.Thezfill(width) method returns a string of the specified length, the original string is right-ali
Today I learned mainly about the main points of the cycle,1.use ofelif whiletrue:temp= Input ("Please enter a score:") score=int(temp)if ->= score >= -: Print ("A") Elif ->= score >= the: Print ("B") Elif the>= score >= -: Print ("C") Elif ->Score:print ("D") Else: Print ("Input Error")2. Use ofassert :When the following condition is true, the error occurs when the condition is false.3. Ternary conversion4,5if x > y = yelse: = xEquivalent to:if Else yThat is, the x if condition else yN
0. Please describe what is a list in a sentence? Describe what a tuple is in a sentence?List: A large warehouse where you can add and remove anything at any time.Tuples: Closed lists, once defined, cannot be changed (cannot be added, deleted, or modified).1. Under what circumstances do you need to use tuples instead of lists?When we want content not to be easily rewritten, we use tuples (putting power into a cage).When we need to change data frequently, we use lists.2. Connect the built-in metho
The practice of Python learningA chess board drawn with turtleImport Turtleturtle.speed a = 30# painting background turtle.up () Turtle.goto ( -10, -10) Turtle.down () Turtle.fillcolor ("Khaki") Turtle.begin_fill () TURTLE.FD (A * 8 +) Turtle.left (+) TURTLE.FD (A * 8 +) Turtle.left (A * 8 +) turtle.fd. Left (TURTLE.FD) (A * 8 +) Turtle.left (All) Turtle.end_fill () #画黑格for I in range (8): If I% 2 = = 0: #偶数行 turtle.u P () Turtle.goto (0, I
For statement syntax:For-Target in expression:Loop bodyExample 1:Favourite = ' IDMask ' for I in favourite: print (I, end= ") The above output isI D m a s KExample 2:member = [' Little Turtle ' ,' hett ' astray ',' Little Pudding '] for in member: Print (each, Len)The result is:Small Turtle 3 Hett 2 lost 2 small pudding 3
range () function This function matches the BIF built-in function w
],list_y[1]) defMove (self):#Random Move positionnew_x = Self.x+r.choice ([1,-1]) new_y= Self.y+r.choice ([1,-1]) #Check whether the zone is exceeded after the move ifnew_xlist_x[0]: self.x= list_x[0]-(new_x-list_x[0])elifNew_x>list_x[1]: self.x= list_x[1]-(new_x-list_x[1]) Else: self.x=new_x#Check if the y-axis is exceeded ifnew_ylist_y[0]: self.y= list_y[0]-(new_y-list_y[0])elifNew_y>list_y[1]: Self.y= list_y[1]-(new_y-list_y[1]) Else: Self.y=new_y#returns
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.