Showing posts with label robot framework. Show all posts
Showing posts with label robot framework. Show all posts

Sunday, October 29, 2023

CHAPTER 2 LEARN VARIABLES

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”.

INTRODUCTION TO ROBOT'S PYTHON

LEARN PYTHON THROUGH SERIES OF ROBOT'S ACTIVITIES

 Artificial Intelligence (AI) is the futuristic technology that promises to be amazing. In the current environment, everyone needs to learn about machine learning and artificial intelligence. In the realm of artificial intelligence (AI), a computer is comparable to a well-manicured paddy field. Therefore, managing a farming estate does not require extensive knowledge of the art of land cultivation. With the right knowledge on what to plant and how to care for it, he can become the greatest farmer. Similar to this, even if a person is not a skilled programmer, they may still use AI and ML algorithms to create computer applications provided they know what kind of software to create and are enthusiastic about computers. This could be the digital era's future vision.

Learn Python to grow yourself further in AI and ML technologies and, you will become an AI and ML enthusiast soon after you read this blog.       

Source codes will be forwarded to you based on your request.  

The Jupiter Notebook was used to create all of the codes (Python programs) in this book. Jupiter Python can be easily installed on your computer/laptop using the link attached here.

1. https://www.python.org/downloads/

2. https://jupyter.org/install

           In these programs, the input is denoted by the letter [In], and the output is indicated next to the word [Out]. For getting output, users have to hit the ‘Enter’ button. The statements starting with the ‘#’ symbol are only for demonstration purposes and do not execute during the run command.

 

All lines must be properly indented in the program. For every Chapter, more than one event/ situation/ incident is elaborated on using examples of real-world problems. In each chapter of this blog, an example event or chaotic situation is given and explained. In each case/example, we need to tell a robot how to help us through the Python language.

CHAPTER 7 LEARN CLASS IN PYTHON

 LEARN PYTHON THROUGH SERIES OF ROBOT'S ACTIVITIES 

A user-defined class serves as a template or prototype from which objects can be built. Classes offer a way to group functionality and data. A new class produces a new type of object, enabling the creation of new instances of that type. Each instance of a class may have characteristics connected to it to preserve its state. Class instances may also contain methods for changing their state that is defined by their class. Sana is working as a professor in a college. Sana had ordered the robot named Tana, to monitor students of her college to improve the educational methods, that is to say,

how well the students have learned the content of each subject by conducting a series of tests or exams on each student.

 

Sana gives the marks obtained by the student to the robot, Tana, and similarly gives the completed question paper to the robot. At present questions are asked from 5 subjects of 20 marks each from each subject.

 

The function of this task is to assess whether the content of all 5 subjects is well understood by the students based on how much each student has scored in these 5 subjects.

To do this, the robot needs information about how each student wrote the answers to the related questions in the 5 subjects,

and the robot has to calculate the percentage of the student's score in each subject and convert it into a percentage and submit it to the professor.

The job of Tana is to get the given data, and marks of the students and, at the same time take the marks of the students in each subject separately and convert it into percentages and get the learning percentage of each subject.

Program 1:

[In]Class Student():

    def __init__(self, name, roll, gen):

        self.name=name

        self.roll=roll

        self.gen=gen

    def show(self):

        print("The student details are: Name :",  self.name, ", Roll No: ", self.roll, ", Gender: ", self.gen)

#This comment prints the student details.

[In]class Student():

    def __init__(self, name, roll, gen):

        self.name=name

        self.roll=roll

        self.gen=gen

    def show(self):

        print("The student details are: Name :",  self.name, ", Roll No: ", self.roll, ", Gender: ", self.gen)

stu1=Student('raj',123,"male")

stu1.show()

[Out]The student details are: Name : raj , Roll No:  123 , Gender:  male

[In]class Science(Student):

    def __init__(self, name, roll, gen):

        super().__init__(name, roll, gen)

        self.marks1=0

        self.marks2=0

    def test1marks(self, score1):

        self.score1=score1

        self.marks1 = self.marks1+ self.score1

        [In]print("The test 1 marks updated", self.marks1)

    def test2marks(self, score2):

        self.score2=score2

        self.marks2 = self.marks2+ self.score2

        [In]print("The test 2 marks updated", self.marks2)

[In]stu1=Science('raji',123,'female')

[In]stu1.test1marks(100)

[Out]The test 1 marks updated 100

[In]stu1.test2marks(10)

[Out]The test 2 marks updated 10

Program 2:

In the second example, A shopkeeper has to calculate the total price for 3 items bought by a customer. The 3 items are moong, oil, and vegetables. The program is very simple to make a class program that contains different functions such as _init_, and price. The output of this program executes the price function with the prices of all the groceries. This is available in the Ingredients class. The values of prices are passed to the Ingredients class.

[In] class Ingredients:

    def __init__(self, m,o,c):

        self.m=m

        self.o=o

        self.c=c

    def price(self):

        tot= self.m + self.o + self.c

        print("The total price is Rs.", tot)

p=Incredients(45,34,4)

p.price()

​[Out] The total price is Rs.  83

The next program explains the functions of a class with more than one function.

[In]class Ingredients:

def unitprice(self,moong,oil,veg):

        self.moong=moong self.oil = oil

        self.veg = veg

        print("The unitprice of moong is Rs",self.moong)

        print("The unitprice of oil is Rs",self.oil)

        print("The unitprice of veg is Rs",self.veg)

def quantity(self,moonquan=float,oilquan=float, vegquan=float):

        self.moonquan=moonquan

        self.oilquan = oilquan

        self.vegquan = vegquan

        print("The quantity of moong is ",self.moonquan,"kg")

        print("The quantity of oil is ",self.oilquan,"kg")

        print("The quantity of veg is ",self.vegquan,"kg")

def price(self,m=float,o=float,v=float,tot=float):

        m=self.moong*self.moonquan

        o=self.oil*self.oilquan

        v=self.veg*self.vegquan

        self.m =m

        self.o =o

        self.v =v

        tot= self.m+self.o+self.v

        print("The total price of the groceries is Rs. ",tot)

p=Incredients()

p.unitprice(1,4,4)

p.quantity(0.5,1,4)

p.price()

[Out] The unitprice of moong is Rs 1

The unitprice of oil is Rs 4

The unitprice of veg is Rs 4

The quantity of moong is  0.5 kg

The quantity of oil is  1 kg

The quantity of veg is  4 kg

The total price of the groceries is Rs.  20.5

 

 

 

CHAPTER 6 LEARN FUNCTIONS

 LEARN PYTHON THROUGH SERIES OF ROBOT'S ACTIVITIES 

To repeat a particular action, reducing the generation of codes each time, and reusing codes generated once, is called operations in computer language. Activities are an event in which an action is initiated and completed within a specified time frame and this event is completed through specified procedures. For example, activities such as going to the store, returning from the store, writing an essay, and cooking can be considered. A shopping activity consists of various small tasks. Decide what to buy, decide how much of each item to buy, decide how much money you need to have, learn about giving money and buying the balance, get it all into a bucket, and take it home again.

This example shows how a robot can complete household chores promptly as an operation. Similarly, other operations may have several smaller tasks and conditions attached to them, such that when a robot is given a command, the commands are executed one after the other, and an operation is completed.

 

Ironing, Washing, Playing, Walking, Brushing, Gardening, Reading, Shopping, Cleaning the home, Cooking, Cleaning the kitchen, and singing.

Ironing function

    [In]def iron():

       dress_type=input("get the type of dress   ")

        dress_typelist=dress_type.split()

        print(dress_typelist)

        for x in dress_typelist:

            if x == "cotton":

           print("Maintain temperature at 60 deg")

                print("iron is over")

            elif x== "velvet":

            print("Maintain temperature at 30 deg")

                    print("iron is over")

            else:

                print("select correct cloth")

    [In]iron()

    [Out]get the type of dress   velvet

    ['velvet']

    [Out]Maintain temperature at 30 deg

    [Out] iron is over

    #Running the function again.

    [In]iron()

    [In]get the type of dress   cotton

    ['cotton']

    [Out]Maintain temperature at 60 deg

    [Out]iron is over

        #Running the function again.

 [In]iron()

    [In]get the type of dress   polyester

    ['polyester']

    [In]select correct cloth

Washing function

    #washing job

    def wash():

no_ofcloth=int(input("enter the no of dresses  "))

        while no_ofcloth<6:

            if no_ofcloth<3:

                waterlow=int(input("get the low water level   "))

                print("motor on. finish wash")

            else:

                waterhigh=int(input("get the high water level   "))

                print("motor on. finish wash")

            break

        else:

            print("get the low no of dresses")

    #Running the function.

    [In]wash()

    [In]enter the no of dresses  2

    [In]get the low water level   4

    [In]motor on. finish wash

    #Running the function again.

    [In]wash()

    [In]enter the no of dresses  5

    [In]get the high water level   5

    [In]motor on. finish wash

    #Running the function again.

    [In]wash()

    [In]enter the no of dresses  7

    [In]get the low no of dresses

    Autonomous Car Driving

         The following decisions were made before the car has to be moved from one place to another place. There were 4 sensors located beside the wheels of the car. If any sensor input is 0, no obstacle is assumed, False condition. If any sensor detects an obstacle, then the sensor input will be 1, True.

[In] def drive1():

         fls=str(input("front left sensor input   "))

         frs=str(input("front right sensor input   "))

    def forwbreak():

           print("stop the forward vehicle, apply brake")

    def forwacce():

         print("forward acceleration on")

    def forright():

        print("steer right")

    def forleft():

        print("steer left")

    def revbreak():

        print("stop the reversed vehicle, apply brake")

    def revacce():

        print("steer 4")

    if fls == "1" and frs == "1":

            forwbreak()

    elif frs=="1" and fls=="0":

            forleft()

    elif fls=="1" and frs=="0":

            forright()

    elif fls == "0" and frs == "0":

            forwacce()

    return

#When the function runs, based on the decision the car will be driven.

[In]drive1()

    front left sensor input   1

    front right sensor input   0

    steer right

[In] drive1()

    front left sensor input   1

    front right sensor input   1

    stop the forward vehicle, apply the brake

[In] drive1()

    front left sensor input   0

    front right sensor input   1

    steer left

[In]drive1()

    front left sensor input   0

    front right sensor input   0

    forward acceleration on

   #This example shown below is the function drive(), that is using 2 sensors. These 2 sensors will get the input from the user. As per user input, the decisions will be made. 

def drive():

        get_sendata=input(" the sensor data    ")

        sendata = get_sendata.split(",")

        print(sendata)

        a=type(sendata)

        b=len(sendata)

        print(a)

        print(b)

        a1=sendata[0]

        b2=sendata[1]

        print(a1)

        print(b2)

        if a1=="0" and b2=="1":

            print("turn left")

        elif a1=="1" and b2=="0":

            print("turn right")

        elif a1=="0" and b2=="0":

            print("accelerate")

        elif a1=="1" and b2=="1":

            print("stop the car")

        return

    When program runs

[In]drive()

    [Out] the sensor data    0,0

    ['0', '0']

    <class 'list'>

    [Out] 2

    [Out] 0

    [Out] 0

    Accelerate

[In]drive()

 

 

[Out] the sensor data    1,1

    ['1', '1']

    <class 'list'>

    [Out] 2

    [Out] 1

    [Out] 1

    [Out] stop the car

Practice Problem

If 4 sensors are fitted in a car, then the following program will be used.

[In]def drive():

         get_sendata=input(" the sensor data    ")

         sendata = get_sendata.split(",")

         print(sendata)

    #a1=front left , b2= front right, c3=rear right,     

        d4=rear left sensors.

        a=type(sendata)

    b=len(sendata)

    print(a)

    print(b)

    a1=sendata[0]

    b2=sendata[1]

    c3=sendata[2]

    d4=sendata[3]

    print(a1)

    print(b2)

    print(c3)

    print(d4)

    if ((a1=="0") and (c3=="0") and (d4=="0") and (b2=="1")):

        print("turn left and accelerate")

    elif ((b2=="1") and (c3=="1") and (d4=="1") and (a1=="0")):

        print("turn right and accelerate")

    elif a1=="0" and b2=="0":

        print("accelerate")

    elif c3=="1" and d4=="1":

        print("stop reverse the car")

    elif ((a1=="1") and (b2=="1") and (c3=="1") and (d4=="0")):

        print("reverse the car towards rear right")

    elif ((a1=="1") and (b2=="1") and (d4=="1") and (c3=="0")):

        print("reverse the car towards rear left")

    return

[In] drive()

[Out] the sensor data    0,0,0,1

['0', '0', '0', '1'] # list created.

<class 'list'>

4 # length of list elements, 4 elements.

0   # sensor data1

0   # sensor data2

0   # sensor data3

1   # sensor data4

accelerate

 

CHAPTER 5 LOOP STRUCTURES

 

LEARN PYTHON THROUGH SERIES OF ROBOT'S ACTIVITIES 

In this chapter, the loop structures are explained with suitable examples. This example shows how Johnny, who is a robot, and what tasks he has to complete each day according to the requirement.

[In]list_duty = ['cleaning', 'cooking', 'arranging','ironing', 'washing', 'singing','playing','breakfast','lunch','dinner']

set_time=["morning","noon","evening", "night"]

for w in list_duty:

    a=input("get the time   ")

    if a == "noon" :

# if and only if, the chosen time is noon, the following duties are to be called. 

        a1=input("call the the followings  ")

        print("the duties are  ", a1)

        continue

    else:

        print("get the time again")

# The next program will select the time and duties simultaneously. 

[In]set_time=["morning","noon","evening", "night"]

[In]list_duty = ['cleaning', 'cooking', 'arranging','ironing', 'washing', 'singing', 'playing','breakfast','lunch','dinner']

[In]for w in list_duty:

    a=input("get the time   ")

    if a in set_time:

        a1=input("call the the followings  ")

        if a1 in list_duty:

           print("the duties are  ", a1)

           print("the duties are over")

        else:

            print("get the correct duty and time")

            continue

    else:

        print("get the correct time again")

[Out]get the time   noon

[Out]call the following _________

[Out]get the correct duty and time

Workout Problem 1:

[In]set_time=["morning","noon","evening", "night"]

[In]list_duty = ['cleaning','wash']

for w in list_duty:

    a=input("get the time   ")

    if a in set_time:

        a1=input("call the the followings  ")

        if a1 in list_duty:

           print("the duties are  ", a1)

           print("the duties are over")

        else:

            print("get the correct duty and time")

            continue

    else:

        print("get the correct time again")

[Out]get the time   noon

[Out]call the followings  lunch

# Here only 'cleaning', and 'washing' duties are provided.

[Out]get the correct duty and time

[Out]get the time   noon

[Out]call the following wash

[Out]the duties are   wash

[Out]the duties are over

Example 2:

#per day duties.

set_time=["morning","noon","evening", "night"]

list_duty = []

duties=input("assign duties ")

list_duty = duties.split()

# split command helps to retrieve individual items in the list.

print(list_duty)

for w in list_duty:

    a=input("get the time   ")

    if a in set_time:

        a1=input("call the the followings  ")

        if a1 in list_duty:

           print("the duties are  ", a1)

           print("the duties are over")

        else:

            print("get the correct duty and time")

            continue

    else:

        print("get the correct time again")

[Out]assign duties _____________

[In] cook, wash, study, pray

['cook,', 'wash,', 'study,', 'pray']

[Out]get the time   ___________

[In]noon

[Out]call the following ______

[In] cook, study

[Out]the duties are   cook, study

[Out]the duties are over

[Out]get the time   ___________

[In]morn

[Out]call the following ______

[In] study

[Out]the duties are  study

[Out]the duties are over

 

CHAPTER 18 EXPLORING THERMODYNAMICS WITH PYTHON: UNDERSTANDING CARNOT'S THEOREM AND MORE

  Python is a versatile programming language that can be used to simulate and analyze various physical phenomena, including thermal physics ...