我在python中进行调查,我想打印一个字符串,但它一直说不能调用它

时间:2015-09-20 11:14:53

标签: python string

我做了一些研究,但网上的所有问题似乎都是错误的变量或不正确的.lower(),所以我想我会问。 这是我的代码。行print ('Here are your answers')是无法调用的字符串。

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')

1 个答案:

答案 0 :(得分:1)

我做了两处修改:

  1. 删除了=
  2. 等行中的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语句相同的缩进级别。
    2. 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')