python - 删除 Python 计算器中的“无”字样
问题描述
我刚刚使用python语言创建了一个简单的计算器程序,但是这里有一个小问题,当我通过输入数字结束程序时1
,总是有文本none
。
问题是我如何摆脱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())
解决方案
更改print(pilihan())
为pilihan()
,返回值为pilihan()
None :)
推荐阅读
- python - 如何在请求会话中使用代理列表
- c# - 如何根据信息更改 if 语句
- jsonnet - 如何在 Jsonnet 中引用对象属性和对象本身
- sql - 如何在同一个表中的同一列中获取 2 个值的计数?
- python-2.7 - Python中的Arduinomillis()
- c# - 使用基于 tcp 的 Web 服务器显示来自 html 文件的图片
- android - RecyclerView adapter ViewHolder id is -1 sometimes
- woocommerce - 删除 woocommerc 结帐页面中的登录表单切换
- .net - 从 Azure 服务上的服务总线处理程序接收事件网格
- python - 3 用 Numpy 输入逻辑或 where