Hướng dẫn why is raw_input not working in python? - tại sao raw_input không hoạt động trong python?

NameError: Tên 'RAW_Input' không được định nghĩa trong Python #

Python "NameError: name 'raw_input' không được xác định" xảy ra khi chúng ta sử dụng hàm raw_input[] trong Python 3. Để giải quyết lỗi, hãy sử dụng hàm input[] thay vì raw_input trong các ứng dụng Python 3, ví dụ: ________số 8.

Dưới đây là một ví dụ về cách xảy ra lỗi.

Copied!

# ⛔️ NameError: name 'raw_input' is not defined s = raw_input['Your name: '] print[s]

Hàm raw_input đã được đổi tên thành đầu vào trong Python 3.

Để giải quyết lỗi, hãy thay thế các cuộc gọi đến raw_input bằng

Copied!

# ✅ using input[] instead of raw_input[] s = input['Your name: '] print[s]
1 trong mã của bạn.

Copied!

# ✅ using input[] instead of raw_input[] s = input['Your name: '] print[s]

Đảm bảo thay thế tất cả các cuộc gọi cho chức năng raw_input[] bằng input[] trong Python 3.

Hàm đầu vào có một đối số

Copied!

# ✅ using input[] instead of raw_input[] s = input['Your name: '] print[s]
4 tùy chọn và ghi nó vào đầu ra tiêu chuẩn mà không cần một dòng mới.

Hàm sau đó đọc dòng từ đầu vào, chuyển đổi nó thành một chuỗi và trả về kết quả.

Một giải pháp thay thế để cung cấp đối số

Copied!

# ✅ using input[] instead of raw_input[] s = input['Your name: '] print[s]
4 là sử dụng các cuộc gọi đến hàm

Copied!

# ✅ using input[] instead of raw_input[] s = input['Your name: '] print[s]
6.

Copied!

print['Your name: '] s = input[] print[s]

Điều này rất giống với việc chuyển đối số

Copied!

# ✅ using input[] instead of raw_input[] s = input['Your name: '] print[s]
4 cho hàm input[] nhưng thay vì hiển thị lời nhắc trên cùng một dòng, nó được hiển thị trên một dòng riêng biệt.

Sự kết luận #

Python "NameError: name 'raw_input' không được xác định" xảy ra khi chúng ta sử dụng hàm raw_input[] trong Python 3. Để giải quyết lỗi, hãy sử dụng hàm input[] thay vì raw_input trong các ứng dụng Python 3, ví dụ: ________số 8.

Ok vì vậy tôi đã thay đổi nó thành:

if input['a']:
      print ["You: Gimme a gun!"]

if input['b']:
       print ["You: Fine"]

Nhưng bây giờ tôi không nhận được lựa chọn, nó buộc tôi phải chọn A và sau đó, nó buộc tôi phải chọn B, một khi tôi vượt qua trở ngại này, tôi có phần còn lại của trò chơi trong túi nhưng tôi thực sự cần sự giúp đỡ để tìm ra điều này ra P.S. Tôi là Noob to Python

import time
Gimme=True
Fine=True




print ["James: Ah, it looks like subject 091-266 is awake"]
time.sleep[4]
print ["Scarlet: Hello, do you remember anything? The crash or anything?"]
time.sleep[4]
print ["You: What.... Where am I?"]
time.sleep[3]
print ["Scarlet: Oh, where are my manners, this is the head quarters of the XionRepublic, Xion"]                        
time.sleep[5]
print ["James: You were involved in Z-9102, code named Attack-Z"]
time.sleep[4]
print ["Scarlet: We were able to pull you and three others out before we  were forced to..."]                                             
print ["James: Exterminate Alpha Base 12."]
time.sleep[6]
print ["You: Exterminate?! Couldn't you just quarantine it?"]
time.sleep[4]
print ["Scarlet: No, Alpha Base 12 had over 3,000 people in it, it was to risky to quarantine"]      
time.sleep[5]
print ["James: Do you recognize these names, Noah, Alex or Robert?"]
time.sleep[4]
print ["You: Yes Alex!? Why? Is he ok?!"]
time.sleep[3]
print ["James: Yes, Yes he was one of the three."]
time.sleep[4]
print ["*ALARM! SECURITY BREACHED, SECURITY BREACHED*"]
time.sleep[4]
print ["James: Scarlet lock the door!"]
time.sleep[3]
print ["You: Whats going on?!"]
time.sleep[3]
print ["James: Z's there here."]
time.sleep[3]
print ["*Screaming*"]
time.sleep[2]
print ["You: I can fight!"]
time.sleep[3]
print ["Scarlet: Trust me you are not in any condition to fight due to some of the drugs in you"]   
print ["CHOICE"]
print ["A.Gimme the gun!"]
print ["B.Fine"]

if raw_input[] == Gimme:
    print ["You: Gimme a gun!"]
if raw_input[] == Fine:
    print ["You: Fine"]

Tại sao Raw_Input không được xác định trong Python?

Python "NameError: name 'raw_input' không được xác định" xảy ra khi chúng ta sử dụng hàm raw_input [] trong python 3. Để giải quyết lỗi, hãy sử dụng hàm input [] thay vì raw_input trong các ứng dụng Python 3, ví dụ: s = input ['tên của bạn:'].occurs when we use the raw_input[] function in Python 3. To solve the error, use the input[] function instead of raw_input in Python 3 applications, e.g. s = input['Your name: '] .

Làm cách nào để định nghĩa Raw_Input trong Python?

Ở đây, giá trị của Python3, nhận được từ người dùng và lưu trữ nó trong biến Val1.Loại giá trị được lưu trữ luôn luôn là chuỗi cho chức năng RAW_Input.... Python3 ..

Sự khác biệt giữa đầu vào [] và raw_input [] là gì?

Về cơ bản, sự khác biệt giữa RAW_Input và đầu vào là loại trả về của RAW_Input luôn luôn là chuỗi, trong khi loại trả về của đầu vào không chỉ cần chỉ là chuỗi.Python sẽ đánh giá loại dữ liệu nào sẽ phù hợp nhất.Trong trường hợp bạn đã nhập một số, nó sẽ lấy nó làm số nguyên.the return type of raw_input is always string, while the return type of input need not be string only. Python will judge as to what data type will it fit the best. In case you have entered a number, it will take it as an integer.

Đầu vào thô có tồn tại trong Python 3 không?

Các trường hợp ngoại lệ của raw_input [] trong python hàm raw_input [] chỉ hoạt động trong python 2 và không hoạt động trong python 3.Python 2 hỗ trợ cả hàm đầu vào [] và raw_input [] nhưng Python 3 chỉ hỗ trợ hàm input [].does not work in python 3 . python 2 supports both input[] and raw_input[] functions but python 3 supports only input[] function.

Bài Viết Liên Quan

Chủ Đề