943,832 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 544
  • Python RSS
Sep 13th, 2008
0

noob who needs help(simple)

Expand Post »
i'm pretty new to using python...i'm still in the 1st basics...
nyway i've tried to work this up...
but it didn't work :s...
it shows that there's something wrong with the "def" of the add and sub and div and mul formulas...here is the program...
tell me what i did wrong please!!!


Python Syntax (Toggle Plain Text)
  1. print"Simple Calculator"
  2. def menu():
  3. print"-------------------------------------------------"
  4. print"the option menu"
  5. print"1)add"
  6. print"2)substract"
  7. print"3)multiply"
  8. print"4)divide"
  9. print"5)exit"
  10. print"-------------------------------------------------"
  11. return input("please choose the number of the task u want =)"
  12.  
  13.  
  14. def add(a,b):
  15. print"u have chosen 2 add two numbers"
  16. print a,"+",b,"=",a+b
  17.  
  18. def sub(a,b):
  19. print"u have chosen 2 substract two numbers"
  20. print a,"-",b,"=",a-b
  21.  
  22. def mul(a,b):
  23. print"u have chosen 2 multiply two numbers"
  24. print a,"x",b,"=",a*b
  25.  
  26. def div(a,b)
  27. print"u have decided 2 divde two numbers"
  28. print a,"/",b,"=",a/b
  29.  
  30. loop=1
  31. choice=0
  32. while loop==1:
  33. choice=menu()
  34. if choice==1:
  35. print add(input("1st number u wanna add"),input("2nd one")
  36. elif choice==2:
  37. print sub(input("1st number u wanna substract"),input("2nd one")
  38. elif choice==3
  39. print mul(input("1st number u wanna multiply"),input("2nd one")
  40. elif choice==4
  41. print mul(input("1st number u wanna divide"),input("2nd one")
  42. elif choice==5
  43. loop=0
  44. else:
  45. print"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
  46. print"type in the correct number...Between 0 and 6!"
  47. print"thank u 4 using this calculator XD"
  48. print"come again soon =)"
Last edited by deviantrunner; Sep 13th, 2008 at 5:29 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
deviantrunner is offline Offline
6 posts
since Jul 2008
Sep 13th, 2008
0

Re: noob who needs help(simple)

Here, I fixed it up for you...It errored up because you had some braces and colons ( : )missing.

Python Syntax (Toggle Plain Text)
  1. print"Simple Calculator"
  2. def menu():
  3. print"-------------------------------------------------"
  4. print"the option menu"
  5. print"1)add"
  6. print"2)substract"
  7. print"3)multiply"
  8. print"4)divide"
  9. print"5)exit"
  10. print"-------------------------------------------------"
  11. return input("please choose the number of the task u want =)")
  12.  
  13.  
  14. def add(a,b):
  15. print"u have chosen 2 add two numbers"
  16. print a,"+",b,"=",a+b
  17.  
  18. def sub(a,b):
  19. print"u have chosen 2 substract two numbers"
  20. print a,"-",b,"=",a-b
  21.  
  22. def mul(a,b):
  23. print"u have chosen 2 multiply two numbers"
  24. print a,"x",b,"=",a*b
  25.  
  26. def div(a,b):
  27. print"u have decided 2 divde two numbers"
  28. print a,"/",b,"=",a/b
  29.  
  30. loop=1
  31. choice=0
  32. while loop==1:
  33. choice=menu()
  34. if choice==1:
  35. print add(input("1st number u wanna add"),input("2nd one"))
  36. elif choice==2:
  37. print sub(input("1st number u wanna substract"),input("2nd one"))
  38. elif choice==3:
  39. print mul(input("1st number u wanna multiply"),input("2nd one"))
  40. elif choice==4:
  41. print mul(input("1st number u wanna divide"),input("2nd one"))
  42. elif choice==5:
  43. loop=0
  44. else:
  45. print"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
  46. print"type in the correct number...Between 0 and 6!"
  47. print"thank u 4 using this calculator XD"
  48. print"come again soon =)"
Last edited by OutOfReach; Sep 13th, 2008 at 7:38 pm.
Reputation Points: 10
Solved Threads: 2
Newbie Poster
OutOfReach is offline Offline
19 posts
since Aug 2008
Sep 13th, 2008
0

Re: noob who needs help(simple)

ok man...i found some mistakes too =P!!!
we have defined the division by mul XD!!!so i found out about it when i was testing it XD!!!
i just thought i should post it anyway...
and i added some few stuff in the division section...
thanks a lot for your help...i can see how stupid i am XD!!!

Python Syntax (Toggle Plain Text)
  1. print"Simple Calculator"
  2. def menu():
  3. print"-------------------------------------------------"
  4. print"the option menu"
  5. print"1)add"
  6. print"2)substract"
  7. print"3)multiply"
  8. print"4)divide"
  9. print"5)exit"
  10. print"-------------------------------------------------"
  11. return input("please choose the number of the task u want =) ")
  12.  
  13.  
  14. def add(a,b):
  15. print"u have chosen 2 add two numbers"
  16. print a,"+",b,"=",a+b
  17.  
  18. def sub(a,b):
  19. print"u have chosen 2 substract two numbers"
  20. print a,"-",b,"=",a-b
  21.  
  22. def mul(a,b):
  23. print"u have chosen 2 multiply two numbers"
  24. print a,"x",b,"=",a*b
  25.  
  26. def div(a,b):
  27. print"u have decided 2 divde two numbers"
  28. print a,"/",b,"=",a/b
  29. print"the rest of the division of",a,"by",b,"is",a%b
  30.  
  31. loop=1
  32. choice=0
  33. while loop==1:
  34. choice=menu()
  35. if choice==1:
  36. print add(input("1st number u wanna add :"),input("2nd one :"))
  37. elif choice==2:
  38. print sub(input("1st number u wanna substract :"),input("2nd one :"))
  39. elif choice==3:
  40. print mul(input("1st number u wanna multiply :"),input("2nd one :"))
  41. elif choice==4:
  42. print div(input("1st number u wanna divide :"),input("2nd one :"))
  43. elif choice==5:
  44. loop=0
  45. else:
  46. print"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
  47. print"type in the correct number...Between 0 and 6!"
  48. print"thank u 4 using this calculator XD"
  49. print"come again soon =)"
Reputation Points: 10
Solved Threads: 0
Newbie Poster
deviantrunner is offline Offline
6 posts
since Jul 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: replace in time.asctime?
Next Thread in Python Forum Timeline: VolumeRendering.py





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC