im trying to create and algorithm in python but i created it in C++ instead as i don't know python well enough i know it's easy and i can learn it in one day or two it's just the syntax but i don't have the time to learn python right now (will do it later xd) so can you please convert it into python?
Code:
all i need to do is creating an algorithm that see integer numbers in a list lets call the list stocks or something and choose the min price without using min function and buy it on this day (just a variable called bought_on_day and print the number of the index) and same for sell but only difference is it will sell it at max price
#include <iostream>
using namespace std;
int main()
{
int max_profit = 0;
int n;
int buyday,sellday;
//input array size
cout<<"Enter the number of days : ";
cin>>n;
int arr[n];
//input all array values
for(int i=0;i<n;i++)
{cout<<"Enter the price on day "<<i+1<<": ";
cin>>arr[i];}
//logic is traverse the rightside of array from current day and update values accordingly
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(arr[j]-arr[i]>max_profit)
{max_profit=arr[j]-arr[i];
buyday=i;sellday=j;}
}
}
cout<<"Buying date :"<<"day "<<buyday+1<<", at the price of $"<<arr[buyday]<<"\n";
cout<<"Selling date :"<<"day "<<sellday+1<<", at the price of $"<<arr[sellday]<<"\n";
cout<<"Maximum profit : $"<<max_profit;
return 0;
}