Các câu hỏi quan trọng cho khoa học máy tính lớp 12 (Python)Đơn vị - I: Lập trình hướng đối tượng với Python - Chương 1 Đánh giá về Python
- Chương 2 Khái niệm lập trình hướng đối tượng
Đơn vị - II: Lập trình trước với Python - Chương 3 liệt kê các thao tác và thực hiện
- Chương 4 Xử lý tệp dữ liệu
- Chương 5 Chức năng Xử lý & Máy phát điện ngoại lệ
Đơn vị - III: Hệ thống quản lý cơ sở dữ liệu và SQL - Chương 6 Khái niệm cơ sở dữ liệu
- Chương 7 Ngôn ngữ truy vấn có cấu trúc
Đơn vị - IV: Đại số Boolean Đơn vị - V: Công nghệ truyền thông phần mềm Mạng & Nguồn mở - Chương 9 Khái niệm Mạng và Nguồn mở
Giải pháp Sciencencert PythonComputer Chủ đề-1 Python Basics Câu hỏi câu trả lời rất ngắn (1 điểm) Python Basics Very Short Answer Type Questions(1 mark) Câu hỏi 1. Đặt tên cho các mô -đun thư viện Python cần được nhập để gọi các chức năng sau: Name the Python Library modules which need to be imported to invoke the following functions : - trọng tải ()
- POW () [CBSE DELHI 2016]
Answer: - dưa chua
- môn Toán
Câu hỏi 2. Đặt tên cho các mô-đun mà các chức năng sau thuộc về: Name the modules to which the following func-tions belong: - Đồng phục ()
- fabs () [CBSE SQP 2016]
Answer:
- ngẫu nhiên ()
- môn Toán ()
Câu 3. Phân biệt giữa các hàm vòng () và sàn () với sự trợ giúp của ví dụ phù hợp. [CBSE Comptt. 2016] Trả lời: Chức năng Vòng () được sử dụng để chuyển đổi một số phân số thành toàn bộ như gần nhất trong khi Slound () được sử dụng chuyển đổi sang số toàn bộ thấp nhất, ví dụ: Vòng (5,8) = 6, Vòng (4.1 ) = 5 và tầng (6,9) = 6, tầng (5.01) = 5 Differentiate between the round() and floor() functions with the help of suitable example. [CBSE Comptt. 2016] Answer: The function round() is used to convert a fractional number into whole as the nearest next whereas the function floor() is used convert to the nearest lower whole number, e.g., round (5.8) = 6, round (4.1) = 5 and floor (6.9) = 6, floor (5.01) = 5 Câu hỏi loại câu trả lời ngắn (2 điểm): Câu 1. Trong số những điều sau đây, hãy tìm các định danh đó, không thể được sử dụng để đặt tên các biến hoặc hàm trong chương trình Python: Tổng * Thuế, trong khi, lớp, Chuyển đổi, Hàng thứ 3, cuối cùng, Cột 31, Tổng cộng. [CBSE bên ngoài Delhi-2016] Trả lời: Tổng * Thuế, Lớp, Hàng thứ 3, cuối cùng Out of the following, find those identifiers, which cannot be used for naming Variables or functions in a Python program: Total * Tax, While, Class, Switch, 3rd Row, finally, Column 31, Total. [CBSE Outside Delhi-2016] Answer: Total * Tax, class, 3rd Row, finally Câu hỏi 2. Đặt tên cho các mô -đun thư viện Python cần được nhập để gọi các chức năng follwing: Name the Python Library modules which need to be imported to invoke the follwing functions : - sqrt()
- kết xuất () (CBSE bên ngoài Delhi-2016)
Answer: - môn Toán
- dưa chua
môn Toán Out of the following, find the identifiers, which cannot be used for naming Variable or Functions in a Python program: [CBSE Delhi 2016] _Cost, Price*Qty, float, switch, Address one, Delete, Number12, do Answer: Price *Qty, float, Address one, do Câu hỏi 2. Đặt tên cho các mô-đun mà các chức năng sau thuộc về: Out of the following find those identifiers, which can not be used for naming Variable or Functions in a Python Program: Days * Rent, For, A_price, Grand Total, do,
2Clients, Participantl, My city Answer: Illegal variables or functions name are as below: Days * Rent, do, 2Clients, For and Grant Total Because of being either keyword or including space or operator or starting with integar. Đồng phục () Name the function / method required for [CBSE SQP 2015] - fabs () [CBSE SQP 2016]
- ngẫu nhiên ()
Answer: - môn Toán ()
- Câu 3. Phân biệt giữa các hàm vòng () và sàn () với sự trợ giúp của ví dụ phù hợp. [CBSE Comptt. 2016] Trả lời: Chức năng Vòng () được sử dụng để chuyển đổi một số phân số thành toàn bộ như gần nhất trong khi Slound () được sử dụng chuyển đổi sang số toàn bộ thấp nhất, ví dụ: Vòng (5,8) = 6, Vòng (4.1 ) = 5 và tầng (6,9) = 6, tầng (5.01) = 5
Câu hỏi loại câu trả lời ngắn (2 điểm): Which
string method is used to implement the following: - Câu 1. Trong số những điều sau đây, hãy tìm các định danh đó, không thể được sử dụng để đặt tên các biến hoặc hàm trong chương trình Python: Tổng * Thuế, trong khi, lớp, Chuyển đổi, Hàng thứ 3, cuối cùng, Cột 31, Tổng cộng. [CBSE bên ngoài Delhi-2016] Trả lời: Tổng * Thuế, Lớp, Hàng thứ 3, cuối cùng
- Câu hỏi 2. Đặt tên cho các mô -đun thư viện Python cần được nhập để gọi các chức năng follwing:
- kết xuất () (CBSE bên ngoài Delhi-2016)
- Câu 3. Trong số những điều sau đây, hãy tìm các định danh, không thể được sử dụng để đặt tên biến hoặc chức năng trong chương trình Python: & nbsp; [CBSE DELHI 2016] Trả lời: Giá *Qty, Float, Địa chỉ một, DO
- Câu hỏi 4. Trong số những điều sau đây, tìm các định danh đó, không thể được sử dụng để đặt tên biến hoặc chức năng trong chương trình Python: Ngày * Thuê, cho, A_Price, Grand Total, DO, 2Clents, Người tham gia Tên các chức năng như dưới đây: Ngày * Thuê, làm, 2Clents, cho và cấp tổng số vì là từ khóa hoặc bao gồm không gian hoặc toán tử hoặc bắt đầu với Integar.
Answer: - len(str)
- str.capitalize()
- ch.isalnum()
- str.upper()
- str.replace(old,new)
Câu 5. Đặt tên cho hàm / phương thức cần thiết cho [CBSE SQP 2015] What is the difference between input() and raw_input()? Answer: raw_input() takes the input as a string whereas input() basically looks at what the user enters, and automatically determines the correct type. We use the inputQ function when you are expecting an integer from the end-user, and raw_input when you are expecting a string. Câu 8. Hai cách đầu ra sử dụng in () là gì? Trả lời: Thông thường, mỗi câu lệnh in tạo ra một dòng đầu ra. Bạn có thể kết thúc câu lệnh in với một dấu vết để kết hợp kết quả của nhiều câu lệnh in thành một dòng. What are the two ways of output using print()? Answer: Ordinarily, each print statement produces one
line of output. You can end the print statement with a trailing ’ to combine the results of multiple print statements into a single line. Câu 9. Tại sao biểu thức 2 + 3*4 dẫn đến giá trị 14 chứ không phải giá trị 24? Trả lời: Các quy tắc ưu tiên của toán tử* Làm cho biểu thức được hiểu là 2 + (3* 4) do đó kết quả là 14. Why does the expression 2 + 3*4 result in the value 14 and not the value 24? Answer: Operator precedence rules* make the expression to be interpreted as 2 + (3*4) hence the result is 14. Câu 10. Python sẽ thực thi mã bên trong vòng sau bao nhiêu lần? Bạn nên trả lời câu hỏi mà không cần sử dụng thông dịch viên! Biện minh cho câu trả lời của bạn. How many times will Python execute the code inside the following while loop? You should answer the question without using
the interpreter! Justify your answers. i = 0
while i < 0 and i > 2 :
print “Hello ...”
i = i+1 Trả lời: 0 lần. 0 times. Câu 11. Python sẽ thực thi mã bên trong vòng sau bao nhiêu lần? How many times will Python execute the code inside the following while loop? i = 1
while i < 10000 and i > 0 and 1:
print “ Hello ...”
i = 2 * i Trả lời: 14. 14. Câu 12. Chuyển đổi phần sau cho vòng lặp thành vòng lặp, cho I trong phạm vi (1.100): Convert the following for loop into while loop, for i in range (1,100): if i % 4 == 2 :
print i, “mod”, 4 , “= 2” Answer: i=1
while i < 100:
if i % 4 == 2:
print i, “mod”, 4 , “= 2”
i = i +1 Câu 13. Chuyển đổi phần sau cho vòng lặp thành vòng lặp. Convert the following for loop into while loop. for i in range(10):
for j in range(i):
print '$',
print" Answer: i=0
while i < 10:
j=0
while j < i:
print '$’
print" Câu 14. Viết lại những điều sau đây cho vòng lặp vào trong khi vòng lặp: [Sách văn bản CBSE] Rewrite the following for loop into while loop: [CBSE
Text Book] for a in range(25,500,25):
print a Answer: a=25
while a < 500:
print a
a = a + 25 Câu 15. Viết lại phần sau cho vòng lặp vào trong khi vòng lặp: [Sách văn bản CBSE] Rewrite the following for loop into while loop: [CBSE Text Book]
for a in range(90, 9, -9):
print a Answer: a = 90
while a > 9:
print a
a = a-9 Câu 16. Chuyển đổi phần sau trong khi vòng lặp thành vòng lặp: Convert the following while loop into for loop: i = 1
while i < 10000 and i > 0 and 1:
print “ Hello ...”
i = 2 * i 0Answer: i = 1
while i < 10000 and i > 0 and 1:
print “ Hello ...”
i = 2 * i 1Câu 17. Chuyển đổi phần sau trong khi vòng lặp thành vòng lặp Convert the following while loop into for loop i = 1
while i < 10000 and i > 0 and 1:
print “ Hello ...”
i = 2 * i 2Answer: i = 1
while i < 10000 and i > 0 and 1:
print “ Hello ...”
i = 2 * i 3Câu 18. Viết lại những điều sau trong khi vòng lặp vào vòng lặp: Rewrite the following while loop into for loop: i = 1
while i < 10000 and i > 0 and 1:
print “ Hello ...”
i = 2 * i 4Answer: i = 1
while i < 10000 and i > 0 and 1:
print “ Hello ...”
i = 2 * i 5Câu 19. Viết lại những điều sau trong khi vòng lặp vào vòng lặp: Rewrite the following
while loop into for loop: i = 1
while i < 10000 and i > 0 and 1:
print “ Hello ...”
i = 2 * i 6Answer: i = 1
while i < 10000 and i > 0 and 1:
print “ Hello ...”
i = 2 * i 7Câu 20. Viết cho tuyên bố để in loạt 10,20,30, 300 câu trả lời: 300 câu trả lời: Write for statement to print the series 10,20,30, ……., 300 Answer: i = 1
while i < 10000 and i > 0 and 1:
print “ Hello ...”
i = 2 * i 8Câu 21. Viết cho tuyên bố để in loạt 105,98,91, câu trả lời .7. Write for statement to print the series 105,98,91,… .7 Answer: i = 1
while i < 10000 and i > 0 and 1:
print “ Hello ...”
i = 2 * i 9Câu 22. Viết vòng lặp WHRE để in loạt: 5,10,15, Câu 100 Câu trả lời: Write the while loop to print the series: 5,10,15,…100 Answer: if i % 4 == 2 :
print i, “mod”, 4 , “= 2” 0Câu 23. Vòng lặp sau được thực hiện bao nhiêu lần? [Sách văn bản CBSE] cho một trong phạm vi (100,10, -10): In một câu trả lời: 9 lần. How many times is the following loop executed? [CBSE Text Book] for a in range(100,10,-10): print a Answer: 9
times. Câu 24. Vòng lặp sau được thực hiện bao nhiêu lần? [Sách văn bản CBSE] How many times is the following loop executed? [CBSE Text Book] if i % 4 == 2 :
print i, “mod”, 4 , “= 2” 1Trả lời: 6 lần 6 times Câu 25. Nêu cho dù tuyên bố là đúng hay sai? Bất kể kiểu dữ liệu cơ bản nếu các giá trị hoàn trả bằng nhau, State whether the statement is True or False? No matter the underlying data type if values are equal returns true, if i % 4 == 2 :
print i, “mod”, 4 , “= 2” 2Trả lời: Đúng. Hai giá trị của cùng một loại dữ liệu có thể bằng nhau. True. Two values of same data types can be equal. Câu 26. Các toán tử logic của Python là gì? Trả lời: Hoặc, và, không What are the logical operators of Python? Answer: or, and, not Câu 27. Sự khác biệt giữa ‘/và và‘ //? Câu trả lời: What is the difference between ‘/’ and ‘//’
? Answer: if i % 4 == 2 :
print i, “mod”, 4 , “= 2” 3Câu 28. Làm thế nào chúng ta có thể nhập một mô -đun trong Python? Trả lời: 1. Sử dụng nhập khẩu How can we import a module in Python? Answer: 1. using import if i % 4 == 2 :
print i, “mod”, 4 , “= 2” 42. Sử dụng từ if i % 4 == 2 :
print i, “mod”, 4 , “= 2” 5Câu 299. Sự khác biệt giữa các tham số và đối số là gì? Câu trả lời: What is the difference between parameters and arguments? Answer:
S.no. | Thông số | Tranh luận | 1 | Các giá trị được cung cấp trong tiêu đề chức năng | Các giá trị được cung cấp trong cuộc gọi chức năng. | 2 | (ví dụ: khu vực def (r): -> r là tham số —> r is the parameter
| . —> radius is the argument
|
Câu 30. Đối số mặc định là gì? Trả lời: Python cho phép các đối số chức năng có các giá trị mặc định; Nếu hàm được gọi mà không có đối số, đối số sẽ nhận được giá trị mặc định của nó What are default arguments? Answer: Python allowes function arguments to have default values; if the function is called without the argument, the argument gets its default value Câu 31. Đối số từ khóa là gì? Trả lời: Nếu có một hàm với nhiều tham số và chúng tôi chỉ muốn chỉ định một số trong số chúng trong cuộc gọi chức năng, thì giá trị cho các tham số đó có thể được cung cấp bằng cách sử dụng tên của chúng thay vì các vị trí. Chúng được gọi là đối số từ khóa. What are keyword arguments? Answer: If there is a function with many parameters and we want to specify only some of them in function call, then value for such parameters can be provided by using their names instead of the positions.
These are called keyword argument. if i % 4 == 2 :
print i, “mod”, 4 , “= 2” 6Câu 32. Ưu điểm của các đối số từ khóa là gì? Trả lời: dễ sử dụng hơn vì chúng tôi không cần nhớ thứ tự của các đối số. Chúng tôi có thể chỉ định các giá trị chỉ cho các tham số mà chúng tôi muốn và các giá trị khác có các giá trị mặc định. What are the advantages of keyword arguments? Answer: It is easier to use since we need not remember the order of the arguments. We can specify the values for only those parameters which we want, and others have default values. Câu hỏi 33. Những người khác trong trò chơi làm gì? TRẢ LỜI Nó đánh giá là true nếu nó tìm thấy một biến/chuỗi trong chuỗi được chỉ định: nếu không I+đánh giá là sai. What does “in” do? Answer: “in” is a membership operator. It evaluates to true if it finds a variable/string in the specified sequence : Otherwise i+evaluates
to false. if i % 4 == 2 :
print i, “mod”, 4 , “= 2” 7Câu hỏi 34. Không phải trong trò chơi nào? Trả lời: Không phải trong các nhà điều hành thành viên. Nó đánh giá đúng nếu nó không tìm thấy một biến/chuỗi trong chuỗi được chỉ định. Nếu không thì nó đánh giá là sai, What does “not in” do? Answer: “not in” is a membership operator. It evaluates to true if it does not finds a variable/string in the specified sequence. Otherwise it evaluates to false, if i % 4 == 2 :
print i, “mod”, 4 , “= 2” 8Câu 355. Slice Slice làm gì? Trả lời: Người vận hành [N: M] trích xuất các phần con từ một chuỗi. Nó không bao gồm các nhân vật tại Index m. What does “slice” do? Answer: The slice[n:m] operator extracts subparts from a string. It doesn’t include the character at index m. if i % 4 == 2 :
print i, “mod”, 4 , “= 2” 9Câu 36. Việc sử dụng các chỉ số tiêu cực trong việc cắt lát là gì? Trả lời: Số lượng Python từ cuối (phải) nếu các chỉ số âm được đưa ra. What is the use of negative indices in slicing?
Answer: Python counts from the end (right) if negative indices are given. i=1
while i < 100:
if i % 4 == 2:
print i, “mod”, 4 , “= 2”
i = i +1 0Câu 37. Giải thích chức năng Tìm ()? Trả lời: Tìm (Sub [, Start [, End]]) Hàm này được sử dụng để tìm kiếm lần xuất hiện đầu tiên của chuỗi con trong chuỗi đã cho. Nó trả về chỉ mục mà tại đó chuỗi con bắt đầu. Nó trả về -1 nếu chuỗi con không xảy ra trong chuỗi. Explain find() function? Answer: find (sub[,start[,end]]) This function is used to search the first occurrence of the substring in the given string. It returns the index at which the substring starts. It returns -1 if the substring doesn’t occur in the string. i=1
while i < 100:
if i % 4 == 2:
print i, “mod”, 4 , “= 2”
i = i +1 1Câu 38. Sự khác biệt giữa các mảng và danh sách là gì? Trả lời: Một mảng chứa số lượng giá trị cố định. Danh sách có độ dài thay đổi-các phần tử có thể được thêm động hoặc xóa một mảng giữ các giá trị của một loại. Liệt kê trong Python có thể giữ các giá trị của loại dữ liệu hỗn hợp. What are the differences between arrays and lists? Answer: An array holds
fixed number of values. List is of variable-length – elements can be dynamically added or removed An array holds values of a single type. List in Python can hold values of mixed data type. Câu 39. Sự khác biệt giữa một tuple và một danh sách là gì? Trả lời: Một tuple là bất biến trong khi một danh sách là một sự thay đổi. Một tuple không thể được thay đổi trong khi một danh sách có thể được thay đổi nội bộ. Một tuple sử dụng dấu ngoặc đơn (()) trong khi danh sách sử dụng dấu ngoặc vuông ([]). Khởi tạo Tuple: A = (2, 4, 5) Danh sách khởi tạo: A = [2, 4, 5] What is the difference between a tuple and a list? Answer: A tuple is immutable whereas a list is a mutable. A tuple cannot be changed whereas a list can be changed internally. A tuple uses parenthess (()) whereas a list uses square brackets ([]). tuple
initialization: a = (2, 4, 5) list initialization: a = [2, 4, 5] Câu 40. Cẩn thận quan sát mã Python sau đây và trả lời câu hỏi sau: X = 5 def func2 (): x = 3 Global x x = x+1 in X in X khi thực hiện Mã trên tạo ra đầu ra sau. 6 3 Giải thích đầu ra liên quan đến phạm vi của các biến. Trả lời: Tên được khai báo với từ khóa toàn cầu phải được giới thiệu ở cấp độ tệp. Điều này là do phạm vi toàn cầu. Nếu không có tuyên bố toàn cầu nào đang được sử dụng, biến với phạm vi cục bộ được truy cập. Do đó, trong mã trên, câu lệnh thành công, câu lệnh Global x thông báo cho Python để tăng biến toàn cầu x do đó, đầu ra là 6 tức là 5 + 1 cũng là giá trị cho toàn cầu X. Khi X được rủng cố với giá trị 3, X cục bộ ẩn toàn cầu X và do đó 3 được in. (2 điểm để giải thích đầu ra) (chỉ 1 điểm để giải thích không gian tên toàn cầu và địa phương.) Carefully observe the following python code and answer the question that follows: x=5 def func2(): x=3 global x x=x+1 print x print x On execution the above code produces the following output. 6 3 Explain the output with respect to the scope of the variables. Answer: Names declared with global keyword have to be referred at the file level. This is
because the global scope. If no global statement is being used the variable with the local scope is accessed. Hence, in the above code the statement succeeding the statement global x informs Python to increment the global variable x Hence, the output is 6 i.e. 5 + 1 which is also the value for global x. When x is reassingned with the value 3 the local x hides the global x and hence 3 printed. (2 marks for explaning the output) (Only 1 mark for explaining global and local
namespace.) Câu 41. Giải thích hai chiến lược được Python sử dụng để phân bổ bộ nhớ. . Khi một số tham chiếu của đối tượng đạt đến 0, Python sẽ tự động thu thập nó. Bộ sưu tập rác tự động: Lập lịch Python Bộ sưu tập rác dựa trên ngưỡng phân bổ đối tượng và giải quyết đối tượng. Khi số lượng phân bổ trừ đi số lượng giải quyết lớn hơn số ngưỡng, bộ thu rác được chạy và các khối bộ nhớ không sử dụng được thu hồi. Explain the two strategies employed by Python for memory allocation. [CBSE SQP 2016] Answer: Pythonuses two strategies for memory allocation- (i) Reference counting (ii) Automatic garbage collection Reference Counting: works by counting the number of times an object is referenced by other in the system. When an object’s reference count reaches zero, Python collects it automatically. Automatic Garbage Collection: Python schedules
garbage collection based upon a threshold of object allocations and object deallocations. When the number of allocations minus the number of deallocations are greater that the threshold number, the garbage collector is run and the unused blocks of memory is reclaimed. Chủ đề - 2 chương trình Python viết Writing Python Programs Câu hỏi 1. Viết lại mã sau trong Python sau khi xóa tất cả (các) lỗi cú pháp. Gạch chân mỗi hiệu chỉnh được thực hiện trong mã. ] Rewrite the following code in Python after removing all syntax errors(s). Underline each correction done in the code. [CBSE Delhi-2016] for Name in [Amar,
Shveta, Parag] if Name [0] = ‘s’: Print (Name) Answer: i=1
while i < 100:
if i % 4 == 2:
print i, “mod”, 4 , “= 2”
i = i +1 2Câu hỏi 2. Viết lại mã sau là Python sau khi xóa tất cả (các) lỗi cú pháp. Gạch chân mỗi hiệu chỉnh được thực hiện trong mã. [CBSE bên ngoài Delhi-2016] cho tên trong [Ramesh, Suraj, Priya] Nếu tên [0] = ‘Siêu: In (Tên) Trả lời: Rewrite the following code is Python after removing all syntax errors(s). Underline each correction done in the code. [CBSE Outside Delhi-2016] for Name in [Ramesh, Suraj, Priya] if Name [0] = ‘S’: Print (Name) Answer: i=1
while i < 100:
if i % 4 == 2:
print i, “mod”, 4 , “= 2”
i = i +1 3Câu 3. Đầu ra của mã Python sau đây sẽ xem xét tập hợp đầu vào sau đây là gì? Amar ba A123 1200 cũng vậy, giải thích việc thử và ngoại trừ được sử dụng trong mã. Start = 0 trong khi đúng: thử: number = int (đầu vào thô (nhập số nhập số)) ngắt trừ giá trịerror: start = start+2 in What will be the output of the following python code considering the following set of inputs? AMAR THREE A123 1200
Also, explain the try and except used in the code. Start = 0 while True : Try: Number = int (raw input (“Enter Number”)) break except valueError : start=start+2 print (“Re-enter an integer”) Print (start) Answer: Output: i=1
while i < 100:
if i % 4 == 2:
print i, “mod”, 4 , “= 2”
i = i +1 4Giải thích: Mã bên trong Thử đảm bảo rằng số hợp lệ được nhập bởi người dùng. Khi bất kỳ đầu vào nào khác, một số nguyên được nhập, lỗi giá trị sẽ được ném và nó nhắc người dùng nhập một giá trị khác. When any input other an integer is entered, a value error is thrown and it prompts the user to enter another value. Câu hỏi 4. Cung cấp đầu ra sau đây với sự biện minh. [CBSE SQP 2015] Give the output of following with justification. [CBSE SQP 2015] i=1
while i < 100:
if i % 4 == 2:
print i, “mod”, 4 , “= 2”
i = i +1 5Trả lời: Đầu ra: 3 Làm việc: Output: 3 Working: i=1
while i < 100:
if i % 4 == 2:
print i, “mod”, 4 , “= 2”
i = i +1 6Câu 5. Điều gì sẽ được in, khi theo mã Python được thực thi? [CBSE SQP 2015] What will be printed, when following Python code is executed? [CBSE SQP 2015] i=1
while i < 100:
if i % 4 == 2:
print i, “mod”, 4 , “= 2”
i = i +1 7Biện minh cho câu trả lời của bạn. Trả lời: 52 arjun.age = 50 arjun.dict có 2 thuộc tính để độ dài của nó là 2. Vì vậy, tổng số = 52. Answer: 52 arjun.age = 50 arjun.dict has 2 attributes so length of it is 2. So total = 52. Câu 6. Đầu ra của đoạn mã sau đây là gì? In 4+9 In PRIN 4+9 Câu trả lời: 13 (Bổ sung), 49 (Concatenation). What would be the output of the following code snippets? print 4+9 print “4+9” Answer: 13
(addition), 49 (concatenation). CÂU HỎI 7. Làm nổi bật các nghĩa đen trong chương trình sau và cũng dự đoán đầu ra. Đề cập đến các loại biến trong chương trình. Highlight the literals in the following program and also predict the output. Mention the types of variables in the program. i=1
while i < 100:
if i % 4 == 2:
print i, “mod”, 4 , “= 2”
i = i +1 8Trả lời: A, C, D = Integer B, E, F, G = Chuỗi đầu ra: 3 với Sathy Kathy, đã đi dự tiệc. 3 với Sathy, 2 với Sathy, 1 với Sathy và Kathy của anh, đã đi dự tiệc. a, c,d = integer b, e,f,g = string Output: 3 with Sathy Kathy, went to party. 3 with Sathy, 2 with Sathy , 1 with Sathy and his Kathy, went to party. Câu 8. Kết quả của 4+4/2+2 là gì? Trả lời: 4 + (4/2) + 2 = 8. What is the result of 4+4/2+2? Answer: 4 + (4/2) + 2 = 8. Câu 9. Viết đầu ra từ mã sau: [Sách văn bản CBSE] Write the output from
the following code: [CBSE Text Book] i=1
while i < 100:
if i % 4 == 2:
print i, “mod”, 4 , “= 2”
i = i +1 9Trả lời: - 10 – 10 Câu 10. Viết đầu ra của mã sau: In Py Python là một giải thích Write the output of the following code: print “Python is an \n interpreted \t Language” Answer: Python is an interpreted Language Câu 11. Viết đầu ra từ mã sau: Write the output from the following code: for i in range(10):
for j in range(i):
print '$',
print" 0Trả lời: sum = 28 sum= 28 Câu 12. Viết đầu ra từ mã sau: [Sách giáo khoa CBSE] Write the output from the following code: [CBSE TextBook] for i in range(10):
for j in range(i):
print '$',
print" 1Answer: for i in range(10):
for j in range(i):
print '$',
print" 2Câu 13. Viết đầu ra từ mã sau: [Sách giáo khoa CBSE] Write the output from the following
code: [CBSE TextBook] for i in range(10):
for j in range(i):
print '$',
print" 1Answer: for i in range(10):
for j in range(i):
print '$',
print" 2Câu 14. Quan sát chương trình sau và trả lời câu hỏi sau: Nhập ngẫu nhiên x = 3 n = ngẫu nhiên, randint (1, x) cho 1 trong phạm vi (n): in 1, ‘#, 1 + 1 a. Số lần tối thiểu và tối đa của vòng lặp sẽ thực thi là bao nhiêu? b. Tìm hiểu, dòng đầu ra nào từ (i) đến (iv) sẽ không được mong đợi từ chương trình? tôi. 0#1 ii. 1#2 III. 2#3 IV. 3#4 Trả lời: a. Số tối thiểu = 1 số tối đa = 3 b. Dòng IV dự kiến sẽ không phải là một phần của đầu ra. Observe the following program and answer the question that follows: import random x = 3 N = random, randint (1, x) for 1 in range (N): print 1, ‘#’, 1 + 1 a. What is the minimum and maximum number of times the loop will execute? b. Find out, which line of output(s) out of (i) to (iv) will not be expected from the program? i. 0#1 ii. 1#2 iii. 2#3 iv. 3#4 Answer: a. Minimum
Number = 1 Maximum number = 3 b. Line iv is not expected to be a part of the output. Câu 15. Quan sát mã Python sau một cách cẩn thận và có được đầu ra, sẽ xuất hiện trên màn hình sau khi thực hiện nó. [CBSE SQP 2016] Observe the following Python code carefully and obtain the output, which will appear on the screen after execution of it. [CBSE SQP 2016] for i in range(10):
for j in range(i):
print '$',
print" 5Trả lời: EA3N EA3n Câu 16. Tìm và viết đầu ra của mã Python sau: Find and write the output of the following Python code: for i in range(10):
for j in range(i):
print '$',
print" 6Answer:
Yếu tố | Ngăn xếp các nhà khai thác | Biểu thức postfix | 1# | 0 | 0 | 1# | (1#) | (1#) | 2# | (1#) | 2# | 1# | (1#) | 2# | 2# | (1#) | 1# | (1#) | (1#) | 2# |
| (1#2#) | (2#) |
(1#2#3#) What are the possible outcome(s) executed from the following code? Also, specify the maximum and import random. [CBSE Delhi 2016] 3#1#2# | (3#) | 1#2#3# | Câu 17. Kết quả có thể được thực hiện từ mã sau là gì? Ngoài ra, chỉ định tối đa và nhập ngẫu nhiên. [CBSE DELHI 2016] | for i in range(10):
for j in range(i):
print '$',
print" 7 | (tôi) | (ii) | Delhidelhi | Delhi |
| Mumbaimumbai | Delhimumbai | Câu 17. Kết quả có thể được thực hiện từ mã sau là gì? Ngoài ra, chỉ định tối đa và nhập ngẫu nhiên. [CBSE DELHI 2016] | Câu 17. Kết quả có thể được thực hiện từ mã sau là gì? Ngoài ra, chỉ định tối đa và nhập ngẫu nhiên. [CBSE DELHI 2016] | for i in range(10):
for j in range(i):
print '$',
print" 7 | for i in range(10):
for j in range(i):
print '$',
print" 7 | (tôi) | (ii) | Delhidelhi |
|
Delhi Option (i) and (iii) are possible option (i) only PICKER maxval = 3 minval = 0 Mumbaimumbai Find and write the output of the following Python code : [CBSE Outside Delhi-2016] for i in range(10):
for j in range(i):
print '$',
print" 8Answer:
Yếu tố | Ngăn xếp các nhà khai thác | Biểu thức postfix | 1# | 0 | 0 | 1# | (1#) | 2# | (1#2#) | 0 | (2#) | 1# | (1#) | 2# | (1#2#) | (2#) | 1# | (1#) | 0 | 2# |
| (1#) | 2# |
| (1#2#) |
|
| (2#) |
|
(1#2#3#) Write the output from the following code: for i in range(10):
for j in range(i):
print '$',
print" 93# Leap Year. 1#2# What does the following print? i=0
while i < 10:
j=0
while j < i:
print '$’
print" 0(3#) 1 2 3 4 5 6 7 8 9 2 4 6 8 10 12 14 16 18 3 6 9 12 15 18 21 24 27 4 8 12 16 20 24 28 32 36 5 10 15 20 25 30 35 40 45 6 12 18 24 30 36 42 48 54 7 14 21 28 35 42 49 56 63 8 16 24 32 40 48 56 64 72 9 18 27 36 45 54 63 72 81 1#2#3# What will be the
output of the following statement? Also, justify the answer. i=0
while i < 10:
j=0
while j < i:
print '$’
print" 1Câu 17. Kết quả có thể được thực hiện từ mã sau là gì? Ngoài ra, chỉ định tối đa và nhập ngẫu nhiên. [CBSE DELHI 2016] SyntaxError: invalid syntax. The single quote needs to be replaced by V to get the expected output. for i in range(10):
for j in range(i):
print '$',
print" 7 Give the output of the following statements :i=0
while i < 10:
j=0
while j < i:
print '$’
print" 2(tôi) ‘H*nesty is the best p*licy’. (ii) Give the output of the following statements : i=0
while i < 10:
j=0
while j < i:
print '$’
print" 3Delhidelhi True. Delhi Give the output of the following statements: i=0
while i < 10:
j=0
while j < i:
print '$’
print" 4Mumbaimumbai
Hello Python Delhimumbai Write the output for the following codes: i=0
while i < 10:
j=0
while j < i:
print '$’
print" 5Chennaichennai [(40,4000), (10,1000), (20,2000), (50,5000), (30,3000)] [40,10, 20, 50, 30] [4000,1000, 2000, 5000, 3000] Delhimumbaicehnnai Write the output from the following code: i=0
while i < 10:
j=0
while j < i:
print '$’
print" 6Kolkatakolkata 5 (iii) Write the output from the following code: i=0
while i < 10:
j=0
while j < i:
print '$’
print" 7(iv) ‘c’ A’ Mumbai Find the output from the following code: i=0
while i < 10:
j=0
while j < i:
print '$’
print" 8Chennai 100
2
Kolkatakolkatakolkata Write the output from the following code: i=0
while i < 10:
j=0
while j < i:
print '$’
print" 9Kolkata 0 -1 1 Trả lời: Tùy chọn (i) và (iii) là tùy chọn có thể (i) chỉ Picker MaxVal = 3 minval = 0 Write the output from the following code: for a in range(25,500,25):
print a 0Câu 18. Tìm và viết đầu ra của mã Python sau: [CBSE bên ngoài Delhi-2016] (10,20,30,40,50,100,200,300) 1* Find the output from the following code: for a in range(25,500,25):
print a 1(1.*) (‘Python’,) 1 3 (1*) Rewrite the following code in Python after remo¬ving all syntax error(s). Underline each correction done in the code. for a in range(25,500,25):
print a 22*
for studednt in values [“Jaya”, “Priya”, “Gagan”]: if student [0] = = “S” print (student) (1*2*) Find and write the output of the following Python code: for a in range(25,500,25):
print a 3(1,*) 1, 11 2,22 3,33 4, 44 (1*2*3*) What are the possible outcome(s) executed from the following code? Also, specify the maximum and minimum values that can be assigned to variable SEL. (2.*)1#2# | (3#) | Mumbaimumbai | Delhimumbai | Chennaichennai | Delhimumbaicehnnai | Delhimumbaicehnnai | Delhimumbaicehnnai | Kolkatakolkata | (iii) | (iv) | Kolkatakolkata | (iii) | (iv) | Mumbai | Chennai | Kolkatakolkatakolkata |
| Kolkata |
|
Trả lời: Tùy chọn (i) và (iii) là tùy chọn có thể (i) chỉ Picker MaxVal = 3 minval = 0 Maximum value of SEL is 3. The possible output is below DEER Monkey Monkey Kangaroo Kangaroo Kangaroo Thus (iv) is the correct option. Câu 18. Tìm và viết đầu ra của mã Python sau: [CBSE bên ngoài Delhi-2016] Random Functions 1* What are the possible outcome(s) executed from the following code ? Also specify the maximum and minimum values that can be assigned to variable PICKER. [CBSE Outside Delhi-2016] (1.*)1#2# | (3#) | Mumbaimumbai | Delhimumbai | Chennaichennai | Chennaichennai | Delhimumbaicehnnai | Kolkatakolkata | Delhimumbaicehnnai | Kolkatakolkata | (iii) | (iv) | Mumbai | Chennai | Kolkatakolkatakolkata | Kolkata | Trả lời: Tùy chọn (i) và (iii) là tùy chọn có thể (i) chỉ Picker MaxVal = 3 minval = 0 | Câu 18. Tìm và viết đầu ra của mã Python sau: [CBSE bên ngoài Delhi-2016] |
| 1* |
(1.*) Option (i) and (iv) are possible OR option (i) only PICKER maxval = 3 minval = 0 (1*) What are the possible outcome(s) expected from the following python code? Also specify maximum and minimum value, which we can have. [CBSE SQP 2015] for a in range(25,500,25):
print a 62* (ii) P – O – R – Y – (iii) O -R – A – G – (iv) A- G – R – M – Answer: Minimum value=5 Maximum value=8 So the only possible values
are O, G, R, A Only option (iii) is possible. (1*2*) Correcting The Errors (1,*) Rewrite the following Python code after removing all syntax error(s). Underline the corrections done. [CBSE SQP 2015] for a in range(25,500,25):
print a 7Answer: for a in range(25,500,25):
print a 8(1*2*3*) Rectify the error (if any) in the given statements. for a in range(25,500,25):
print a 9Answer: a=25
while a < 500:
print a
a = a + 25 0Câu 3. Tìm các lỗi từ mã sau: t = [a, b, c] in t Trả lời: nameError: Tên A A không được xác định. T = [‘A,’ B, ‘C,] Find the errors from the following code: T=[a,b,c] print T Answer: NameError: name ‘a’ is not
defined . T=[‘a’,‘b’,‘c’] Câu hỏi 4. Tìm các lỗi từ mã sau: Đối với I trong 1 đến 100: In I Trả lời: Đối với I trong phạm vi (1.100): In I Find the errors from the following code: for i in 1 to 100: print I Answer: for i in range (1,100): print i Câu 5. Tìm các lỗi từ mã sau: Find the errors from the following code: a=25
while a < 500:
print a
a = a + 25 1Answer: a=25
while a < 500:
print a
a = a + 25 2Câu 6. Tìm các lỗi từ mã sau: Find the errors from the following code: a=25
while a < 500:
print a
a = a + 25 3Answer: a=25
while a < 500:
print a
a = a + 25 4Câu 7. Tìm lỗi từ các mã sau: Find errors from the following codes: a=25
while a < 500:
print a
a = a + 25 5Answer: a=25
while a < 500:
print a
a = a + 25 6Câu 8. Quan sát định nghĩa lớp sau và trả lời câu hỏi sau: [CBSE SQP 2016] Observe the following class
definition and answer the question that follows : [CBSE SQP 2016] a=25
while a < 500:
print a
a = a + 25 7tôi. Viết câu lệnh để gọi hàm 1. ii. Khi thực hiện mã trên, câu lệnh 2 đang đưa ra một lỗi giải thích. Trả lời: i. In i ii. Câu lệnh 2 đang gây ra lỗi vì _ systemDate là một biến riêng tư và do đó không thể được in bên ngoài lớp. ii. On Executing the above code, Statement 2 is giving an error explain. Answer: i. print I ii. The statement 2 is giving an error because _ Systemdate is a private variable and hence cannot to be printed outside the class. Chủ đề - 5 chương trình ngắn Short Programs Câu 1. Viết một chương trình để tính diện tích của một hình chữ nhật. Chương trình nên có được chiều dài và chiều rộng; Giá trị từ người dùng và in khu vực. Câu trả lời: Write a program to calculate the area of a rectangle. The program should get the
length and breadth ; values from the user and print the area. Answer: a=25
while a < 500:
print a
a = a + 25 8Câu 2. Viết một chương trình để tính toán rễ của phương trình bậc hai. Câu trả lời: Write a program to calculate the roots of a quadratic equation. Answer: a=25
while a < 500:
print a
a = a + 25 9Câu 3. Viết một chương trình để nhập bất kỳ số nào và in tất cả các yếu tố của số đó. Câu trả lời: Write a program to input any number and to print all the factors of that number. Answer: for a in range(90, 9, -9):
print a 0Câu hỏi 4. Viết một chương trình vào đầu vào,. Bất kỳ số và để kiểm tra xem số đã cho có phải là Armstrong hay không. (Armstrong 1.153, v.v. 13 = 1, 13 +53 +33 = 153) Trả lời: Write a program to input ,.any number and to check whether given number is Armstrong or not. (Armstrong 1,153,etc. 13 =1, 13+53 +33 =153) Answer: for a in range(90, 9, -9):
print a 1Câu hỏi 5. Viết một chương trình để tìm tất cả các số nguyên tố lên đến một số đã cho câu trả lời: Write a program to find all the prime numbers up to a given number Answer: for a in range(90, 9, -9):
print a 2Câu 6. Viết một chương trình để chuyển đổi số thập phân thành nhị phân. Câu trả lời: Write a program to convert decimal number to binary. Answer: for a in range(90, 9, -9):
print a 3Câu hỏi 7. Viết chương trình chuyển đổi nhị phân thành câu trả lời thập phân: Write a program to convert binary to decimal Answer: for a in range(90, 9, -9):
print a 4Câu 8. Viết một chương trình để nhập hai số phức và để tìm tổng các số phức tạp đã cho. Câu trả lời: Write a program to input two complex numbers and to find sum of the given complex numbers. Answer: for a in range(90, 9, -9):
print a 5Câu 9. Viết một chương trình để nhập hai số phức và để thực hiện phép nhân các số phức tạp đã cho. Câu trả lời: Write a program to input two complex numbers and to implement
multiplication of the given complex numbers. Answer: for a in range(90, 9, -9):
print a 6Câu 10. Viết một chương trình để tìm tổng của tất cả các chữ số của số đã cho. Câu trả lời: Write a program to find the sum of all digits of the given number. Answer: for a in range(90, 9, -9):
print a 7Câu 11. Viết một chương trình để tìm mặt trái của một số. Câu trả lời: Write a program to find the reverse of a number. Answer: for a in range(90, 9, -9):
print a 8Câu 12. Viết một chương trình để in kim tự tháp. 1 2 2 3 3 3 4 4 4 4 5 5 5 5 Trả lời: Write a program to print the pyramid. 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 Answer: for a in range(90, 9, -9):
print a 9Câu 13. Viết một chương trình để nhập tên người dùng và mật khẩu và để kiểm tra xem tên người dùng và mật khẩu đã cho có chính xác hay không. Câu trả lời: Write a program to input username and password and to check whether the given
username and password are correct or not. Answer: a = 90
while a > 9:
print a
a = a-9 0Câu 14. Viết hàm tạo tạo tạo () hiển thị các hình vuông của các số từ 100 đến n trong đó n được truyền dưới dạng đối số. Câu trả lời: Write a generator function generatesq () that displays the squareroots of numbers from 100 to n where n is passed as an argument. Answer: a = 90
while a > 9:
print a
a = a-9 1Câu 15. Viết một phương thức trong Python để tìm và hiển thị số nguyên tố từ 2 đến n. Vượt qua N như là đối số cho phương thức. Câu trả lời: Write a method in Python to find and display the prime number between 2 to n. Pass n as argument to the method. Answer: a = 90
while a > 9:
print a
a = a-9 2Câu 16. Viết một chương trình để nhập tên người dùng và mật khẩu và để kiểm tra xem tên người dùng và mật khẩu đã cho có chính xác hay không. Câu trả lời: Write a program to input username and password and to check whether the given
username and password are correct or not. Answer: a = 90
while a > 9:
print a
a = a-9 3Câu 17. Phương thức chuỗi nào được sử dụng để thực hiện như sau: [Sách văn bản CBSE] Which string method is used to implement the following: [CBSE Text Book] - Để đếm số lượng ký tự trong chuỗi.
- Để thay đổi ký tự đầu tiên của chuỗi trong chữ cái.
- Để kiểm tra xem ký tự đã cho là chữ cái hay số.
- Để thay đổi chữ thường thành chữ hoa.
- Thay đổi một ký tự thành một nhân vật khác.
Answer: - len(str)
- str.title () hoặc str.capitalize ()
- str.isalpha và str.isdigit ()
- lower(str[i])
- str.replace (char, newchar)
Câu 18. Viết một chương trình để nhập bất kỳ chuỗi nào và để tìm số lượng từ trong chuỗi. Câu trả lời: Write a program to input any string and to find the number of words in the string. Answer: a = 90
while a > 9:
print a
a = a-9 4Câu 19. Viết một chương trình để nhập N số và chèn bất kỳ số nào vào một vị trí cụ thể. Câu trả lời: Write a program to input n numbers and to insert any number in a particular position. Answer: a = 90
while a > 9:
print a
a = a-9 5Câu 20. Viết một chương trình để nhập n số và tìm kiếm bất kỳ số nào từ danh sách. Câu trả lời: Write a program to input n numbers and to search any number from the list.
Answer: a = 90
while a > 9:
print a
a = a-9 6Câu 21. Viết một chương trình để tìm kiếm nhập bất kỳ tên khách hàng nào và hiển thị số điện thoại khách hàng nếu tên khách hàng tồn tại trong danh sách. Câu trả lời: Write a program to search input any customer name and display customer phone number if the customer name is exist in the list. Answer: a = 90
while a > 9:
print a
a = a-9 7Câu 22. Viết một chương trình để nhập N số và đảo ngược tập hợp số mà không cần sử dụng các hàm. Câu trả lời: Write a program to input n numbers and to reverse the set of numbers without using functions. Answer: a = 90
while a > 9:
print a
a = a-9 8Câu 23. Tìm và viết đầu ra của mã Python sau: [Bổ sung CBSE-2016] Find and write the output of the following Python code: [CBSE Complementry-2016] a = 90
while a > 9:
print a
a = a-9 9Answer: i = 1
while i < 10000 and i > 0 and 1:
print “ Hello ...”
i = 2 * i 00Câu 24. Đầu ra của mã Python sau đây sẽ xem xét tập hợp đầu vào sau đây là gì? What will be the output of the
following Python code considering the following set of inputs? i = 1
while i < 10000 and i > 0 and 1:
print “ Hello ...”
i = 2 * i 01mehtods: - dencal () # phương thức để mật độ tính toán như mọi người/khu vực - thêm () # phương thức để cho phép người dùng nhập các giá trị dcode, dname, con người, khu vực và gọi dencal () mehtod - xem () # phương thức để hiển thị tất cả Các thành viên dữ liệu cũng hiển thị một thông báo về số lượng lớn dân số Nếu mật độ lớn hơn 8000. Trả lời: Đầu ra dưới 2 RE nhập số 10 RE Nhập số 5 đầu vào = Số 3 đầu vào = Số thử và ngoại trừ được sử dụng để xử lý ngoại lệ trong Mã Pythan. – DenCal () # Method to calcualte Density as People/Area – Add () # Method to allow user to enter values Dcode, DName, People, Area and Call DenCal () Mehtod – View () # Method to display all the data members also display a message “”High Population” if the Density is more than 8000. Answer: Output is below 2 Re Enter Number 10 Re Enter Number 5 Input = Number 3 Input =
number Try and except are used for handling exception in the Pythan code. Câu 25. Viết một phương thức trong Python và hiển thị các số nguyên tố giữa 2 đến N. Truyền làm đối số cho các phương thức.Câu trả lời: Write a method in Python and display the prime numbers between 2 to N. Pass as argument to the methods. Answer: i = 1
while i < 10000 and i > 0 and 1:
print “ Hello ...”
i = 2 * i 02Câu hỏi loại câu trả lời dài (6 điểm) Câu 1. Aastha wnats để tạo một chương trình chấp nhận một chuỗi và hiển thị các ký tự ở phía sau trong cùng một dòng bằng cách sử dụng ngăn xếp.Cô đã tạo mã sau, giúp cô bằng cách hoàn thành các định nghĩa trên cơ sở các yêu cầu được đưa ra dưới đây: [CBSE SQP 2016] Aastha wnats to create a program that accepts a string and display the characters in the reverse in the same line using a Stack. She has created the following code, help her by completing the definitions
on the basis of requirements given below:[CBSE SQP 2016] i = 1
while i < 10000 and i > 0 and 1:
print “ Hello ...”
i = 2 * i 03Answer: i = 1
while i < 10000 and i > 0 and 1:
print “ Hello ...”
i = 2 * i 04Python & NBSP; NCERT Solutions |