LEARN PYTHON THROUGH SERIES OF ROBOT'S ACTIVITIES
Jony is a robot. Her boss lady has given Jony a job today. Jony's boss lady orders him to go to the
store and buy some things. "Jony, you must go to the shop. Here are the
items you need to buy: two coconuts, one kilogram of apple, three liters of
ghee, and half a liter of coconut oil. You should buy this half liter of
coconut oil only if you have money. I will give you 500 rupees“, Shaking her
head yes, she scanned the paper around her eyes, compared the items on the list
with the list of items she heard with her ears, and decided in two seconds that
it was ok and started to go to the store.
# Jony’s boss lady said a few
words and it can be the string data type. It can be represented in Python as
below with a variable name with (“ …… ”) symbol.
[In]bossword =
("Jony, you must go to the shop. Here are the items you need to buy: two
coconuts, one kilogram of apple, three liters of ghee, and half a liter of
coconut oil. You should buy this half liter of coconut oil only if you have
money. I will give you 500 rupees")
#Jony wants to count the
letters in the statement given by his boss lady.
#Jony uses the following
comment.
[In]len(bossword)
[Out]254
#Jony wants to store the numbers in a different location, whereas, in the previous comment the whole statement was stored in a single variable named ‘bossword’.
[In]coconut_nos=2
[In]apple_kgs=1
[In]ghee_litres=3
[In]coco_oil_litres=0.5
[In]money_rs= 500
The code can also be written as below.
[In]bossword = ("Jony, you must go to the shop. Here are the items you need to buy: "+str(coconut_nos)+" coconuts, "+str(apple_kgs)+" kilogram of apple, "+str(ghee_litres)+" liters of ghee and "+str(coco_oil_litres)+" of coconut oil. You should buy this half liter of coconut oil only if you have money. I will give you "+str(money_rs)+" rupees")
[In]bossword
[Out] 'Jony, you must go to the shop. Here are the items you need to buy: 2
coconuts, 1 kilogram of apple, 3 liters of ghee, and 0.5 of coconut oil. You
should buy this half liter of coconut oil only if you have money. I will give
you 500 rupees'
She carefully separated what kind of data she was given, namely integers 2 coconuts: the number 2 is an integer, a kilogram of apples is one, three liters of oil is an integer, and finally 1.5 liters of coconut oil is a decimal number (float). Now, she kept her master's commands as a string in her memory and also took a list of ingredients, coconut: two, apple: one kg, more ghee: one liter, coconut oil: 1.5, and operator.
# check the datatypes of
each value
#list the values and index
all
After tabulating the
products and asking the shopkeeper for a price list, calculate the total price
of 500 rupees and give it to the shopkeeper, if there is any leftover, buy one
and a half liters of coconut oil.
#Jony is now
preparing to go to the shop. She listed the items to buy first, then count the
items.
[In]list_items=["coconut","ghee","coconut
oil","apple"]
[In]total_items=len(list_items)
[In]total_items
[Out]4
The calendar was included
in the table and the price of the other items that the shopkeeper paid would
correspond to the prices of the other items.
#Jony
includes the calendar and the shop id using the dictionary datatype to verify
the transaction details later.
[In]shoping_details={"shopid":234,
"date":"04:02:2022"}
[In]shoping_details
{'shopid': 234, 'date': '04:02:2022'}
shoping_details["date"]
'04:02:2022'
Jony patiently asked the
shopkeeper to tell her the price of the items. Further, She said, "If there is a balance, I will
take the items away, I will give you the price list". Shopkeeper said ok, she calmed down, and
counted the items, the number of items on the list and the number of items he
was keeping was correct, ok, She waited for the price list, the price list
said 475, so there are only 25 rupees left, for 25 rupees, She can buy a
coconut.
#shopkeeper
told Jony the price items.
[In]price_items={"2
coconuts":30,"1 kg apple":250,"1 liter
ghee":55,"0.5 liter coconut oil":75}
#jony gets
the total price.
[In]total_price=sum(price_items.values())
[In]total_price
[Out]410
The shopkeeper asked how much coconut oil Jony wants. Jony wants 1.5 liters. If it is less than 25 rupees, give her the rest. If not, She explained that only 25 rupees is enough.
#now jony calculates
the balance price.
[In]total_price=410
[In]money_rs=500
[In]bal_price=money_rs-total_price
[In]bal_price
[Out]90
Robots can use different
types of programming languages. Jony uses Python language. Now she explains
how Johnny fulfilled his duty perfectly. "I first recorded in my memory
the words spoken by my master.
I made a separate note of the numbers marked in them and put in a table the objects connected with them. Before that, I saved in written form the long statement made by her boss lady.
Now when I visit a store I
save the store ID in my memory. Also, I have added the store name along with
the store ID. I will also include the location of the store.
Now what I need to do is
to know if there are any approaches in this shop I go to that shop, and now the
shopkeeper asked Jony, "Jony you have already loaned Rs 10 on a specified
date last week and now you have to pay it". Jony couldn't make up his mind
because boss lady didn't give her any information about this, after a while she
said no you give me 1.5 liters for the remaining amount, I will give this 10
rupees when I come back next time. For my mistress did not tell me these particulars,
although I have noted them in my memory. After getting the approval for it, I
will give it when I come next time”.
No comments:
Post a Comment