Python Answers

Questions answered by Experts: 5 288

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search


Create your own Python code examples that demonstrate each of the following. Do not copy examples from the book or any other source. Try to be creative with your examples to demonstrate that you invented them yourself.


Example 1: Define a function that takes an argument. Call the function. Identify what code is the argument and what code is the parameter.


Example 2: Call your function from Example 1 three times with different kinds of arguments: a value, a variable, and an expression. Identify which kind of argument is which. 


Example 3: Create a function with a local variable. Show what happens when you try to use that variable outside the function. Explain the results.



Hollow Right Triangle

Given an integer number 

N as input. Write a program to print the hollow right-angled triangular pattern of N lines as shown below.

Note: There is a space after each asterisk (*) character.

Input

The first line of input is an integer 

N.

Explanation

In the given example the hollow right angled triangle of side 

4. Therefore, the output should be

* * * * 
  *   *
    * *
      *




Diamond Crystal

Given an integer value 

N, write a program to print a diamond pattern of 2*N rows as shown below.

Input

The first line of input is an integer 

N.

Explanation

In the given example, the number of rows in the diamond is 

2*5 = 10.

So, the output should be




    /\
   /  \
  /    \
 /      \
/        \
\        /
 \      /
  \    /
   \  /
    \/

Write a program to print all the Armstrong numbers in the given range A to B(including A and B). An N-digit number is an Armstrong number if the number equals the sum of the Nth power of its digits.




Prompts the user for a password. Check if the password is valid where a valid password has the following criteria. It must be at least 5 characters long. It must start with either a c or a 5. It must contain at least one special character from &,@,# and %


input an integer n and then draws a right angle isosceles triangle with asterisks of height n


You are given a positive integer N .

Your task is to print a palindromic triangle of size N .

For example, a palindromic triangle of size  is 5:

1
121
12321
1234321
123454321

You can't take more than two lines. The first line (a for-statement) is already written for you.

You have to complete the code using exactly one print statement.



Apply your knowledge of the .add() operation to help your friend Rupal.


Rupal has a huge collection of country stamps. She decided to count the total number of distinct country stamps in her collection. She asked for your help. You pick the stamps one by one from a stack of N  country stamps.


Find the total number of distinct country stamps.

The first line contains an integer N , the total number of country stamps.

The next N  lines contains the name of the country where the stamp is from.

Sample Input

7
UK
China
USA
France
New Zealand
UK
France 

Sample Output

5

Explanation

UK and France repeat twice. Hence, the total number of distinct country stamps is  5(five).


Minimum cost of adding all the numbers in the array

You are given a function f(x)=x^2. You are also given k lists. The ith  list consists of  ni elements.

You have to pick one element from each list so that the value from the equation below is maximized:

s-fx1+fx2................fxk %m


% denotes the element picked from the  list . Find the maximized value  obtained.

 denotes the modulo operator.

Note that you need to take exactly one element from each list, not necessarily the largest element. You add the squares of the chosen elements and perform the modulo operation. The maximum value that you can obtain, will be the answer to the problem.


LATEST TUTORIALS
APPROVED BY CLIENTS