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 displayList

    displayList = []

# Loop through the prices in levelsList.

 # During each loop:

 # - Create a variable called priceLevelLabel consisting of the text 'Price Level:  '

followed by the price.     

# - Add priceLevelLabel and the price as two separate items to a new list (the sub-List).     

# - Append the sub-List to displayList. for price in self.levelsList:

 . . .

 # Create a variable called previousPriceLabel consisting of the text 'Previous Price: ' followed 

# by previousPrice. # Add previousPriceLabel and previousPrice as two separate items to a new list (the sub-List).  # Append the sub-List to displayList.

. . .

# replace ellipsis with applicable cod


#During the first loop of this method, previousPrice will still be 0 here,
#because it was set to currentPrice above, which also was 0 before we updated
#it above via getBitMexPrice().
#So, when we reach this point during the first loop, previousPrice will be 0
#while currentPrice would have just been updated via getBitMexPrice().
#We don't want to create the impression that the price shot up from 0 to
#currentPrice.
#ThereFore, if previousPrice == 0.0, it must be set equal to currentPrice here.

Add two polynomials


Given two polynomials A and B, write a program that adds the given two polynomials A and B.


Input


The first line contains a single integer M.


Next M lines contain two integers Pi, Ci separated with space, where Pi denotes power and Ci denotes co-efficient of Pi for polynomial A After that next line contains a single integer N. Next N lines contain two integers Pj, Cj separated with space, where Pj denotes power and Cj denotes co-efficient of Pj for polynomial B.


I am not getting proper output


given an MxN integer matrix write a program to

Find all zeros and replace them with the sum of their neighboring elements.

After replacing the zeros set all other elements the corresponding row and column with zeros (excluding the elements which where previously zeros)

Note: consider the upper ,lower,right and left elements as neighboring elements

INPUT

The first line of input is two space seperated integeres M and N

The next M lines of input contain N space seperated integers

OUTPUT

the output should be an MxN matrix

sample input 1

3 3

1 2 3

4 0 2

1 1 8

sample output 1

1 0 3

0 9 0

1 0 8

sample input 2

4 5

4 8 0 0 0

4 7 0 9 7

5 5 6 9 8

7 4 3 6 7

sample output 2

0 0 8 9 7

0 0 22 0 0

5 5 0 0 0

7 4 0 0 0




you given a list of prices where prices[i] is the price of a given stock o the i th day write a program to print the maximum profit by choosing a single day to buy a stock and choosing a different day in the future to sell that stock if these is no profit that can be achieved return 0

INPUT

the input is a single line containing space seperated integers

OUTPUT

the output should be an integer

Explanation

in the example the given prices are 7 1 5 3 6 4

buying stocks on day two having price 1 and selling them on the fifth day having price 6 would give the maximum profit which is 6 - 1

so the output should be 5.

sample input 1

7 1 5 3 6 4

sample output 1

5

sample input 2

1 11 13 21 19

sample output 2

20


given a sentence S. and a positive integer N. write a program to shift the sentence by N words to the right

INPUT

The first line pf input is a string S.

The second line of input is an integer N

OUTPUT

The output should be a single line containing the sentence by shifitng the N word to the right

EXPLANATION

in the example the sentence is python is a programming language and N is 2 shift the sentence two words to the right which means the last two words will be moved to the front.

so the output should be programming language python is a

sample input 1

Python is a programming language

2

sample output 1

programming language Python is a

sample input 2

Cats hate water

4

Sample output 2

water Cats hate


Activity #5 – Applying Functions


The output of this activity will be the same as activity #3 but instead you are

required to use a function for the following algorithm:


1. A function for getting the length of each string

2. A function to get the shortest string

3. And a function to get the longest string

Assume that each string has its own unique length.


Sample Run:


Sample Run A

Enter value of X: 3

Enter string value: a

Enter string value: ab

Enter string value: abc

a - total length is 1

ab - total length is 2

abc - total length is 3

The shortest string is 1

The longest string is 3


Sample Run B

Enter value of X: 4

Enter string value: chico

Enter string value: strawberry

Enter string value: banana

Enter string value: guyabano

chico - total length is 5

strawberry - total length is 10

banana - total length is 6

guyabano - total length is 8

The shortest string is chico

The longest string is strawberry


Activity #3 – Strings and Lengths



Create a program that will accept an integer X from the user, followed by X

number of strings. The program will then print each string followed by the length of

each string. Then the program will print the shortest and the longest string.

Assume that each string has its own unique length.


Sample Run:


Sample Run A

Enter value of X: 3

Enter string value: a

Enter string value: ab

Enter string value: abc

a - total length is 1

ab - total length is 2

abc - total length is 3

The shortest string is a

The longest string is abc


Sample Run B

Enter value of X: 4

Enter string value: chico

Enter string value: strawberry

Enter string value: banana

Enter string value: guyabano

chico - total length is 5

strawberry - total length is 10

banana - total length is 6

guyabano - total length is 8

The shortest string is chico

The longest string is strawberry


Activity #2 – Smallest and Divisibility


Create a program that will accept 3 integers from the user. Then the program

will print the smallest integer.

The program will also check if the average of the 3 numbers are divisible by 2, 3,

4 and 5. Each divisibility check will output either “The average is divisible by X” or

“The average is not divisible by X”. Each output is separated by a new line.

If the average is not divisible by 2, 3, 4 and 5 the program must output “The

average is not divisible by 2, 3, 4 and 5”.


Sample Run:


Sample Run A

Enter first value: 2

Enter second value: 5

Enter third value: 9

Smallest value is 2

The average is nor divisible by 2

The average is not divisible by 3

The average is not divisible by 4

The average is divisible by 5


Sample Run B

Enter first value: 13

Enter second value: 14

Enter third value: 13

Smallest value is 13

The average is not divisible by 2, 3, 4 and 5



Roll the Dice, where each dice has from 1 to 6 dots on each side. Two dice will be rolled. Use the random function to generate a random integer between the beginning and ending range of dot possibilities.

Your program should generate a random number. Then display a message to prompt a player to enter his/her name and then guess the number. They have 5 chances to get the number correct. If they guess the right one, display to them that they guessed the correct number in the number of guesses. If they did not guess itin 5 attempts, display a message telling them they were not successful in guessing the correct number and tell them which number it was. Allow the player to play again.


LATEST TUTORIALS
APPROVED BY CLIENTS