小编Der*_*ick的帖子

我可以在输入语句中使用变量吗?

def main():
    total = 0.0
    totalcom = 0.0
    name = input("Please enter your name: ")
    for x in range(1, 8):
        sales = float(input("Please enter your sales from day", x))

        total += sales
        commission = sales * .1
        totalcom += commission

    print("Your total sales is: ", total)
    print("Your commission is: ", totalcom)


main()
Run Code Online (Sandbox Code Playgroud)

我的目标本质上是佣金计算器.我应该从用户那里获得每天的销售额.但是,我希望用户知道他们输入的信息是在哪一天.我得到的错误是"输入预期最多一个参数,得到2".那么有没有办法在输入语句中使用x?

python arguments input

3
推荐指数
1
解决办法
1万
查看次数

如何判断一个字符是否是元音

我正在尝试使用vector[].substr(),但我不知道这是否可能。有谁知道另一种方法可以做到这一点?我的目标是取出一个向量中的单词并将其与第一个元音分开。任何帮助表示赞赏。我的代码如下所示:

#include <iostream>
#include "derrick_math.h"
#include <string>
#include <sstream>
#include <vector>
#include <cctype>
#include <algorithm>
using namespace std;

int main()
{
    string phrase;
    string ay = "ay";
    vector<string> vec;
    cout << "Please enter the word or phrase to translate: ";
    getline(cin, phrase);

    istringstream iss(phrase);
    copy(istream_iterator<string>(iss), 
         istream_iterator<string>(), 
         back_inserter(vec));
    for (int i = 0; i < vec.size(); i++)
    {
        if (vec[i].substr(0, 1) == "a || e || i || o || u || A || E || I || O …
Run Code Online (Sandbox Code Playgroud)

c++

0
推荐指数
1
解决办法
8005
查看次数

标签 统计

arguments ×1

c++ ×1

input ×1

python ×1