So id like to make varibles from my function input
So basically, the if statement should check if the varible is True or not. And i want to use the function input + ”-outcome” to check.
Function-outcome = True Function2-outcome = False c def a(B): Global c If f’{B}-outcome’ == True: Print(”yes”) Else: Print(”no”) a(”function”) a(”function2”)
Here is an example, to make you understand my problem better!
I’ve tried to find a solution but don’t find it anywhere
Thanks!
Advertisement
Answer
import yfinance as yf from datetime import date import pandas as pd d_start = '2022-01-01' d_end = date.today().strftime('%Y-%m-%d') #top50 S&P to create a list, if you will use a variable from an API you will just need to declare it as a string #you can create a list of your fav ones and it will work the same, I grabbed from this site because it was the top 50 easy to get tl = pd.read_html('https://dailypik.com/top-50-companies-sp-500/')[0]['Symbol'].to_list() def main(l, d_start, d_end): #I used the download function here, you will use the one that will fulfill your aim, analysis, actions, balance_sheet #for isntance df = yf.earnings df = yf.download(str(l), start=d_start, end=d_end) #you can't assign a variable with a fstring, the work around is name the df opening opportunities later on df.name = l return df df_list = [main(k, d_start, d_end) for k in tl] di_ticks = {k:v for k,v in zip([df_list[i].name for i in range(0, len(df_list))], df_list)} #here you can pass any tick that you have in the tl(tick list) di_ticks['MSFT']