![](/img/trans.png)
[英]How do I use the user value set in the in QDateEdit widget in another function?
[英]If a function returns a value entered by a user, how can I use that value in another function without asking the user to input another value
def userChoice():
print("Press 1 to send text message\n Press 2 to share file")
action = int(input("Please what do you want to do ? "))
return action
def useValue():
value=userChoice() + 1
print(value)
userChoice()
useValue()
""" 我發現第二個函數再次要求用戶輸入,而我不想要那個,相反我只需要用戶在第一個函數中已經給出的值 """
您需要獲取userChoice()
的結果並將其作為參數傳遞給useValue()
。 嘗試這個:
def userChoice():
print("Press 1 to send text message\n Press 2 to share file")
action = int(input("Please what do you want to do ? "))
return action
def useValue(choice):
value=choice + 1
print(value)
user_input = userChoice()
useValue(user_input)
按照您的方式,對userChoice
的第一次調用從用戶userChoice
獲取輸入,並且從不對其進行任何操作。 然后當useValue
被調用時,它會獲取另一個用戶輸入並將其用於打印輸出。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.