删除python计算器中的“无”字

2024-09-19 23:29:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我刚刚用python语言创建了一个简单的计算器程序,但是这里有一个小问题,当我通过输入数字1结束程序时,总是有文本none

enter image description here

问题是我如何去掉我创建的程序中的文本none?因为说实话,这很烦人,会损害我创建的程序的形象

def pilihan():
    i = 0
    while i == 0:
        print('\n\tWelcome to the Simple Calculator Program')
        print("\nPlease Select Existing Operations", "\n1. subtraction", "\n2. increase", "\n3. division", "\n4. multiplication")
        pilihan2 = int(input('Enter your choice (1/2/3/4): '))
        if pilihan2 == 1:
            angka1 = int(input('Enter the First Number: '))
            angka2 = int(input('Enter the Second Number: '))
            print(angka1, "-", angka2, "=", angka1 - angka2)
        elif pilihan2 == 2:
            angka1 = int(input('Enter the First Number: '))
            angka2 = int(input('Enter the Second Number: '))
            print(angka1, "+", angka2, "=", angka1 + angka2)
        elif pilihan2 == 3:
            angka1 = int(input('Enter the First Number: '))
            angka2 = int(input('Enter the Second Number: '))
            print(angka1, ":", angka2, "=", angka1 / angka2)
        elif pilihan2 == 4:
            angka1 = int(input('Enter the First Number: '))
            angka2 = int(input('Enter the Second Number: '))
            print(angka1, "x", angka2, "=", angka1 * angka2)
        else:
            print('Error option, please try again')
            continue
        
        print('Program finished, want to restart?')
        y = 0
        while y == 0:
            ulang = int(input('Type 0 for YES and 1 for NO = '))
            if ulang == 0:
                y += 1
                break
            elif ulang == 1:
                y += 2
                break
            else:
                print('\nThe command you entered is an error, please try again')
                continue
        if y == 1:
            continue
        else:
            break

print(pilihan())

Tags: the程序numberinputifelseintfirst