简体   繁体   English

如何将某些内容附加到函数的结果中并将其存储在python中的变量中

[英]How can I append something to a result of a function and store that in a Variable in python

I am trying to write a Program that will work out the max. 我试图写一个程序,将最大。 profit and one function is "Steigung" which I need to work out the optimum price. 利润和功能之一就是“ Steigung”,我需要制定出最佳价格。

So what I have is: 所以我有:

def Steigung ():
    Propreis=eval(raw_input("Dein hoechster Preis:"))
    Satmenge=eval(raw_input("Wie viele leute werden es kaufen:"))
    if Propreis >0 and Satmenge >0:
        print(-1*Satmenge/Propreis)

and this works fine but what I want to do is to add the Value I specified in "Satmenge" so that the result is for example if Satmenge = 100000 and Propreis = 6 is -16666x+100000 instead of -16666 by itself and how can I store the desired result in a variable to use later? 并且它可以正常工作,但是我想要做的是添加我在“ Satmenge”中指定的值,这样的结果是,例如,如果Satmenge = 100000且Propreis = 6是-16666x + 100000而不是-16666本身,以及如何我将所需的结果存储在变量中以备后用? Thanks in advance 提前致谢

You can return multiple values in the following way: 您可以通过以下方式返回多个值:

def Steigung ():
    Propreis=eval(raw_input("Dein hoechster Preis:"))
    Satmenge=eval(raw_input("Wie viele leute werden es kaufen:"))
    if Propreis >0 and Satmenge >0:
        print(-1*Satmenge/Propreis)
    return Propreis, Satmenge

And store the returned values like that: 然后像这样存储返回的值:

a, b = Steigung()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将存储在变量中的函数结果存储为字符串? - How can I store the result of a function stored in variable as a string? 如何在Python中调用带有存储为字符串的变量的函数 - How in Python can I call a function with a variable which is store as a string 我何时应该将函数的结果存储为python中的变量? - When should I store the result of a function as a variable in python? 我可以将函数结果转换为python / FLASK中另一个函数的变量吗? - Can I transform a function result into a variable for another function in python/FLASK? 如何存储通过“ for statement”变量获得的打印结果? - how can i store the printing result, obtained by “for statement” variable? Python:如何将 function 的结果分配给我可以读取的变量_csv - Python: How do I assign the result of my function to a variable that i can read_csv 将函数结果存储到变量中 - Store function result into variable 将函数的结果存储为变量 - Store the result of a function as a variable 如何将中间结果存储在 pyspark reduceByKey 函数中? - how can I store the intermediate result in pyspark reduceByKey function? 如何将密码查询值存储到python函数内的变量中? - How can I store the cypher query value into a variable inside python function?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM