Python Forum
A little help, I cannot find how to solve this
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A little help, I cannot find how to solve this
#1
Hi guys,

Below these lines done I have two programs that gives me two list. However, now, I have some problems which I cannot find anyplace which can give me hand to sort them out.

1. I would like to multiply the OPEX_evolution(26) outcome by a constant in order that each item of the list is multiply by that constant
            e.g.  79241500 * 2 = 158483000

2. How can I transform the outcome OPEX_evolution(26) into a string:

 e.g.     from                                                                  into: [79241500, 80826330,.......,124955863.04342265, 127454980.30429111]
 
 79241500

80826330.0

82442856.6

84091713.732

85773548.00664

87489018.96677281

89238799.34610827

91023575.33303043

92844046.83969104

94700927.77648486

96594946.33201456

98526845.25865485

100497382.16382794

102507329.8071045

104557476.4032466

106648625.93131153

108781598.44993776

110957230.41893652

113176375.02731526

115439902.52786157

117748700.57841879

120103674.58998717

122505748.08178692

124955863.04342265

127454980.30429111


3. How can I select from the OPEX_evolution(26) one item (e.g. the third one: 82442856.6) and be multiply by one constant (e.g. x = 25)

and 

4. Giving OPEX_evolution(26) and Grid_Price(26), how can I do to write them in such a way that, when running, I have got two columns and how can interact between them?

Cheers, I hope I can develop  faster so that I can master this language. Sorry, it is my first approach to programming


# OPEX evolution for 25 years                                                     #PROGRAM TO OBTAIN OPEX FOR 25 YEARS

print('OPEX FOR 25 YEARS')

def OPEX_evolution®:
    Total_initial = Total_OPEX
    print(Total_initial)
    Total_initial_h = Total_initial

    for n in range(2, r):
        Total_initial_h = Total_initial_h * (1 + Interest_Rate)
        print(Total_initial_h)

OPEX_evolution(26)



# GRID PRICE                                                                                          #PROGRAM TO OBTAIN GRID PRICES


ROC = Offshore_ROC
print('ROC')
print(Offshore_ROC)

print('GRID PRICE')

def Grid_Price®:
    Initial_Price = Baseline_price
    Initial_Price_baseline = Baseline_price + ROC
    print(Initial_Price_baseline)
    Initial_price_h = Initial_Price

    for n in range(2,21):
        Initial_price_h = Initial_price_h * (1 + Interest_Rate)
        Last_Price = Initial_price_h + ROC
        print(Last_Price)
    for n in range(21,r):
        Initial_price_h = Initial_price_h * (1 + Interest_Rate)
        print(Initial_price_h)

Grid_Price(26)


RUNNING IT GIVES:


OPEX FOR 25 YEARS                                                           #OPEX LIST

79241500

80826330.0

82442856.6

84091713.732

85773548.00664

87489018.96677281

89238799.34610827

91023575.33303043

92844046.83969104

94700927.77648486

96594946.33201456

98526845.25865485

100497382.16382794

102507329.8071045

104557476.4032466

106648625.93131153

108781598.44993776

110957230.41893652

113176375.02731526

115439902.52786157

117748700.57841879

120103674.58998717

122505748.08178692

124955863.04342265

127454980.30429111




GRID PRICE                                                     #GRID PRICES


118.495
119.535
120.5958
121.677816
122.78147232
123.90720176640001
125.05544580172801
126.22665471776256
127.42128781211781
128.63981356836018
129.8827098397274
131.15046403652192
132.44357331725234
133.7625447835974
135.10789567926935
136.48015359285475
137.87985666471184
139.30755379800607
140.7638048739662
142.24918097144553
77.26926459087443
78.81464988269192
80.39094288034576
81.99876173795268
83.63873697271173
Reply
#2
That's a massive block of text.  Could you maybe cut that down a bit so it's easier to read?  Maybe with only one or two lines of output, along with what you want the output to be?

And why not just multiply it?  
items = OPEX_evolution(25)
constant = 100
for item in items:
   print(item * constant)
Reply
#3
(Nov-10-2016, 04:17 PM)nilamo Wrote: That's a massive block of text.  Could you maybe cut that down a bit so it's easier to read?  Maybe with only one or two lines of output, along with what you want the output to be?

And why not just multiply it?  
items = OPEX_evolution(25)
constant = 100
for item in items:
   print(item * constant)
Sorry for that, I did it that way so that it can be understood. 
The code you just given, it doesn't work. I tried before and I don't get anything. The point is when you define a function
def f(x):

   z=7

   for n in range(1,5):

       a= 2

       b=3

       c = a + b

       print(c)

   for n in range(5,x):

       h = z

       print(h)


f(7)
Outcome:       How f(7)*2 will give the outcome:   How f(7) outcome can be move into [5,5,5,5,7,7]

Output:
5              10 5              10 5              10 5              10 7              14 7              14
Edit admin:
Use code tag,look at BBCode help button in the middel of editor.
Reply
#4
Instead of printing within the function, build a list and return it. Then you can modify the results however you want before displaying it.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020