我正在嘗試制作一個游戲,您可以在其中輸入命令并且游戲會做出回應。在游戲的某個部分,您必須選擇路徑并輸入 1 或 2,它會將用戶帶到 path1() 或 path2() def 但是當我到達該部分并輸入一個路徑時,一個不會運行它只會顯示 >>> 詢問我的命令,您可以在此處查看整個專案 --> https://github.com/CodeMaster-exe/thepengogame但這是我遇到問題的部分。
elif cmd == "job hut":
print("Manager: How may I help you?")
print(f"{user}: Can I get a job?")
print('''
Manager: I have 2 jobs to offer:
Job 1: A Community manager
Job 2: A Money manager
''')
sleep(1)
hmhy1r = int(input("Which would you like? Job (1) or Job (2)?: "))
if cmd == 1:
path1()
elif cmd == 2:
path2()
# paths
def path1():
print("hi")
def path2():
print("Working on path 2 taking you to path 1 in 3 seconds")
sleep(3)
path1()
我知道我從一個 elif 開始,但它上面有一個 if 陳述句,所以不要介意。還有一個while回圈正在運行,cmd = input(">>> ")但它一直在第一行。所以你可以再次在 github 上查看我的完整程式,上面的鏈接。
uj5u.com熱心網友回復:
您正在嘗試比較cmd哪個不是您存盤使用輸入的變數。
既然你寫
hmhy1r = input("Which would you like? Job (1) or Job (2)?: ")
你需要檢查hmhy1r價值
hmhy1r = int(input("Which would you like? Job (1) or Job (2)?: "))
if hmhy1r == 1:
path1()
elif hmhy1r == 2:
path2()
PENGUIN ADVENTURE PRESS A TO BEGIN
>>> c
What is your name ?: Sigma
What is your age (please no decimals)?: 20
Now you will be prompted to enter some info
Please enter a user name: Sigma
Now is when the Teaching begins press d to start
>>> job hut
Manager: How may I help you?
Sigma: Can I get a job?
Manager: I have 2 jobs to offer:
Job 1: A Community manager
Job 2: A Money manager
Which would you like? Job (1) or Job (2)?: 1
hi
>>> job hut
Manager: How may I help you?
Sigma: Can I get a job?
Manager: I have 2 jobs to offer:
Job 1: A Community manager
Job 2: A Money manager
Which would you like? Job (1) or Job (2)?: 2
Working on path 2 taking you to path 1 in 3 seconds
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/492280.html
上一篇:回傳2列中的2個值
下一篇:創建輸入向量和數字的函式
