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

MODULE 10:

Go ahead and try to write the code in this module. If you accomplished it and run without an issue, add

another feature of our calculator. Try to add the following: 

  • MODULUS DIVISION

SAMPLE OUTPUT:

what's the first number?:15

+

-

*

/

%

e

pick an operation:%

what's the number?: 4

15.0% 4.0=3.0

type 'y' to continue calculating with 3.0, or type 'n' to start a new calculation:


  • EXPONENT

SAMPLE OUTPUT:

what's the first number?:5

+

-

*

/

%

e

pick an operation:e

what's the number?: 3

5.0% 3.0= 125.0

type 'y' to continue calculating with 125.0, or type 'n' to start a new calculation:




You are making a 4 player dice game. Each of the four players starts the game by rolling one 5 sided dice and one 8 sided dice. The total is recorded.

  • If the player rolls an even number, they become an "EVEN" player.
  • If they roll an odd, then the player becomes an "ODD" player


  • If the Player is an "EVEN" Player, then he wins the total if that total is a 3 or 9 or 11
  • If the Player is an "ODD" Player, then he wins the total if that total is a 5 or 7 or 12



Player Object

Attributes:

  • The name
  • The total points
  • The type of the player "EVEN" or "ODD"

Constructor:

  • Accept name of the player as the parameter
  • Set the points accumulated to 0

Behaviours:

  • Set Type Function:
  • Accept a string either "EVEN" or "ODD"
  • Set the player type attribute


  • Roll Function:
  • Accept two dice objects as parameters
  • Return the sum of two dice rolls


  • Set Points Function:
  • Accept a value representing the sum of two dice
  • Return the number of points the player should earn based on that sum

Please provide the needed code of the question below, please avoid using 'def'.


Using the discussed methods, Convert the following Infix Expression to its equivalent Postfix and Prefix


Expression


1. a^b/c+d-(e/t-g+(h+i-j)^k+l-m/n)


2. a/b c d+e+f)/g^h-ij/(k'l'm^n)


Help me with this. Thank you! Create a python code with this problem, without using 'def'


Create a program that will convert an infix expression entered by the user to its equivalent prefix and postfix expression.


Sample Output:

Enter an Infix Expression: a+b^(c^d- e/(f+g)+(h^i)^j)

Postfix Expression: abcd^efg+/- hi^j^+^+

Prefix Expression: +a^b+- ^cd/e+fg^^hij


Secret Message - 1

Given a string, write a program to mirror the characters of the string in alphabetical order to create a secret message.


Note: Mirroring the characters in alphabetical order replacing the letters 'a' with 'z', 'b' with 'y', ... , 'z' with 'a'. You need to mirror both uppercase and lowercase characters. You can ignore mirroring for all characters that are not letters.


a b c d e f g h i j k l m n o p q r s t u v w x y z

z y x w v u t s r q p o n m l k j i h g f e d c b a


Explanation

Input

For example, if the given input is "python", "p" should replaced with "k", similarly "y" with "b", "t" with "g", "h" with "s", "o" with "l", "n" with "m". So the output should be "kbgslm".


Sample Input 1

python


Sample Output 1

kbgslm


Sample Input 2

Foundations


Sample Output 2

Ulfmwzgrlmh




  1. Give an example of defining and calling functions.
  2. Create a function that prints the sum of two numbers and divides the sum by 5. The result should be float.

Can you please provide the code, with this question below. Please don't use def in doing the code, please do a simple one. Thankyou!


Using the discussed methods, Convert the following Infix Expression to its equivalent Postfix and Prefix Expression

  1. a^b/c+d-(e/f-g+(h+i-j)^k+l-m/n)
  2. a/b^c^d+(e+f)/g^h-i*j/(k*l*m^n)

Can you please rewrite the code, without using def.

opening_list = ["[", "{", "("]

closing_list = ["]", "}", ")"]

def parenthesis(str):

stack = []

 for j in str:

if j in opening_list:

stack.append(j)

 elif j in closing_list:

 position = closing_list.index(j)

  if ((len(stack) > 0) and

=  (opening_list[position] == stack[len(stack) - 1])):

 stack.pop()

else:

return "Unbalance"

if len(stack) == 0:

return "Balance"

else:

 return "Unbalance"

string = input("Enter the set of parenthesis: \n")  

print(string, "-", parenthesis(string))   


Can you please rewrite the code below. Please, thank you. This is the question:

Create a program that will convert an infix expression entered by the user to its equivalent prefix and postfix expression Sample Output: Enter an Infix Expression: a+b^(c^d- e/(f+g)+(h^i)^j) <input> Postfix Expression: abcd^efg+/- hi^j^+^+ <compute> Prefix Expression: +a^b+- ^cd/e+fg^^hij <compute>

prefix = input("Enter an Infix Expression: ')

infixstack = []

 x = len(prefix)

for i in range (x) :

index = (x-1)-i

if prefix[index == " + " or prefix[index] == "-" or prefix[index] == "-" or prefix[index] == "*':

op1 = infixstack.pop()

op2 = infixstack.pop()

Infix = "(" op1 + " " + prefix[index] + " " + op2 + ")"

infixstack.append(Infix)

 else:

ifixstack.append(prefix[index])

print(*infixstack)


Can you please rewrite this program without using class and def, The question is given below. i didn't input all the code because it's too long. i need a simple one.


Create a program that will convert an infix expression entered by the user to its equivalent prefix and postfix expression Sample Output: Enter an Infix Expression: a+b^(c^d- e/(f+g)+(h^i)^j) <input> Postfix Expression: abcd^efg+/- hi^j^+^+ <compute> Prefix Expression: +a^b+- ^cd/e+fg^^hij


class infix_to_prefix:

  precedence={'^':5,'*':4,'/':4,'+':3,'-':3,'(':2,')':1}

  def __init__(self):

    self.items=[]

    self.size=-1

  def push(self,value):

    self.items.append(value)

    self.size+=1

  def pop(self):

    if self.isempty():

      return 0

    else:


LATEST TUTORIALS
APPROVED BY CLIENTS