python中的基本计算器程序 [英] Basic calculator program in python
本文介绍了python中的基本计算器程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是用python写了一个简单的计算器脚本,通常python默认会识别(-)减号(*)乘号(/)分隔符号,但考虑到此脚本,它无法识别符号。请留下您的评论以使我明白...
I just wrote a simple calculator script in python, generally python should recognize the (-)minus,(*)multiplication,(/)divide sign by default but while considering this script it's fails to identify the signs. please leave your comments to clear me...
#! /usr/bin/python
print("1: ADDITION")
print("2: SUBTRACTION")
print("3: MULTIPLICATION")
print("4: DIVISION")
CHOICE = raw_input("Enter the Numbers:")
if CHOICE == "1":
a = raw_input("Enter the value of a:")
b = raw_input("Enter the value of b:")
c = a + b
print c
elif CHOICE == "2":
a = raw_input("Enter the value of a:")
b = raw_input("Enter the value of b:")
c = a - b
print c
elif CHOICE == "3":
a = raw_input("Enter the value of a:")
b = raw_input("Enter the value of b:")
c = a * b
print c
elif CHOICE == "4":
a = raw_input("Enter the value of a:")
b = raw_input("Enter the value of b:")
c = a / b
print c
else:
print "Invalid Number"
print "\n"
推荐答案
您需要更改输入内容,串s为整数或浮点数。由于存在除法,因此最好将其更改为浮点数。
You need to change your inputs, strings to integer or float. Since, there is division you are better change it to float.
a=int(raw_input("Enter the value of a:"))
a=float(raw_input("Enter the value of a:"))
这篇关于python中的基本计算器程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文