The Python Language is a simple start to programming. It was the first time I had used it and I found it vey interesting. There were certain commands and functions that took a little longer to get my head around and below I have posted my first assignment to give you an idea of how a python programme looks and whats actually included in the programme.
This is for a simple ATM programme:
# -*- coding: utf-8 -*-
def ATM_Service():
Pin = '2120'
Overdraft = 250
Balance = 1000
while True:
pin_input = raw_input('Insert Pin Now: ')
if Pin == pin_input:
print("PIN Confirmed")
print "Please Select an option from the menu below"
break
print("Invalid PIN try again")
while True:
menu_input = raw_input('\n 1.Balance \n 2.Withdraw \n 3.Deposit \n 4.Exit\n Enter option: ')
if ('1' == menu_input):
print "\n Balance remaining:" + str(Balance)
print "\n Overdraft remaining:" + str(Overdraft)
print "\n Total Balance Remaining:"
print int(Balance)+int(Overdraft)
raw_input("\n Press any key to return to menu...")
elif ('2' == menu_input):
print 'Withdraw Selected'
while True:
try:
option = int(raw_input("\n Enter Withdrawal Amount(Pounds): "))
except ValueError:
print "\n Oops invalid entry...try again"
continue
if option > 0:
if option > Balance + Overdraft:
print "\n That exceeds your limit...please enter valid amount"
continue
else:
Balance = Balance - option
else:
print "\n Invalid Withdrawal entry...please enter valid amount"
continue
break
print "\n You have withdrawn(£): " + str(option)
print "\n Balance is now: "
print int(Balance)+int(Overdraft)
raw_input("\n Press any key to return to menu...")
elif ('3' == menu_input):
print 'Deposit Selected'
while True:
try:
option = int(raw_input("Enter Deposit Amount(Pounds): "))
except ValueError:
print "Oops invalid entry...try again"
continue
if option < 1:
print "Invalid Deposit entry...try again"
continue
else:
Balance = Balance + option
break
print "You have deposited(£): " + str(option)
print "Balance is now: "
print int(Balance)+int(Overdraft)
raw_input("Press any key to return to menu...")
elif ('4' == menu_input):
raw_input("Until We Meet Again Compadre")
break
ATM_Service()
Have you used Python yet? What do you think of it? Did you enjoy designing a program?
ReplyDeletei copied and pasted your python work and when i tested it it didnt work. why would you upload it?
ReplyDeleteI highly doubt that.. this is the code I submitted for my assignment and I got an extremely good grade .. maybe u copied it wrong
Deleteno i didnt mate check your work probley your teacher is lieing to you, wake up son
ReplyDeleteEven if its wrong. I got a better mark for it than you did didn't I? Or do you need reminding?
DeleteNice code, what was your mark for it?
ReplyDeletePYTHON WAS HARD. it shouldn't have been an introduction to the foundation course!
ReplyDelete