Python: input function not accessible on website? - python

I wrote a script and it works on Anaconda. However, on the website (hosted by namecheap), the input function doesn't seem to work, what is wrong?
Website address: http://xterraminer.com.au/cgi-bin/nctests.py
Have already set up namecheap python to Django, not sure if this helped.
> user_input=float(input("What is your income?")) tax=float()
> take_home=float() if user_input<=18200:
> print("You pay $0 tax") elif user_input>18200 and user_input<=37000:
> tax=(user_input-18200)*0.19
> print("Your tax is $",tax) elif user_input>37000 and user_input<=90000:
> tax=(user_input-37000)*0.325+3572
> print("Your tax is $",tax) elif user_input>90000 and user_input<=180000:
> tax=(user_input-18200)*0.37+20797
> print("Your tax is $",tax) elif user_input>180000:
> tax=(user_input-18200)*0.45+54097
> print("Your tax is $",tax) take_home=user_input-tax print("Your take home pay is $", take_home)
Would expect the website asking for an input

Related

How to permanently change a variable in Python?

I decided to make a code in Python that is like an ATM Machine, and Everything works very well, you can check your balance, extract or add money,and change the PIN code. But when I change the PIN code i tried to assign the "changed_pin_code" variable to the "real_pin_code" variable,and it doesen't work, the PIN code remains the same. If you could give me some ideas on how I could solve the problem, or improve my code, that would be fantastic.
I am at the beggining with coding, and I am doing this so I can test my knowledge.
I left the code below.
def atm_machine():
code = input("Enter yout PIN code:")
pin_code = int(code)
real_pin_code = 4137
balance = 10000
if pin_code == real_pin_code:
print("""
ATM
1)Check Balance
2)Add money
3)Extract money
4)Change PIN code\n""")
number_select = int(input("Select a number:"))
if number_select > 4 and number_select == 0:
print("You must select a number between 1 and 4!")
atm_recall()
if number_select == 1:
print("Your current balance is:", balance, "$")
atm_recall()
if number_select == 2:
money_add = int(input("Enter amount of money you want to add:"))
new_money = balance + money_add
print("Your current balance is:", new_money, "$")
atm_recall()
if number_select == 3:
money_extract = int(input("Enter the amount of money you want to extract:"))
if money_extract > balance:
print("Insufficent fund")
atm_recall()
if money_extract <= balance:
remained_money = balance - money_extract
balance = remained_money
print("Your current balance is:", remained_money, "$")
atm_recall()
if number_select == 4:
measure_pin = 9999
changed_pin_code = int(input("Enter new PIN code:"))
if changed_pin_code == real_pin_code:
print("You can't enter the same PIN code:")
print("Wait for yout card!")
atm_recall()
if changed_pin_code > measure_pin:
print("PIN code must be formed of 4 digits!")
print("Wait for your card")
atm_recall()
else:
real_pin_code = changed_pin_code
print("PIN code succesfully changed!")
print("Your new PIN code is:", changed_pin_code)
atm_recall()
else:
print("PIN code inccorect!")
print("Wait for your card!")
def atm_recall():
question = str(input("To make another action, type \"Y\",else, type\"N\" "))
if question == "Y":
result = atm_machine()
return result
if question == "N":
print("Good Bye!")
print("Wait for your card!")
atm_machine()
The problem you are currently facing is because at end of each option you call atm_recall function, in which if the user selects the 'Y' option, it calls the atm_machine function which whenever called starts with real_pin_code set to 4137.
Solution:
As already mentioned by others, in comments what you should rather do is get rid of the recursion as it uses up a lot of memory and fills up the call stack on each function call. So a refactored approach would be something like this:
real_pin_code = 4137
balance = 10000
while True:
code = input("Enter yout PIN code:")
pin_code = int(code)
if pin_code == real_pin_code:
print("""
ATM
1)Check Balance
2)Add money
3)Extract money
4)Change PIN code\n""")
number_select = int(input("Select a number:"))
if number_select == 1:
print("Your current balance is:", balance, "$")
elif number_select == 2:
money_add = int(input("Enter amount of money you want to add:"))
balance = balance + money_add
print("Your current balance is:", balance, "$")
elif number_select == 3:
money_extract = int(input("Enter the amount of money you want to extract:"))
if money_extract > balance:
print("Insufficent fund")
else:
remained_money = balance - money_extract
balance = remained_money
print("Your current balance is:", remained_money, "$")
elif number_select == 4:
measure_pin = 9999
changed_pin_code = int(input("Enter new PIN code:"))
if changed_pin_code == real_pin_code:
print("You can't enter the same PIN code:")
print("Wait for yout card!")
elif changed_pin_code > measure_pin:
print("PIN code must be formed of 4 digits!")
print("Wait for your card")
else:
real_pin_code = changed_pin_code
print("PIN code succesfully changed!")
print("Your new PIN code is:", changed_pin_code)
else:
print("You must select a number between 1 and 4!")
else:
print("PIN code inccorect!")
print("Wait for your card!")
question = str(input("To make another action, type \"Y\",else, type\"N\" "))
if question == "N":
print("Good Bye!")
print("Wait for your card!")
break
Changes:
I took real_pin_code out of the loop, so its value doesn't reset at each iteration.
Also, for the same reason I took balance out of the loop and made the changes to balance itself rather than declaring a new variable new_money.
Also, as a good programming practice I changed a lot of if statements to elif and else where the conditions were exclusive of each other.
Better Approach:
A better approach, as already highlighted by others would be to use class where you would initialize an ATMMachine object with all the required details. However the approach you choose, mostly all the logic would remain the same except some refactoring and specific methods for each task.
I'm not sure if it's a best way to do it, but I would create a txt file with atm pin which You could read in the beggining to take pin code and write it when You want to change it. Something like this:
def atm_machine():
code = input("Enter yout PIN code:")
pin_code = int(code)
real_pin = open("code.txt", "r")
real_pin_code = int(real_pin.read())
Here I already have a txt file with some code created in program folder so python could read it, and here I'm saving new pin to same txt file:
else:
real_pin = open("code.txt", "w")
real_pin.write(str(changed_pin_code))
print("PIN code succesfully changed!")
print("Your new PIN code is:", changed_pin_code)
atm_recall()
Hope this helps anyhow.

Expected expression ATM

I was following along with a youtube video to a ATM using python and I got expected expression. I dont know how to fix it. line 32, 37 and 40.
enter image description here
You can't have an elif after an else. This is because else will capture all the remaining cases. Indentation, meaning spaces or tabs before the line is very important in Python.
Here is what I think you meant to write:
balance = 1000
print("""
Welcome to Dutch Bank
Choose Transaction
1) BALANCE
2) WITHDRAW
3) DEPOSIT
4) EXIT
""")
while True:
option = int(input("Enter Transaction"))
if option == 1:
print ("Your Balance is", balance)
anothertrans = input("Do You Want to make another Transaction? Yes/No: ")
if anothertrans == "YES":
continue
else:
break
elif option == 2:
withdraw = float(input("Enter Amount To Withdraw"))
if (balance > withdraw):
total = balance - withdraw
print("Success")
print("Your New Balance is: ",total)
else:
print("Insufficient Balance")
elif option == 3:
deposit = float(input("Enter Amount To Deposit"))
totalbalance = balance + deposit
print("Sucess")
print("Total Balance Now is: ", totalbalance)
elif option == 4:
print("Thank You ForBanking With Dutch Bank")
exit()
else:
print ("No selected Transaction")

Having trouble with while loops and collecting user input

Hi I'm working on an assignment where I make a self-service program. I'm having trouble trying to incorporate a while loop while collecting user input. I want my code to collect an amount of money (entered by the user) and prompt the user on how much more they need to pay. Once the amount paid exceeds the amount due, I want to continue with the rest of my code. This is what I have so far but the loop stops after 2 inputs, even if the user has not paid enough.
elif paid < TotalCost:
due = TotalCost - paid
while due > 0:
print("You need to pay $",round(due,2)," more.")
morepaid=float(input("Enter the amount paid: $"))
if morepaid>TotalCost:
change= morepaid- TotalCost
print("Change due: $",round(change,2))
print(" ")
print("Thank you for visiting McDonald's")
elif due== 0:
print("Change due: $0.00")
print(" ")
print("Thank you for visiting McDonald's")
else:
due -= morepaid
You can simply subtract the amount paid from due, you don't need another variable totalpaid.
elif paid < totalCost:
due = totalCost - paid:
while due > 0:
print("You need to pay $",round(due,2)," more.")
morepaid=float(input("Enter the amount paid: $"))
due -= morepaid

If else statement not outputting correctly?

I'm a beginner to Python and am struggling with a project I am working on. The program takes monthly income, fixed monthly expenses, asks for any additional expenses, and then outputs with an if else statement. My issue is in this function:
def spending(income, totals):
finalTotal = income - totals
if income > finalTotal:
print("You saved $", "%.2f"%finalTotal, "this month!")
elif finalTotal > income:
print("You overspent by $", "%.2f"%finalTotal, "this month!")
else:
print("You broke even this month!")
It is printing:
You saved $ -805.00 this month!
When I'd like it to print:
You overspent by $ 805.00 this month!
Any feedback would be greatly appreciated!!
Here is my code:
https://replit.com/#ashleyshubin/BudgetProgram#main.py
If totals is your monthly expenses, then subtracting totals from income gives you how much money you made this month. The first if statement should be
if finalTotal > 0:
The second if statement would be
if finalTotal < 0:
And you would want to use abs(finalTotal) when printing finalTotal so it does not display a negative number
Your checks are wrong. You can do the following:
def spending(income, totals):
finalTotal = income - totals
if income > totals:
print("You saved $", "%.2f"%finalTotal, "this month!")
elif totals > income:
print("You overspent by $", "%.2f"%-finalTotal, "this month!")
else:
print("You broke even this month!")
This section is where it is going wrong:
finalTotal = income - totals
if income > finalTotal:
print("You saved $", "%.2f"%finalTotal, "this month!")
It looks like you're comparing the wrong variables in your "if" statement. your "finalTotal" variable already includes your income. Think of it like alegbra, and replace "finalTotal" with "income - totals", and your if statement now looks like:
if income > (income - totals):
this statement will always evaluate to true, no matter what values you are using. You probably want to rewrite your if statements to compare "income > totals", rather than finalTotal.
your comparison shoud be based on finaltotal , as fianaltotal is finalTotal = income - totals, also else never runs based on the other conditions in your code:
def spending(income, totals):
finalTotal = income - totals
if finalTotal > 0:
print("You saved $", "%.2f" % finalTotal, "this month!")
else:
print("You overspent by $", "%.2f" % abs(finalTotal), "this month!")
you should be comparing Income with total spends.
def spending(income, totals):
finalTotal = abs(income - totals)
if totals < income:
print("You saved $", "%.2f"%finalTotal, "this month!")
elif totals > income:
print("You overspent by $", "%.2f"%finalTotal, "this month!")
else:
print("You broke even this month!")

why can't i enter if condition 3 and 4. 1 and 2 are working fine for this sample banking code

please can anyone check my code and correct me why I am unable to enter if statement when I was given option input==3 and option input==4.
import sys,os,math
Account_balance= int(25000)
print('*** WELCOME TO SBI BANK NAKKALAGUTTA ***')
givenpin=input('Enter The 4 Digit Pin Number ')
if givenpin =='0351':enter code here
print('welcome MR.Anudeep RAO')
else:
print('unauthorized access try again')
sys.exit()
print('your A/C number is: 10987xxxxxx')
print("### choose an option below ###")
print("""
1) Balance
2) Withdraw
3) Deposit
4) Quit
""")
option = int(input("Enter option:"))
if option == 1:
print('your Account balance is' +' '+ str(int(Account_balance)) +'Rs/-')
elif option == 2:
input_to_Withdraw = int(input("enter amount to withdraw "))
if input_to_Withdraw > 25000:
print("Insufficient Funds in Your A/C")
elif input_to_Withdraw < 25000:
present_balance = (Account_balance - input_to_Withdraw)
print('collect cash and available balance is ' + str(int(present_balance)))
if option == 3:
Input_to_Deposit = int(input("enter amount to deposit into A/C "))
print('deposited balance is:')
print(Account_balance +Input_to_Deposit)
if option == 4:
print('Transaction complete leave bank safely Bye:')
The if option == 3: and if option == 4: cases are deep inside the elif option == 2: case. Since you don't reset the value of option anywhere, I assume this is a mistake.
Fix the indentation of these two cases so your code has a chance to follow these paths. They should be at the same indentation level as elif option == 2:.

Categories