Re: [Tutor] Recognising Errors

2014-04-21 Thread Saba Usmani
Thanks for the advice and tips. I wasn't taking anything as an insult; I just 
have a problem with one of the staffs attitude responses. He needs sleep. 

Alan Gauld has been very helpful- a special thanks to you.

Kind regards
Saba


On 21 Apr 2014, at 18:40, Danny Yoo d...@hashcollision.org wrote:

 If for some reason you can't read this code properly as outlook has
 formatted it to look messy/cluttered; you do not have to respond.
 
 You are missing the point of people point this out.  Look at what the
 email archive thinks of your previous messages:
 
   https://mail.python.org/pipermail/tutor/2014-April/100904.html
   https://mail.python.org/pipermail/tutor/2014-April/100940.html
   https://mail.python.org/pipermail/tutor/2014-April/100985.html
   https://mail.python.org/pipermail/tutor/2014-April/100997.html
 
 
 When folks are saying that we can't read your programs, we're not
 trying to insult you.  Rather, we're making a very technical
 observation: your email client is interfering with the indentation of
 your program.  In Python, indentation and formatting _changes_ the
 meaning of your program, so we really can not tell what your program
 _means_.  Under those conditions, we can't help very effectively.
 
 If you really can not fix your email client, then post your programs
 on a pastebin which should preserve formatting and meaning.  For
 example, http://gist.github.com.  But please do not treat the advice
 you're been getting as personal insults.  They are not intended to be
 such.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Recognising Errors

2014-04-20 Thread Saba Usmani
Hi,
I have designed some code, but I want it to be able to recognize invalid inputs 
- such as a binary number with more than 8 digits or non-binary values. What do 
I have to add and where do I add it?
print Welcome to the binary - decimal / decimal - binary converter!loop = 
Truewhile loop:choice = raw_input(Enter b to convert from binary to 
decimal, d to convert from decimal to binary or e to exit)if choice == 
b:decimal_num = 0binary_num = 0factor = 1;
binary_num = raw_input (Enter Binary Number:)
binary_num=binary_num.lstrip(0)binary_num = int(binary_num)
while(binary_num  0):if((int(binary_num) % 10) == 1):  
  decimal_num += factorbinary_num /= 10factor = factor 
* 2print The Decimal Equivalent is: , decimal_num   elif 
choice == d:z=0n=int(input('Enter Decimal Number: ')) 
   z=nk=[] # arraywhile (n0):a=int(float(n%2)) 
   k.append(a)n=(n-a)/2k.append(0)string= 
   for j in k[::-1]:string=string+str(j)print('The 
Binary Equivalent is %d is %s'%(z, string)) elif choice == e :
print Thanks For Using This Converter!loop = False

If for some reason you can't read this code properly as outlook has formatted 
it to look messy/cluttered; you do not have to respond. 
Thanks___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Creating an Invalid Message for user

2014-04-18 Thread Saba Usmani
Hi,
I am meant to design code for a program that converts from binary number to 
decimal and vice versa. 
This is what i have so far:
print Welcome to the binary and decimal converterloop = Truewhile loop:
bord = raw_input(Enter b for binary or d decimal or exit to exit)if bord 
== b:d = 0b = 0factor = 1;b = raw_input 
(Enter Binary Number:)b=b.lstrip(0)b = int(b)
while(b  0):if((int(b) % 10) == 1):d += factor 
   b /= 10factor = factor * 2print The Decimal Number 
is: , d   elif bord == d:x=0n=int(input('Enter 
Decimal Number: '))x=nk=[] # arraywhile (n0):  
  a=int(float(n%2))k.append(a)n=(n-a)/2
k.append(0)string=for j in k[::-1]:
string=string+str(j)print('The binary Number for %d is %s'%(x, string)) 
elif bord == exit :print Goodbyeloop = False
- This code does not recognize invalid inputs e.g in the binary to decimal 
conversion, so if I enter e.g 10021, not a binary number, it will not inform 
me,the user, that the input is invalid. The same problem occurs with the 
decimal to binary conversion - if i enter e.g 123gf I am not told to try 
again with a valid input  - how do I implement this in the code above
ThanksSaba___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Creating an Invalid message for user

2014-04-11 Thread Saba Usmani
Hi,
I am meant to design code for a program that converts from binary number to 
decimal and vice versa. 
This is what i have so far:
print Welcome to the binary and decimal converterloop = Truewhile loop:
bord = raw_input(Enter b for binary or d decimal or exit to exit)if bord 
== b:d = 0b = 0factor = 1;b = raw_input 
(Enter Binary Number:)b=b.lstrip(0)b = int(b)
while(b  0):if((int(b) % 10) == 1):d += factor 
   b /= 10factor = factor * 2print The Decimal Number 
is: , d   elif bord == d:x=0n=int(input('Enter 
Decimal Number: '))x=nk=[] # arraywhile (n0):  
  a=int(float(n%2))k.append(a)n=(n-a)/2
k.append(0)string=for j in k[::-1]:
string=string+str(j)print('The binary Number for %d is %s'%(x, string)) 
elif bord == exit :print Goodbyeloop = False
- This code does not recognize invalid inputs e.g in the binary to decimal 
conversion, if I enter 10021 it will not inform me,the user, that the input is 
invalid. The same problem occurs with the decimal to binary conversion - if i 
enter 123gf I am not told to try again with a valid input  - how do I 
implement this in the code above
ThanksSaba___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Refining Code

2014-04-10 Thread Saba Usmani
My task is :A food vending machine accepts 10p, 20p, 50p and £1 coins. One or 
more coins are inserted and the current credit is calculated and displayed. A 
product is selected from those available. The system checks to see if there is 
enough credit to purchase the product chosen. If there is not enough credit the 
system displays an error message. If there is enough credit it dispenses the 
product, updates the credit available and displays the remaining credit. 
Further selections can be made if there is enough credit. The vending machine 
simulation should have five products and prices. Design, code, test and 
evaluate a program for this simulation.
I have designed the following code, but would like to know how to make it more 
efficient without making it too complex as I am a beginner or is this fine? 
Also, how do I add a loop to this so that once one product has been dispensed 
the program asks the user if they would like to continue and purchase another 
product? 

Code:
print Welcome to Snack Attack
snack1 = 0.40snack2 = 0.75snack3 = 1.20snack4 = 0.99snack5 = 0.50insert = 0
change = 0currentCredit = 0.00A = 0.10B = 0.20C = 0.50D = 1.00a = 0.10b = 0.20c 
= 0.50d = 1.00
print Menuprint Snack 1: Snickers - £0.40print Snack 2: Doritos - £0.75 
print Snack 3: J20 - £1.20print Snack 4: Oreos - £0.99print Snack 5: 
MM's - £0.50 print Exit?- how do I make this a Boolean 
expression, so the user can respond with either yes or no?
choice = input(Select your snack: )
if choice==1:   printprint You have selected Snickers, which cost £0.40 
 print Please insert £0.40  while currentCredit  snack1:  print Please 
select which of these coins to insert; A:10p,B:20p,C:50p and D:£1  
insert_coins = input(Insert coins: )  currentCredit = insert_coins + 
currentCredit  print Your current credit is £,currentCredit  else:  
change_given=currentCredit-snack1  printprint Your change is 
£,change_given  print Your Snickers have been dispensed...Enjoy!
elif choice==2: print You have selected Doritos, which cost £0.75 
print Please insert £0.75 while currentCreditsnack2:  print Please 
select which of these coins to insert; A:10p,B:20p,C:50p and D:£1  
insert_coins = input(Enter coins: )  currentCredit = insert_coins + 
currentCredit  print Your current credit is £,currentCredit else: 
 change_given=currentCredit-snack2  printprint Your change is 
£,change_given  print Your Doritos have been dispensed...Enjoy!
elif choice==3: print You have selected J20, which costs £1.20 print 
Please insert £1.20 while currentCreditsnack3:  print Please select 
which of these coins to insert; A:10p,B:20p,C:50p and D:£1  insert_coins = 
input(Enter coins: )  currentCredit = insert_coins + currentCredit  
print Your current credit is £,currentCredit else:  
change_given=currentCredit-snack3  printprint Your change is 
£,change_given  print Your J2O has been dispensed...Enjoy!
elif choice==4: print You have selcetd Oreos, which cost £0.99 print 
Please insert £0.99 while currentCreditsnack4:  print Please select 
which of these coins to insert; A:10p,B:20p,C:50p and D:£1  insert_coins = 
input(Enter coins: )  currentCredit = insert_coins + currentCredit  
print Your current credit is £,currentCredit else:  
change_given=currentCredit-snack4  printprint Your change is 
£,change_given  print Your Oreos have been dispensed...Enjoy!
elif choice==5: print You have selected MM's, which cost £0.50 print 
Please insert £0.50 while currentCreditsnack5:  print Please select 
which of these coins to insert; A:10p,B:20p,C:50p and D:£1  insert_coins = 
input(Enter coins: )  currentCredit = insert_coins + currentCredit  
print Your current credit is £,currentCredit else:  
change_given=currentCredit-snack5  printprint Your change is 
£,change_given  print Your MM's have been dispensed...Enjoy!
elif choice==Exit:print Thank You and Have a Nice Day   else:print 
 print Invalid choice
Thanks,Saba

  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor