Hướng dẫn terminal based program in python - chương trình dựa trên thiết bị đầu cuối trong python

Trình bày về chủ đề: "Chương trình dựa trên thiết bị đầu cuối"-Bảng điểm trình bày:

1 Thiết bị đầu cuối chương trình dựa trên thiết bị đầu cuối cho phép người dùng Torun đầu ra chương trình làm văn bản trên màn hình hoặc trong đầu vào Windowenter dưới dạng văn bản từ các hệ thống máy tính bàn phím hoàn toàn dựa trên thiết bị đầu cuối, hiện đại đã thêm GUI (Giao diện người dùng đồ họa) lấy từ: Terminal-Based Programs
A terminal allows a user to run a program view output as text on a screen or in a window enter input as text from the keyboard Early computer systems were entirely terminal-based, modern systems have added a GUI (graphical user interface) Retrieved from:

2 Hành vi của các chương trình dựa trên thiết bị đầu cuối inNputSCputationsOutSprompt Người dùng để biết một số thông tin sử dụng thông tin để thực hiện một số tính toán ra mắt kết quả Behavior of Terminal-Based Programs
Inputs Computations Outputs Prompt the user for some information Use that information to perform some computations Output the results

3 Cấu trúc của các chương trình dựa trên thiết bị đầu cuối inSinputSCputationsOutSdocStringImport statementsInput statementscomputation fatorsoutput fatorsprogrogam Mã trong một tệp có phần mở rộng .py. Structure of Terminal-Based Programs
Inputs Computations Outputs docstring import statements input statements computation statements output statements Program code goes in a file with a .py extension.

4 Nhập báo cáoImport MathPrint (Math.pi) In (Math.sqrt (2)) Nhập khẩu thường xảy ra trước khi bắt đầu chương trình thực thi CodeThey cung cấp các tài nguyên có sẵn từ các mô -đun Python khác chỉ là một tệp của mã Python import Statements import math print(math.pi) print(math.sqrt(2)) Imports usually occur before the beginning of the executable program code They make available resources from other Python modules A module is just a file of Python code

5 Báo cáo nhập từ Nhập Math Nhập PIPRINT (PI) Thay vào đó, người ta có thể nhập các tài nguyên cụ thể từ một mô -đun nhất định và sau đó bỏ qua vòng loại mô -đun từ tham chiếu import Statements from math import pi print(pi) Alternatively, one can import particular resources from a given module and then omit the module qualifier from the reference

6 Báo cáo nhập từ Nhập Math *In (pi) In (sqrt (2)) hoặc, người ta có thể nhập tất cả các tài nguyên cụ thể từ một mô -đun nhất định và sau đó bỏ qua vòng loại mô -đun từ tất cả các tài liệu tham khảo import Statements from math import * print(pi) print(sqrt(2)) Or, one can import all the particular resources from a given module and then omit the module qualifier from all the references

7 Đầu vào của TextInput ('Nhập tên của bạn:') Hàm đầu vào in đối số chuỗi của nó và chờ đợi đầu vào của người dùng. Hàm sau đó trả về chuỗi các ký tự được nhập tại bàn phím. Input of Text input('Enter your name: ') The input function prints its string argument and waits for user input. The function then returns the string of characters entered at the keyboard.

8 Đầu vào của số in (đầu vào ('Nhập tuổi của bạn:')) khi dự kiến ​​một số nguyên, bạn phải chuyển đổi chuỗi đầu vào thành int.float (đầu vào ('nhập mức lương hàng giờ của bạn:')) khi một số thực (với Một điểm thập phân) được mong đợi, bạn phải chuyển đổi chuỗi đầu vào thành một chiếc phao. Input of Numbers int(input('Enter your age: ')) When an integer is expected, you must convert the input string to an int. float(input('Enter your hourly wage: ')) When a real number (with a decimal point) is expected, you must convert the input string to a float.

9 Câu lệnh gán đơn giảnName = Input ('Nhập tên của bạn:') Thu nhập = Float (Input ('Nhập thu nhập của bạn:')) Toán tử đánh giá biểu thức sang phải và đặt biến sang trái của nó vào giá trị kết quả. Sử dụng các biến để giữ lại dữ liệu để sử dụng thêm. Simple Assignment Statements
name = input('Enter your name: ') income = float(input('Enter your income: ')) The = operator evaluates the expression to its right and sets the variable to its left to the resulting value. We use variables to retain data for further use. Note: = does not mean equals in Python!

10 Mẫu cú pháp cho gán đơn giản = Mẫu cú pháp thể hiện quy tắc ngữ pháp bằng ngôn ngữ. Khung góc bao quanh tên của các cụm từ hoặc thuật ngữ được xác định bởi các quy tắc khác.area = math.pi * RADIUS ** 2century = 100Squareroot sqrt (2) Syntax Template for Simple Assignment
= A syntax template expresses a grammar rule in a language. The angle brackets enclose the names of phrases or terms that are defined by other rules. area = math.pi * radius ** 2 century = 100 squarerootof2 = math.sqrt(2)

11 Thêm về các biến Bất kỳ biến nào cũng có thể đặt tên cho bất kỳ điều gì. , hoặc _.variables không thể chứa khoảng trắng.python nhạy cảm với trường hợp. Sử dụng chữ thường cho ngay bây giờ. More on Variables Any variable can name any thing.
firstname = input('Enter your first name: ') Any variable can name any thing. Variables must begin with a letter or the _ character. They can contain any number of letters, digits, or _. Variables cannot contain spaces. Python is case-sensitive. Use lowercase letters for now.

12 TÀI LIỆU THAM KHẢO BIDEX = # x Bắt đầu là 10x = x # x được đặt lại thành 11y = y + x # error! Không thể tìm thấy giá trị của Ykhen Python nhìn thấy một biến trong một biểu thức, nó phải có khả năng tra cứu giá trị của nó. Nếu một biến không có giá trị được thiết lập, chương trình dừng lại với thông báo lỗi. Variable References x = # x begins as 10 x = x # x is reset to 11 y = y + x # Error! Can't find value of y When Python sees a variable in an expression, it must be able to look up its value. If a variable has no established value, the program halts with an error message. Variables are given values by assignment statements

13 Kết thúc của dòng Nhận xét x = 10 # x bắt đầu vì 10x = x # x được đặt lại thành 11y = y + x # error! Không thể tìm thấy giá trị của y # bắt đầu một kết thúc của bình luận dòng - Python bỏ qua văn bản từ # đến cuối dòng End of Line Comments x = 10 # x begins as 10
x = x # x is reset to 11 y = y + x # Error! Can't find value of y # begins an end of line comment - Python ignores text from # to the end of line

14 Đánh giá biểu thứcPrint (TotalinCome - Khấu trừ * Tỷ lệ) In ((TotalinCome - Khấu trừ) * Tỷ lệ) In (10 + X * Y ** 2) Biểu thức được đánh giá từ trái sang phải, trừ khi người vận hành ưu tiên ghi đè thứ tự này. Sử dụng dấu ngoặc đơn để ghi đè lên tiêu chuẩn ưu tiên khi cần thiết. Evaluating Expressions
print(totalincome - deduction * rate) print((totalincome - deduction) * rate) print(10 + x * y ** 2) Expressions are evaluated left to right, unless operator precedence overrides this order. Use parentheses to override standard precedence when necessary.

15 Mode Mode ArithMeticPrint (5 * 100) in (5 * 100.0) Giá trị của một biểu thức phụ thuộc vào các loại toán hạng của nó. / y luôn tạo ra một chiếc phao. Mixed-Mode Arithmetic
print(5 * 100) print(5 * 100.0) The value of an expression depends on the types of its operands. In general, two ints produce an int, whereas at least one float produces a float. Exception: x / y always produces a float.

16 Chức năng chuyển đổi loại (3.72) # returns'3.72'Float ('3,72') # Trả về 3.72Int (3.72) # Trả về 3Float (3) # Trả về Loại dữ liệu 3.0each có chức năng chuyển đổi các giá trị của một số loại khác thành các giá trị của các giá trị của các giá trị của các giá trị của có giá trị của có giá trị của có giá trị của có giá trị của có của các giá trị của có của các giá trị của có của các giá trị của có của các giá trị của có của các giá trị của có của các giá trị của có của các giá trị của có của các giá trị của có của các giá trị của có của các giá trị của có của các giá trị của có của các giá trị của có của các giá trị của có các giá trị của có của các giá trị của có của các giá trị của có của các giá trị của có của các giá trị của có của các giá trị của của của của của các giá trị của có của các giá trị của có của các giá trị có loại đó. in cắt một phao bằng cách loại bỏ phần phân số. Type Conversion Functions
str(3.72) # Returns'3.72' float('3.72') # Returns 3.72 int(3.72) # Returns 3 float(3) # Returns 3.0 Each data type has a function to convert values of some other types to values of that type. int truncates a float by removing the fractional part.

17 Làm tròn và chính xác (3.72) # Trả về 4Round (3,72, 1) # Trả về 3.7Round (3.729, 2) # Trả về đối số thứ hai tùy chọn 3,73. Rounding and Precision
round(3.72) # Returns 4 round(3.72, 1) # Returns 3.7 round(3.729, 2) # Returns 3.73 round’s optional second argument specifies the number of digits of precision in the fractional part

18 Sử dụng functionRound (3.72) # return 4abs (-5) # returns 5Math.sqrt (2) # return () Một hàm có thể có một hoặc nhiều đối số bắt buộc và/hoặc một số đối số tùy chọn phải thuộc các loại thích hợp Using Functions round(3.72) # returns 4 abs(-5) # returns 5 math.sqrt(2) # returns () A function can have one or more required arguments and/or some optional arguments Arguments must be of the appropriate types

19 Biểu đồ biểu thứcSquareOfa = a ** 2SquareOfb = b ** 2sumofsquares = SquareOfa + SquareOfBC = math.sqrt (sumofsquares) in ('Hypotenuse là', c) Composing Expressions
squareofa = a ** 2 squareofb = b ** 2 sumofsquares = squareofa + squareofb c = math.sqrt(sumofsquares) print('The hypotenuse is', c) Use assignment to name the results of computations

20 Biểu đồ biểu thứcSquareOfa = a ** 2SquareOfb = b ** 2sumofsquares = squareofa + squareofbc = math.sqrt (sumofsquares) in ('hypotenuse là', c) 2 + b ** 2) in ('Hypotenuse là', c) hoặc chỉ soạn biểu thức và chuyển nó như một đối số cho hàm Composing Expressions
squareofa = a ** 2 squareofb = b ** 2 sumofsquares = squareofa + squareofb c = math.sqrt(sumofsquares) print('The hypotenuse is', c) Use assignment to name the results of computations c = math.sqrt(a ** 2 + b ** 2) print('The hypotenuse is', c) Or just compose the expression and pass it as an argument to the function

21 Lấy thư mục của một mô -đun >>> nhập toán >>> dir (toán học) ['__ doc__', '__file__', '__name__', 'acos', 'asin', 'atan', 'atan2', ' ',' cos ',' cosh ',' độ ',' e ',' exp ',' fabs ',' sàn ',' fmod ',' frexp ',' hypot ',' ldexp ',' log ', 'log10', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh con', 'sqrt', 'tan', 'tanh'] >>> hàm dir trả về danh sách một danh sách tất cả các thành phần được đặt tên trong một mô -đun Getting the Directory of a Module
>>> import math >>> dir(math) ['__doc__', '__file__', '__name__', 'acos', 'asin', 'atan', 'atan2', 'ceil', 'cos', 'cosh', 'degrees', 'e', 'exp', 'fabs', 'floor', 'fmod', 'frexp', 'hypot', 'ldexp', 'log', 'log10', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh'] >>> The dir function returns a list of all of the named components in a module

22 Nhận trợ giúp về một hàm >>> nhập toán >>> DIR (Toán học) ['__ Doc__', '__File__', '__name__', 'acos', 'asin', 'atan', 'atan2', 'ceil' , 'cos', 'cosh', 'độ', 'e', ​​'exp', 'fabs', 'sàn', 'fmod', 'frexp', 'hypot', 'ldexp', 'log', ',' log10 ',' modf ',' pi ',' pow ',' radians ',' sin ',' Sinh ',' sqrt ',' tan ',' tanh '] >>> trợ giúp (math.sqrt) sqrt ( x) Trả về căn bậc hai của x. Getting Help on a Function
>>> import math >>> dir(math) ['__doc__', '__file__', '__name__', 'acos', 'asin', 'atan', 'atan2', 'ceil', 'cos', 'cosh', 'degrees', 'e', 'exp', 'fabs', 'floor', 'fmod', 'frexp', 'hypot', 'ldexp', 'log', 'log10', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh'] >>> help(math.sqrt) sqrt(x) Return the square root of x.

23 In đầu ra (3, 4) # hiển thị 3 4 in (str (3) + str (4)) # hiển thị 34print ('Xin chào \ nken!') ) # Hiển thị một lineprint ('ken') in luôn kết thúc đầu ra bằng một dòng mới, trừ khi đối số cuối cùng của nó là kết thúc = '' Output print(3, 4) # displays 3 4 print(str(3) + str(4)) # displays 34
print('Hello there\nKen!') # displays two lines print('Hello there ', end='') # displays one line print('Ken') print always ends output with a newline, unless its last argument is end=''

24 Đối với hôm nay nhập toán và in ra thư mục của nó. For Today Import math and print out it’s directory.
Write a python script that asks the user for his/her name and age. Output Hello, name Output The square root of your age is: ans

Chương trình dựa trên thiết bị đầu cuối trong Python là gì?

Thiết bị đầu cuối là một cách dựa trên văn bản để tương tác với các tệp và chương trình trên máy tính của bạn. Một thiết bị đầu cuối cho phép bạn truy cập đầy đủ vào tất cả các hoạt động bên trong của máy tính, thông qua đầu vào dựa trên văn bản.a text based way to interact with the files and programs on your computer. A terminal allows you full access to all the inner workings of your computer, through text based input.

Làm thế nào để bạn viết một chương trình trong Python Terminal?

Viết mã đơn giản bằng trình thông dịch Python, bạn có thể sử dụng trình thông dịch Python bằng cách nhập Python vào thiết bị đầu cuối. Trình thông dịch Python cho phép bạn viết và thực thi từng dòng mã. Khi bạn viết mã phức tạp hơn, bạn sẽ muốn viết trước mã của mình. Các tập tin PY.use the python interpreter by typing python in the Terminal. The python interpreter lets you write and execute code line by line. As you write more complex code, you will want to pre-write your code in . py files.

Ứng dụng dựa trên thiết bị đầu cuối là gì?

Nó cung cấp một bộ khả năng phong phú để kiểm tra các thuộc tính máy chủ, thuộc tính trường máy chủ và luồng màn hình thông qua một ứng dụng máy chủ.Nó sử dụng các điểm xác minh và thuộc tính thiết bị đầu cuối, cũng như mã đồng bộ hóa để xác định mức độ sẵn sàng của thiết bị đầu cuối cho đầu vào của người dùng.provides a rich set of capabilities to test host attributes, host field attributes and screen flow through a host application. It uses terminal verification points and properties, as well as synchronization code to identify the readiness of terminal for user input.

Phần mềm dựa trên thiết bị đầu cuối là gì?

Một thiết bị đầu cuối cho phép người dùng chạy đầu ra xem chương trình dưới dạng văn bản trên màn hình hoặc trong đầu vào cửa sổ Nhập dưới dạng văn bản từ bàn phím Hệ thống máy tính sớm hoàn toàn dựa trên thiết bị đầu cuối, các hệ thống hiện đại đã thêm GUI (Giao diện người dùng đồ họa) được lấy từ:2 Hành vi của các chương trình dựa trên thiết bị đầu cuối. Early computer systems were entirely terminal-based, modern systems have added a GUI (graphical user interface) Retrieved from: 2 Behavior of Terminal-Based Programs.