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.
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.
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.