-2

from A.py to B.py file

A.py file

def ticket():
    .
    .
    .
    tickets = child + student + senior + adult
    total_price = child * Child_price + student * student_price + senior * senior_price + adult * adult_price

How can i import total_price from A.py file to B.py file

Vaibhav Jadhav
  • 2,020
  • 1
  • 7
  • 20
sunil ghimire
  • 505
  • 4
  • 14

1 Answers1

2

Check out the below solution:

You need to import file A in file B and return the value from file B

File A.py contains:

def ticket():
    .
    .
    .
    .
    tickets = child + student + senior + adult
    total_price = child * Child_price + student * student_price + senior * senior_price + adult * adult_price
    return(tickets,total_price)

Contents of file B.py:

from A import ticket
tickets,total_price= ticket()
print(tickets,total_price)

OR

import A
print(A.ticket())

OR

from A import ticket
print(ticket())
Vaibhav Jadhav
  • 2,020
  • 1
  • 7
  • 20