Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python modules?
#1
Hey all,

I'm really new to python(I used C/C++ in the past and strongly prefer it). I'm having trouble using "modules". What I got was that they're supposed to be like functions but overly simplified. Python is supposed to be REALLY simple but I feel like I'm going crazy over all my errors being invisible. No bracket, semicolons, proper endings just everything all floating out in the ether.
num = float(input('Enter the cost of your meal: '))


def conver(num):

    while num < 0 or num == 0:
     num = float(input('please enter a positive number: '))
    #rejects numbers 0 or below
    if num > .01 and num < 5.99:
     tip = (num / 100) * 10
    elif num > 6 and num < 12:
      tip = (num/100) * 15
    elif num > 12.01 and num < 17:
       tip = (num/100) * 20
    elif num > 17.01 and num < 25:
       tip = num/100 * 25
    else:
      tip = (num/100) * 30
    return tip
#calculates tip depending on input


def calculate(num, tip):

    tax = (num / 100) * 10
    total = num + tip + tax


print("Food cost: $", round(num))
print("Tip: $",'{0:.1f}'.format(tip))
print("Tax: $",'{0:.1f}'.format(tax))
print("Total: $",'{0:.1f}'.format(total))
#Displays results back to user after calculations.
# The tax and total are set to one digit after the decimal, float values as shown.
#The example showed integer values for 'food' and 'tip' so they were rounded.

conver(num)
calculate(num, tip)
This is basically what I'm working on. It's a mess because I keep trying different thingsnames. The problem I'm having is:

1. tax = (num / 100) * 10
total = num + tip + tax
depending on indentation ONE of those variables disappears/ "Is not used in scope"

2. chunks of the modules work and other don't based on same patterns. Everything ran smoothly before I tried to create 'modules'. Python is REALLY weird to me and our book mostly has pseudocode (which feels pretty useless without keywords or syntax to make things run). Anything I look up looks simple enough and I don't know if something is fundamentally wrong or if I just have a wrong space in the gears.

3. Only one of my print statements will run and local variables aren't acknowledged in the lower mod. I could see numbers being wrong but I can barely tell where things begin and end.
Reply


Messages In This Thread
python modules? - by Kuron3ko - Feb-07-2018, 09:19 PM
RE: python modules? - by nilamo - Feb-07-2018, 09:47 PM
RE: python modules? - by Gribouillis - Feb-07-2018, 09:53 PM
RE: python modules? - by Kuron3ko - Feb-07-2018, 10:15 PM
RE: python modules? - by buran - Feb-08-2018, 07:14 AM
RE: python modules? - by kmcollins - Feb-10-2018, 04:47 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020