BLOG - Page 5 of 7 - GlobalSQA

9
Jul

Get Name from Email Address

Question:

Write python program to print the user name of a given email address.

Program:

Explanation:

Email addresses are in the “[email protected]” format.

Both user names and company names are composed of letters only.

Use \w to match letters.

Output:

Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

Assertion Error

Question:

Raise Assertion error when trying to verify that every number in the list [2,4,6,8,1] is even.

Use “assert expression” to make assertion

Program:

Explanation:

The Assert Statement: When python encounters an assert statement, Python evaluates the accompanying expression, which is hopefully true. If the expression is false, Python raises an AssertionError exception. 

Output:

Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

Square a List Without Loops

Question:

Write a program to print the squares of the numbers in a list [1,2,3,4,5] without using any iterative function.,

Program:

Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

zip() and izip()

Question:

Write a python program to show the difference in zip() and izip() function

Explanation:

zip() is a standard library which combines elements into tuples.

The izip() function works the same way, but it returns an iterable object for an increase in performance by reducing memory usage.

We can directly print the list returned by zip() but, we cannot directly print an iterable object. We need to use next(iterable_object) or a loop.

Lists are stored in memory so they have the advantage of faster access times over Iterable Object whose contents are not entirely stored in memory but fetched on-demand instead.

Program:

Output:
Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

Solve Quadratic Equation

Question:

Write a python program to solve a quadratic equation

Program:

Explanation:

Quadratic Equations is a equation having form like ax2 + bx+c =0. Roots are of the form  x = (-b +/-√(b2 – 4ac))/2a. To know more about Quadratic Equations, click here.

Output:

Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

Convert Fahrenheit to Celsius

Question:

Write a python program to convert Fahrenheit to Celsius

Program:

Explanation:

To convert the temperature from Fahrenheit to Celsius, deduct 32, then multiply by 5, then divide by 9.

Output:

Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

Convert KPH to MPH

Question:

Write a python program to convert KPH to MPH

Program:

Explanation:

To convert KPH to MPH, just multiply by 0.6214

Output:

Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

Remove Punctuation From String

Question:

Write a python program to remove punctuations from a string

Program:

Explanation:

There are fourteen punctuation marks commonly used in English grammar. They are the period, question mark, exclamation point, comma, semicolon, colon, dash, hyphen, parentheses, brackets, braces, apostrophe, quotation marks, and ellipsis.

Output:

Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

Addition of Two Matrices

Question:

Write a python program to add two matrices

Program:

Explanation:

If A and B are the two matrices for addition, both of them must be of the same order.

If i and j are the index positions, then result[i][j] = A[i][j] + B[i][j]

Output:

Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

HCF Python Program

Question:

Write a python program to find the HCF

Program:

Explanation:

The Highest Common Factor (H.C.F) of two (or more) numbers is the largest number that divides evenly into both numbers. In other words the H.C.F is the largest of all the common factors. The common factors or of 12 and 18 are 1, 2, 3 and 6. The largest common factor is 6, so this is the H.C.F. of 12 and 18.

Output:

Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

Factorial Using Recursion

Question :
Write a program to find the factorial of a number using recursive function

Program:

Explanation:
Factorial of a number is the product of all natural numbers till that number. It does not exist for negative numbers.

For example, the factorial of 4 would be 1*2*3*4=24

A recursive function is a function that calls on itself. In the above recursive function, the function calls on itself with n-1 as argument till n becomes 1 and 1 is returned. Each time the function is called, product the corresponding n and the factorial of n-1 is returned. Hence, factorial is found.

Output:
1.

2.
3.
Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

Factors of a Number

Question:

Write a python program to find the factors of a given number

Program:

Explanation:

The factors of a number are any numbers that divide into it exactly. This includes 1 and the number itself. For example, the factors of 6 are 1, 2, 3 and 6. The factors of 8 are 1, 2, 4 and 8. For larger numbers it is sometimes easier to ‘pair’ the factors by writing them as multiplications.

Output:

Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

Largest of Three Numbers

Question

Write a python program to find the largest of three numbers

Hint: Use if and elif

Program:

 

Explanation:

Three numbers are accepted from the user ‘nos1′,’nos2′,’nos3’.

First ‘nos1’ is checked.If it is greater than both ‘nos2’ and ‘nos3’, then ‘large’ is allocated wth the value of ‘nos1’

Otherwise ‘nos2’ is checked. If it is greater than both ‘nos1’ and ‘nos2’,then ‘large’ is allocated with the value of ‘nos2’

Otherwise ‘large’ is allocated with ‘nos3’

Output:

Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

LCM of Two Numbers

Question:

Program to find the LCM of two numbers

Program:

Explanation:

A common multiple is a number that is a multiple of two or more numbers. The common multiples of 3 and 4 are 0, 12, 24, …. The least common multiple(LCM) of two numbers is the smallest number (not zero) that is a multiple of both.

Output:

Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

The Palindrome Program

Question 

Write a python program to check whether given string is palindrome or not without using any inbuilt function to reverse the string

Program:

Explanation:

A palindrome is a string which is same read forward or backwards. Dad is a palindrome while Python is not.

In the program, we first accept the string to ‘string’. Since capital letters and small letters are perceived differently because of difference in ASCII codes, we convert the string to all lower for uniformity using inbuilt function ‘x.lower()’ where x is the string

In the above program, we have used the slice operator to reverese the string.The slice operator[n:m:p] returns the part of the string from nth to the (m-1)th character Setting p to -1 returns the reverse order of the slice of string you asked for. Since here we want the whole string, we use the shorthand [::-1]

Compare both the string and it’s reversal. If they are equal, then it’s a palindrome, otherwise not.

Output:

1.

2.
Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

Python Armstrong program

Question 2

Write a Python program to check whether a given number is armstrong or not.

Program:

Explanation:

Armstrong number is the number whose sum of cube of individual digits is equal to the number itself.

Output:

1.

2.
Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

The Fibonacci Sequence

Question:

Program to print the Fibonacci Number

Program:

Explanation:

A Fibonacci sequence is the integer sequence of 0, 1, 1, 2, 3, 5, 8….

The first two terms are 0 and 1. All other terms are obtained by adding the preceding two terms

Ex: 5th term is sum of 4th and 3rd term;3=2+1

Output:

1.

2.
3.
Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

Multiplication Table

Question;

Write a program to print the multiplication table of a number

Program:

Output:
Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
1
Jul

Print Python Built-In Function Documentation

Question:
Write a program to print some Python built-in functions documents, such as abs(), int(), raw_input(). The built-in document method is __doc__.

Program:

Explanation:

Python documentation strings (or docstrings) provide a convenient way of associating  documentation  with  Python  modules, functions, classes, and methods. An object’s docsting is defined by including a string constant as the first statement in the object’s definition

Output:

Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
19
Jun

How to Debug Code with Android Studio

How to Debug Code with Android Studio



Being Tester we are used to reporting bugs and we know that developer debug the code to find out the line of code causing the bug. But now you are the one coding the test cases and you are responsible for solving any bug in your testing framework.


Android Studio provides some shortcut keys for debugging. In this post, we will use our HelloWord Espresso test Case Example and We will run our test Case In Debug mode and we will debug our code line by line.


It is always good practice to use Debug Mode for root tracing the bug as it allows you to run your code line by line by setting a debug point. Debug point is the nothing but marking the line of code from which you wish to start debugging. This speeds up your work and efficiency.

  • In your Android Studio project copy the below test case.
  •  
  • Now we will set a debug pointer. Suppose we are confident that our test of code is working fine except our test and we wish to debug the test case then we will place our debug pointer at the first line inside our test case. For this click on the left side space in front of the selected line and the pointer is set as shown the below screenshot(Red Dot represents the debug point).

  • Now we need to run our test case in Debug mode. Select the class name -> right click -> Debug as “MyActivityTest”. Make sure that the Android device is attached to your computer with USB debugging ON.

    Debug

  • As soon as your code runs till the debug point. You will see a debug console on your bottom left side and the code stops running at the debug point. Now the control is in your hands to run the code line by line.

  • The button highlighted in below screenshot allows you to run the rest of the code. When you click on it rest of the code runs automatically.

  • The button highlighted in below screenshot allows you to run the code step by step. Each time you click the button the line highlighted in the code gets executed.

  • You can also observe what is getting stored in your variables by opening checking variable window –

This will help you debug your test cases and write a efficient and bug free code.