2017-07-10 111 views
0

我目前正在製作一個基於文本的RPG,並且爲了解決在輸入過程中區分大小寫的問題,我使用了.upper使其全部爲大寫。但是,它似乎不適用於我的代碼。有人可以幫忙嗎?.upper命令不工作

if weapon in normalswords or weapon in fireswords or weapon in airswords or weapon in grassSwords: 
       if weapon in normalswords: 
        print (normalswords[weapon]) 
        while y== True: 
         variable= input("Equip? Yes or No") 
         variable.upper() 
         if variable== "YES": 
          print (weapon, "Equipped") 
          x= False 
          y=False 
         elif variable == "NO": 
          x= True 
         else: 
          print ("That is not a valid answer") 
          y=True 

回答

2

str.upper()返回轉換爲大寫的字符串的副本。它不會修改字符串,因爲字符串在Python中是不可變的。

試試這個:

variable = variable.upper()