Thread: Sale

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    5
    Rep Power
    0

    Sale


    A local shop is having a promotion. If you spend over 10 you will get a 1 voucher to spend next time you come in the store. If you spend over 20 you get a 3 voucher.
    Write a programme to tell the sales assistant which voucher to give the customer.
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,851
    Rep Power
    481
    Try to write the program without < and without > operators. I think I can. Hint: use the decimal module.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    5
    Rep Power
    0
    I haven't learned 'decimal module' so could you please show me how to do so? as i can't seem to find the correct thing towards this question over internet.
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,851
    Rep Power
    481
    I will not show you how to use the decimal module because the solution I have in mind is brain dead.

    You must show some work and ask a specific question for assistance at this web site. Even if all you can manage is a piddly flow chart.

    Comments on this post

    • codergeek42 agrees : Well said...it's hard to help those who won't help themselves.
    [code]Code tags[/code] are essential for python code and Makefiles!
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    5
    Rep Power
    0
    Code:
    print 'Welcome to the Mega Sale'
    spend = input('How much have you spend today in the mega sale?')
    
    if spend >10:
        print 'You earned a 1 voucher'
    
    if spend > 20:
        print 'You earned a 3 voucher'
    
    if spend < 10:
        print 'You earned no voucher'
    This is how far i got to, i encounter this problem where i type '25' say, i get the 3 voucher and 1 voucher which is not what i want.
  10. #6
  11. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,851
    Rep Power
    481

    if .. elif .. elif .. else


    if elif executes the first block of code that meets a condition.

    Code:
    if spend > 20:
        print 'You earned a 3 voucher'
    
    elif spend >10:
        print 'You earned a 1 voucher'
    
    else:
        print 'You earned no voucher'
    [code]Code tags[/code] are essential for python code and Makefiles!
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    5
    Rep Power
    0
    Thanks, I'll take note of this.

IMN logo majestic logo threadwatch logo seochat tools logo