关于#python#的问题:不可以使用max ,min ,exit ,break

img


只需要def main 里面的东西,不可以使用max ,min ,exit ,break ,continue

已帮你完成代码如下,望采纳

def main():
    while True:
        print("Enter 1 to convert Fahrenheit to Celsius")
        print("Enter 2 to convert Celsius to Fahrenheit")
        print("Enter 3 to calculate the body mass index (BMI)")
        print("Enter 4 to exit the program")
        choice = input("Enter your choice: ")

        if choice == "1":
            # ask for temperature in Fahrenheit and convert it to Celsius
            temp_fahrenheit = input("Enter the temperature in Fahrenheit: ")
            try:
                temp_fahrenheit = float(temp_fahrenheit)
                temp_celsius = (temp_fahrenheit - 32) * 5 / 9
                print("The temperature in Celsius is: ", temp_celsius)
            except ValueError:
                print("Invalid temperature value. Please try again.")

        elif choice == "2":
            # ask for temperature in Celsius and convert it to Fahrenheit
            temp_celsius = input("Enter the temperature in Celsius: ")
            try:
                temp_celsius = float(temp_celsius)
                temp_fahrenheit = temp_celsius * 9 / 5 + 32
                print("The temperature in Fahrenheit is: ", temp_fahrenheit)
            except ValueError:
                print("Invalid temperature value. Please try again.")

        elif choice == "3":
            # ask for weight and height and calculate BMI
            weight = input("Enter your weight in pounds: ")
            height = input("Enter your height in inches: ")
            try:
                weight = float(weight)
                height = float(height)
                bmi = weight / height ** 2 * 703
                print("Your BMI is: ", bmi)
            except ValueError:
                print("Invalid weight or height value. Please try again.")

        elif choice == "4":
            # exit the program
            print("Goodbye!")
            break

        else:
            print("Invalid menu choice. Please try again.")

        # add a little space after the results before displaying the menu again
        print()
        
# run the main function
main()

翻译翻译,我英文泰拉跨了

有中文吗,将文本粘贴一下也行

参考如此:



def main():
    print(
        """
        Menu:
            1:option "add"
            2:option "avg"
            3:option "multiplication"
            4:exit!
        """
    )
    action = input(f"Please select one No from [1-4]:")

    match action:
        case "1":
            sums()
        case "2":
            average()
        case "3":
            muil()
        case "4":
            print('Good bye')
            return
        case _:
            print("Invalid Menu chioce")
    main()

def sums():
    a = eval(input("Input num1: "))
    b = eval(input("Input num2: "))
    print(f"a + b = {a+b}")
    return

def average():
    seq = eval(input("Input a list nums;eg:[1,2,3]"))
    print(f"list nums avg is {sum(seq) / len(seq)}")
    return

def muil():
    pass

main()

在Python中,max,min,exit和break都是关键字,不能用作变量名或函数名。max和min用于返回可迭代对象中的最大值和最小值,exit用于退出Python程序,而break用于终止循环。
例如,您可以使用以下代码来查找列表中的最大值和最小值:

# 定义一个列表
my_list = [1, 2, 3, 4, 5]
# 使用 max 函数查找列表中的最大值
max_value = max(my_list)
# 使用 min 函数查找列表中的最小值
min_value = min(my_list)

在这里,max和min是Python的内置函数,不能用作变量名或函数名。