2015-09-20 26 views
0

我已經做了一些研究,但所有在線問題似乎與不正確的變量或不正確.lower(),所以我我以爲我會問。 這是我的代碼。行print ('Here are your answers')是不能被調用的字符串。我正在python進行調查,我想打印一個字符串,但它一直說,它不能被稱爲

if age < 16: 

      favorite_film = input ('What is your favorite film? ') 
      print = ('Thank You') 

      favorite_book = input ('What is your faavorite book? ') 
      print = ('Thank You') 

      family_number = input ('How many people do you live with? ') 
      print = ('Thank You') 

      print ('Here are your answers') 
      print (name1) 
      print (name2) 
      print (town) 
      print (age) 
      print (favorite_film) 
      print (favorite_book) 
      print (family_number) 

      print ('You are finished, you may now leave') 

    elif age >= 16: 

      bank = input ('What bank do you store your money at? ') 
      print = ('Thank You') 

      house = input ('What kind of accomidation do you reside in? ') 
      print = ('Thank You') 

      favorite_food = input ('What is your favorite type of food? ') 
      print = ('Thank You') 

      print ('Here are your answers') 
      print (name1) 
      print (name2) 
      print (town) 
      print (age) 
      print (bank) 
      print (house) 
      print (favorite_food) 

      print ('You are finished, you may now leave') 
+0

未來,請參閱[如何創建最小,完整,可驗證示例](http://stackoverflow.com/help/mcve)。一般而言,StackOverflow問題中的代碼應該是其他人可以運行的最短可能的事情(意味着它需要運行得足以運行)才能看到同樣的問題;這個問題應該是精確的,包括例外或錯誤的確切文本。 –

回答

1

我做了兩個變化:

  1. 在線路如print = ('Thank you')

刪除了=通過指定一個字符串值print你推翻了它的意義,並解釋可能表明你此錯誤:

Traceback (most recent call last): 
    File "string.py", line 14, in <module> 
    print ('Here are your answers') 
TypeError: 'str' object is not callable 
  1. èlif age >= 16:移至與初始if聲明相同的縮進級別。

ifelif應該始終處於相同的縮進級別,即使它們綁在一起。 Python3

if age < 16: 
      favorite_film = input ('What is your favorite film? ') 
      print ('Thank You') 

      favorite_book = input ('What is your faavorite book? ') 
      print ('Thank You') 

      family_number = input ('How many people do you live with? ') 
      print ('Thank You') 

      print ('Here are your answers') 
      print (name1) 
      print (name2) 
      print (town) 
      print (age) 
      print (favorite_film) 
      print (favorite_book) 
      print (family_number) 

      print ('You are finished, you may now leave') 

elif age >= 16: 

      bank = input('What bank do you store your money at? ') 
      print ('Thank You') 

      house = input ('What kind of accomidation do you reside in? ') 
      print ('Thank You') 

      favorite_food = input ('What is your favorite type of food? ') 
      print ('Thank You') 

      print ('Here are your answers') 
      print (name1) 
      print (name2) 
      print (town) 
      print (age) 
      print (bank) 
      print (house) 
      print (favorite_food) 
      print ('You are finished, you may now leave') 
相關問題