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
1 trong mã của bạn.Copied!
# ✅ using input[] instead of raw_input[] s = input['Your name: '] print[s]
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ố
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.Copied!
# ✅ using input[] instead of raw_input[] s = input['Your name: '] print[s]
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ố
4 là sử dụng các cuộc gọi đến hàmCopied!
# ✅ using input[] instead of raw_input[] s = input['Your name: '] print[s]
6.Copied!
# ✅ using input[] instead of raw_input[] s = input['Your name: '] print[s]
Copied!
print['Your name: '] s = input[] print[s]
Điều này rất giống với việc chuyển đối số
4 cho hàmCopied!
# ✅ using input[] instead of raw_input[] s = input['Your name: '] print[s]
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"]