Note that there are some explanatory texts on larger screens.

plurals
  1. PODealing with Functions (Basic Python)
    primarykey
    data
    text
    <p>I a new comer to programming (<strong>python</strong>) and have been doing some recent homework but I'm really stuck on this simple function implementation. Essentially, I have to ask for user input executed in the main() then define another function to work out the calculation with variables assigned to the user input. When run in IDLE, it outputs 0. Any help or hints will be immensely helpful, thankyou. Here is the code I have so far:</p> <pre><code>#global variables firstClass = 0.0 businessClass = 0.0 economyClass = 0.0 soldFirstClass = 0.0 soldBusinessClass = 0.0 soldEconomyClass = 0.0 totalFC = 0.0 totalBC = 0.0 totalEC = 0.0 ###################################### ###########MAIN FUNCTION############# ###################################### def main(): print('***WELCOME***\n') print('***Please ENTER the Airlines ticket prices***\n') firstClass = float(input ('Please ENTER a ticket price for First Class: ')) businessClass = float(input ('Please ENTER a ticket price for Business Class: ')) economyClass = float(input ('Please ENTER a ticket price for Economy Class: ')) print('\nThank You\n') soldFirstClass = float(input ('Please ENTER the number of sold tickets for First Class: ')) soldBusinessClass = float(input ('Please ENTER the number of sold tickets for Business Class: ')) soldEconomyClass = float(input ('Please ENTER the number of sold tickets for Economy Class: ')) calcClass() def calcClass(): global firstClass, soldFirstClass, businessClass, soldBusinessClass, economyClass, soldEconomyClass totalFC = firstClass*soldFirstClass print('Total money earned for First Class = %0.0f ') % totalFC totalBC = businessClass*soldBusinessClass print('Total money earned for Business Class = %0.0f ') % totalBC totalEC = economyClass*soldEconomyClass print('Total money earned for Economy Class = %0.0f ') % totalEC main() </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload