Jump to content


Photo

Chpater 6, Transaction Pyware

python transaction-file chpater-6

  • Please log in to reply
3 replies to this topic

#1 TheFuture

TheFuture

    New Member

  • Members
  • Pip
  • 3 posts

Posted 17 August 2015 - 08:08 AM

Hi!

I've a qusetion about the program in chpater 6, page 184.

 In last line where else condition is lying:

    else:
        credit_card = input("Credit card number: ")
        save_transaction(prices[choice - 1], credit_card,items[choice-1])

What happens when save_transaction function is run? Please answer by focusing on given argument :

(prices[choice - 1], credit_card,items[choice-1])

 

Thanks friend!



#2 #TM#

#TM#

    Active Member

  • Members
  • PipPipPip
  • 91 posts
  • Gender:Not Telling

Posted 18 August 2015 - 10:39 PM

Hi!

I've a qusetion about the program in chpater 6, page 184.

 In last line where else condition is lying:

    else:
        credit_card = input("Credit card number: ")
        save_transaction(prices[choice - 1], credit_card,items[choice-1])

What happens when save_transaction function is run? Please answer by focusing on given argument :

(prices[choice - 1], credit_card,items[choice-1])

 

Thanks friend!

Hi TheFuture, is that hard to understand ?  which part of it?

 

Anyway, if the customer don't choose quit which is in the if condition the else clause will run.

That means the customer wants to buy something.

 

In the else part , the save_transaction() will run; with the choice, price of choice and credit card number the customer entered.

 

Well, choice-1 is used here because python start indexing list/string/tuple etc at 0 (zero). Here is a link if you want to know why?! (Mr. Guido van Rossum written about it himself). But it will be difficult to understand if you don't know a little bit of computer science, algorithms, data structures etc. You may not be able to comprehend and may be like "What the hell is he talking about??!!" wacko.png

 

Guido van Rossum on why python start index at 0 (zero)

 

Anyway, let's get back to the program. You give choice to customer as 1,2,3... by using option=1 in the while loop, that is starting from 1. Obviously, in day to day life customers don't expect to encounter something like choice no. 0. tongue.png

 

So, now the function is called and the input customer provided are given as arguments to the save_transaction(price,credit_card,description).

where input to price argument is prices[choice-1]

input to credit_card argument is the credit_card number entered.

and input to description argument is the name of thing customer purchased,i.e., items[choice-1]

Now, the save_transaction() will write these above details to a file.

smile.png cool.png


Edited by #TM#, 18 August 2015 - 11:07 PM.


#3 TheFuture

TheFuture

    New Member

  • Members
  • Pip
  • 3 posts

Posted 19 August 2015 - 12:21 AM

Thank you so much for the great comprehensive talks. I'm new to programming and sometimes get to as such problems.

My main misconception was about the "items[choice-1]", but with your valuable guidance I just ran out the trap!

have a nice time brother! smile.png


Edited by TheFuture, 19 August 2015 - 12:28 AM.


#4 #TM#

#TM#

    Active Member

  • Members
  • PipPipPip
  • 91 posts
  • Gender:Not Telling

Posted 19 August 2015 - 11:24 PM

you are welcome Bro...! smile.png






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users