首页 > 解决方案 > 未调用 Python 函数。只能打印我的打印语句中的问题

问题描述

history = []
print("Options: 1) Integer Summation, 2) String concatenation, 3) Last Display, 4)Exit...")
def main():

    def summation():
      first_num = int(input("Type the first integer: "))
      second_num = int(input("Type the second integer: "))

      total_0 = first_num + second_num
      print("Sum of two integers is: ",total_0)

      history.append(total_0)

    def string():
      first_num = str(input(":ype the first string: "))
      second_num = str(input("Type the second string: "))

      total_1 = first_num + second_num
      history.append(total_1)
      print("Concatenation of two strings is: ",total_1)

    def last():
      print("The Previous result is: " + str(history()))

    def exits():
      print("Exiting...")

while True:
    x = str(input("Type your option: "))
    if x == "1" or x == "2" or x == "3" or x == "4":
        break
    

    if x == "1":
        summation()

    elif x == "2":
        string()

    elif x == "3":
        last()

    else:
        exits()
    
main()

标签: python

解决方案


你的while的缩进是错误的。它应该在您的主要功能中。


推荐阅读