如何编写用于计算字母字符数的Python代码

时间:2017-02-09 13:21:21

标签: python math calculator sympy

我想创建python计算器解决2a + 3a,3ab + 5ab之类问题。我做了普通的计算器,但我想创建这种类型的计算器。怎么做?给我一些想法

1 个答案:

答案 0 :(得分:0)

让我们说你得到了输入,

#include "../../std_lib_facilities.h"

int main() {
int one, ten, twenty, fifty, one_pound, two_pound;
double amount;
amount = (one * 0.01) + (ten * 0.1) + (twenty * 0.2) + (fifty * 0.5) + one_pound + (two_pound * 2);
cout << "Welcome to the change counter app!\nHow many 1p's do you have?\n";
cin >> one;
cout << "How many 10p's do you have?\n";
cin >> ten;
cout << "How many 20p's do you have?\n";
cin >> twenty;
cout << "How many 50p's do you have?\n";
cin >> fifty;
cout << "How many £1 coin's do you have?\n";
cin >> one_pound;
cout << "How many £2 coin's do you have?\n";
cin >> two_pound;
cout << "You have: " << one << " 1p coins!\n"
    << "You have: " << ten << " 2p coins!\n"
    << "You have: " << twenty << " 20p coins!\n"
    << "You have: " << fifty << " 50p coins!\n"
    << "You have: " << one_pound << " £1 coins!\n"
    << "You have: " << two_pound << " £2 coins!\n"
    << "The total amount of money you have is: " << amount << "\n";
}

python版本2.7 +