❌

Normal view

There are new articles available, click to refresh the page.
Before yesterdayNaresh Kamalesh

Python Day 11

14 June 2024 at 09:49

Same car game but inform the user when the car is already running and already stopped.

command = ""
started = False
stopped = False
while True:
command = input("> ").lower()
if command == "start":
if started:
print("Car is already started !")
else:
started = True
print("Car Started....")
elif command == "stop":
if stopped:
print("Car is already stopped!")
else:
stopped = True
print("Car Stopped")
elif command == "help":
print("""Start - to start the car
Stop - to stop the car
quit - to quit""")
elif command == "quit":
break
else:
print("Sorry, i don't understand")

Python Day 10

4 June 2024 at 12:35

Car Game

start – to start the car
stop – to stop the car
quit – to exit

if any other commands are given – I don’t understand that…
if typed car started -> Car started…Ready to go!
if typed car stopped-> Car stopped.
if type quit -> the program terminates

command = ""
while True:
command = input("> ").lower()
if command == "start":
print("Car Started....")
elif command == "stop":
print("Car Stopped")
elif command == "help":
print("""Start - to start the car
Stop - to stop the car
quit - to quit""")
elif command == "quit":
break
else:
print("Sorry, i don't understand")

Python Day 9

31 May 2024 at 09:01

Weight Converter

Ask for weight and then convert the weight into kilo or pounds

Solution->

weight = int(input('Weight: '))
unit = input ('(L)bs or (K)g: ')
if unit.upper() == 'L':
converted = weight * 0.45
print(f"You are {converted} kilos")
else:
converted = weight / 0.45
print(f"You are {converted} Pounds")

-> Weight: 160
-> (L)bs or (K)g: l
-> You are 72.0 kilos

While Loops

i=1
while i <=5:
print(i)
i=i+1
print(β€œDone”)

i=1
while i <=5:
print(β€˜*’ * i)
i=i+1
print(β€œDone”)

->

*
**
***
****
******
Done

Guess the secret number game:

secret_number = 9
guess_count = 0
guess_limit = 3
# while i ❀
# i is guess_count and 3 is guess_limit
while guess_count < guess_limit:
    guess = int(input('Guess: '))
    guess_count +=1
    if guess == secret_number:
        print("You Won!")
        break
else:
    print("Sorry you failed")

Python Day 8

30 May 2024 at 06:54

Logical Operators

OR

Check if an applicant is eligible for loan, if he either has a high income or a good credit.

has_high_income = True
has_good_credit = False

if has_high_income or has_good_credit:
print('Eligible for Loan')

else: print('Not eligible for loan')

Result-> Eligible for Loan

Logical Operators

NOT

Check if an applicant is eligible for loan, if he has a good credit and doesn't have a criminal record, then he is eligible for loan

has_good_credit = True
has_criminal_record = False

if has_good_credit and not has_criminal_record :
print('Eligible for Loan')
else:
print('Not eligible for loan')

Result-> Eligible for Loan

Comparison Operators

Temperature check:

temperature = 33

if temperature > 30:
print("It's a Hot Day")
else:
print("It's not a Hot Day")

If name is less than 4 characters long,
name must be at least 4 characters long
If name is more than 10 characters long,
name can be a maximum of 10 characters long
otherwise
name looks good

name = "ruby"
print (len(name))

if len(name) < 4:
print("Name must be at least 4 characters long")
else:
if len(name) > 10:
print("name can be a maximum of 10 characters long")
else:
print("name looks good")

-> 4
-> name looks good


Python Day 6

26 March 2024 at 06:47

If Statements

If its Hot
-> Its a hot day
Drink plenty of water
If its Cold
-> Its a Cold day
Wear warm clothes
otherwise
-> its a lovely day

is_hot = True
is_cold = False

if is_hot:
print("Its a Hot Day")
print("Drink plenty of water")
elif is_cold:
print("Its a Cold Day")
print("Wear warm clothes")
else:
print("Its a Lovely day")
print("Enjoy your day")

Excersise:

Price of a house is $1M
if buyer has good credit
they need to put down 10% down payment
otherwise
they need to put 20% down payment
print the down payment

1)
has_good_credit = False
cost= 1000000
GC = cost / 10
BC = cost / 5

if has_good_credit:
print("You need to put a 10% down payment")
print(GC)
else:
print("You need to put a 20% down payment")
print(BC)
2)
has_good_credit = False
cost= 1000000
GC = cost / 10
BC = cost / 5
if has_good_credit:
print(f"You need to put a down payment of ${GC}")
else:
print(f"You need to put a down payment of ${BC}")

Python Day 5

25 March 2024 at 12:03

x = 10
x = x – 3
print(x)

# Augmented assignment operator

x = 10
x -= 3
print(x)

-> 7

Operator Precedence

x = 10 + 3 * 2
print(x)
-> 16

# Order is as follows(as per Math)
Exponentiation (power off), Multiplication, Division, addition, Subtraction
but, parenthesis always takes priority

x = 10 + 3 * 2 ** 2
print(x)
-> 22

x = (10 + 3) * 2 ** 2
print(x)
-> 52

Excersise:
x = (2+3)*10-3
2+3 ->5
5*10 ->50
50-3 -> 47

Math Functions:

x =2.9

Round->
x = 2.9
print(round(x))
-> 3

Absolute->
x = 2.9
print(abs(-x))
-> 2.9

abs will always give a positive number

import math
to access all math functions do a math.

print(math.ceil(2.9))
->3

Python Day 4

18 March 2024 at 11:37

#calclutae the number of characters in a string

course = "Python for Beginners"
print (course)
print (len(course))
-> Python for Beginners
-> 20

To convert to upper case use
.upper()
To convert to lower case use
.lower()

print(course.upper())
-> PYTHON FOR BEGINNERS
print(course.lower())
-> python for beginners
this does not modify the original string

To find character in a string(case sensitive), result will be the index of the character. (not available-> -1)
course.find('')

print(course.find('s'))
->19
print(course.find('P'))
->0
print(course.find('Q'))
->-1
print(course.find('for'))
->7 #(the word for starts at index 7)


#replace
.replace()

print(course.replace('for', 'is for'))
->Python is for Beginners
print(course.replace('P', 'is K'))
->is Kython for Beginners

to find is character/word is in the string
course 'Python for Beginners'
print('Python'in course)
->True
print('python'in course)
->False #(case sensitive 'P')

#Arithmetic Operations
Add:
print(10 + 8)
Sub:
print(10 - 8)
Multiply
print(10 * 8)
Divide (Float)
print(10 / 8)
->1.25
Divide (Integer)
print(10 // 8)
->1
Modulus (reminder of the division)
print(10 % 8)
->2
Exponent(power of)
print(10 ** 8)
->100000000

x = 10
x = x + 3
print(x)

# Augmented assignment operator

x = 10
x += 3
print(x)



Python Day 3

13 March 2024 at 13:13

Formatted string

#John [Smith] is a painter - > expected results
first_name = 'John'
last_name = 'Smith'
message = first_name + ' ['+ last_name + '] is a painter'
print(message)
# now using formatted string, the formatted string always prefixed with a 'f'
msg = f'{first_name} [{last_name}] is a painter'
print(msg)
-> John [Smith] is a painter


Python Day 2

11 March 2024 at 13:12

Modify a String

course = 'python for beginners'
print (course)

modify to
course = 'python's course for beginners'

error received : SyntaxError: unterminated string literal
solution: need to change single quotes to double

course = "python's course for beginners"
print (course)
-> if having multiple lines string use tripe quotes.

Index in a string
course = 'python for beginners'
print(course[0])
-> p

negative index to find out index from end

course = "python's course for beginners"
print(course[-1])
-> s

finding index of a set of charecters
course = "python's course for beginners"
print (course[0:3])
-> pyt

if you don't supply end value then all the characters are listed.

course = "python's course for beginners"
print (course[0:])
-> python's course for beginners

similarly

course = "python's course for beginners"
print (course[:6])
-> python

# Exercise: Remove first and last character in a string
name = 'Jennifer'
print(name[1:-1])
-> ennife





Python Day 1

5 March 2024 at 13:08


print("Naresh Kamalesh")

String
print("*" * 10)
# anything within "" is a string, so in this case * is being multiplied 10 times

Variable (placeholders to store data value)
price = 10
print (price)
#note, price has to be without "", else it will print the word price and not the value of price, ie 10.

# Exercise: Check in a Patient named John Smith, age 20, and is a new patient.

Patient_name = ("John Smith")
Patient_age = (20)
Is_new_patient = True

Output > John Smith 20 True

input('What is your name? ')
#type the input in the terminal and the output will be
Output > What is your name? Naresh

name = input('What is your name? ')
print ('Hi ' + name)
#type the input in the terminal and the output will be
Hi Naresh

# Exercise: Ask two questions, Person's name and favorite colour. Then print a message like "Shiva likes blue"

name = input('What is your name? ')
fav_colour = input('What is your Favorite colour? ')
print (name +' likes '+ fav_colour)

#type the input in the terminal and the output will be

What is your name? Shiva
What is your Favorite colour? Blue
Shiva likes Blue

# Converting a string to integer
# To find age

birth_year = input('Birth Year: ')
age = 2024 - birth_year

#in terminal
Birth Year: 1981
Traceback (most recent call last):
File "C:\Users\Pragathi Solutions\PycharmProjects\Hello\demo.py", line 177, in <module>
age = 2024 - birth_year
~~~~~^~~~~~~~~~~~
TypeError: unsupported operand type(s) for -: 'int' and 'str'

#This is because age is a number/integer and birth_year is a string, so python cannot substract an integer from a string.
# solution > int(birth_year), pass the birth year variable to the 'int' function function
birth_year = input('Birth Year: ')
age = 2024 - int(birth_year)
print(age)

#in terminal
Birth Year: 2001
23

#Type
birth_year = input('Birth Year: ')
print(type(birth_year))
age = 2024 - int(birth_year)
print(type(age))
print(age)

#in terminal
Birth Year: 2001
<class 'str'>
<class 'int'>
23

# Exercise: Ask a user their weight in pounds, convert it to kilograms and print on the terminal.

weight = input ("Enter your weight in Pounds ")
weight_new = int(weight) / 2.205
print(weight_new)

#in terminal
Enter your weight in Pounds 123
55.78231292517007

Framework Design

27 February 2024 at 07:04

Data

-> TBD

Driver

-> TBD

Lib

-> TBD

Pageobject

-> Have all the page object listed here

SWAG-LABS-PAGE-LOGIN-AND-GLOABAL-NAV

SWAG-LABS-Sanity-Test-Page-Object

SWAG-LABS-Common_methods

Results

Run_Manager

Folder -> SWAG-LABS-Sanity-Test

-> Excel SWAG-LABS-Sanity-Test

Testcase Name;Description;URL;Browser;TestCase ID;Auto mail;Auto Defect;Planned to Execute ?
SWAG-LABS-Sanity-Test;SWAG-LABS-Sanity-Test;marketplace_url;chrome;SWAG-LABS-Sanity-Test-01;TRUE;TRUE;TRUE

Scripts

Folder- > SWAG-LABS-Sanity-Test

Testdata

-> Excel files(for each component, here Sanity test is a component) with the below details

File Name -> SWAG-LABS-Sanity-Test_data

-> SWAG-LABS-Sanity-Test.rb

TC_ID;username;password;qq
SWAG-LABS-Sanity-Test-01;standard_user;secret_sauce;qq

Installing Ruby, Watir, Selenium

27 February 2024 at 04:37

Install Ruby

Install Watir

Install Selinium

irb

require β€˜rubygems’

require β€˜Watir’

br=Watir::Browser.new :chrome

br.goto(β€œhttps://www.saucedemo.comβ€œ)

br.text_field(id:’user-name’).set”standard_user”

br.text_field(id:’password’).set”secret_sauce”

br.button(:id=>”login-button”).click

br.div(:class=>”bm-burger-button”).click

br.div(:class=>”bm-menu”).link(:id=>”inventory_sidebar_link”).click

br.div(:class=>”bm-menu”).link(:id=>”about_sidebar_link”).click

br.back

❌
❌