From arduino code to Python

Hello,
I’m using this code to show the speed in an LCD. i wrote it in the arduino code, I must write it in Python code, any one help me please, thank you in advance.

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

const byte TRIGGER=6;   
const byte ECHO=7;   
const float vitesse_du_son=34; 

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  Serial.begin(9600);
pinMode(8,OUTPUT);
digitalWrite(8,LOW);
pinMode(9,OUTPUT);
digitalWrite(9,HIGH);
pinMode(TRIGGER,OUTPUT);
digitalWrite(TRIGGER,LOW);
pinMode(ECHO,INPUT);


  
}

float distance()
{
digitalWrite(TRIGGER, HIGH);
delayMicroseconds(10);
digitalWrite(TRIGGER, LOW);
unsigned long duration = pulseIn(ECHO, HIGH);
return duration * 0.034 / 2; } 
void loop() {
 

float distance1 = distance();
delay(10);
float distance2 = distance();
float vitesse = (distance1 - distance2) * 10 *10/ 10;


   lcd.setCursor(0,0);
  // Print a message to the LCD.
  lcd.print("speed is:"); 
  lcd.setCursor(0,1);
  
  lcd.print(vitesse);
    lcd.print(" cm/s");
  lcd.noDisplay();
  delay(500);
  lcd.display();
  delay(500);

}

If you had asked for someone to write you some code for Arduino, the response would likley be that this is a forum where people are prepared to help you, not write code for you.

So you want someone to convert the code into Python ?

If the Arduino code works, why do you need to write it in Python, what specific device are you going to run it on ?

Hello
I have to write it in python for the folowing reason : we study just python language in our school an i have to present this project in few days.. and i need help to convert some functions into python ...I have looked for how to translate the code but got few informations. i'd like to know how to import Lcd library and work with functions related to it in a python code.
thank you

Hamzaelyou:
Hello
I have to write it in python for the folowing reason : we study just python language in our school an i have to present this project in few days.. and i need help to convert some functions into python ...I have looked for how to translate the code but got few informations. i'd like to know how to import Lcd library and work with functions related to it in a python code.
thank you

Have you, using your favorite search engine, looked to see if the library already exists as Python code?

You would like someone to write, for you, Python code from CPP, for free?

Hamzaelyou:
I must write it in Python code,

If you want help writing a Python program then you should ask on a Python Forum.

What hardware are you going to run the Python code on?

...R

we study just python language in our school

So how come you can’t write in it? What have you spent your time doing?

i’d like to know how to import Lcd library and work with functions related to it in a python code.

Basically you can’t for the following reasons:-

  1. The Arduino library is written in C, and calling C routines in Python, while not impossible, is difficult.
  2. Even if you could call the library it is written in a hardware specific way. It would not even work in other C environments let alone your Python environment.
  3. You need to understand and rewrite the whole of the library in Python as a class, and adapt to the machine specific environment you have but will not tell us about.