Write, save, and run a Python program that will do the following when run:
a = 1 * 2 + 38 / 8 You want to change the precedence of the operators so that the addition operations are executed first. How would you re-write the assignment? Write a print statement to show the output. |
||||
x = 'z' y= ['x', 'z', 'q'] Now, apparently x is a member of y. Write a print statement that should display True- what operator will you use to check if x is a member of y? |
||||
tax = 15.2 tax = tax - 2.5 |
||||
salary = 55000 vacation = 250
points = 14 Write a print statement that returns the remainder of points divided by 3 using a special operator (not the division one). Write another print statement that returns the integer part of points divided by 3 using a special operator (not the division one) |
||||
5.2967 |
||||
The hourly pay rate, number of hours worked and the amount of the tax.
|
#Sample run
5
True
12.7
--For Q.4 sample can not be provided –
2
4
5.297
234 |
Please provide code and screenshot of the results.
a) Since Python uses a set of precedence of operators we use () to make + get executed first
# using () so that "+" gets precedence
a = 1 * (2 + 38) / 8
print(a)

b) The statement "x in y" asks that if x is a member of the list y
x = 'z'
y= ['x', 'z', 'q']
print(x in y)

c) We can use" tax -= 2.5" operator instead of using "tax = tax - 2.5" . They are the same in python.
tax = 15.2
tax -= 2.5
print(tax)

d) Using == operator in python means we are checking if both sides of the operator are equal or not. It gives True or False as answer.
salary = 55000
vacation = 250
print(salary == 55000)
print(vacation == 200)

e) We can use %(mod) operator to find the remainder and // operator for the quotient
points = 14
print(points % 3)
print(points // 3)

f) We can use round(value,precision) to round off to the needed digits.
print(round(5.2967,3))

g) We use a list to take all inputs in one single line
x = [50,5,16]
print("%d "%(x[0] * x[1] - x[2]),end = '|')

Write, save, and run a Python program that will do the following when run: Let’s consider...
Using Python The variables x and y refer to numbers. Write a code segment that prompts the user for an arithmetic operator and prints the value obtained by applying that operator to x and y. Using the following information run an example in Python Idle op = input("Enter an arithmetic operator: ") if op == "+": print(x + y) elif op == "-": print(x – y) elif op == "*": print(x * y) elif op == "/":...
1. Using logical operators modify the following Python "if" statement to print ("AND operator condition worked")? x=2 y=3 if (x<=2 or y>=3) and (x>2 or y<2): print("AND operator condition worked") else: print("it doesn't work") 2. Write a program that asks user for five numbers and returns the largest of them. Do not use max function built in python.
Write a Python Program What should the values of X and Y be, so that the following code prints the 'd' found inside one of the elements of alist? alist = [['47a','47b'],'47c','47d',[['47e','47f'],'47g']] print(alist[X][Y]) Then write another print(...) statement that prints the the 'b' inside of alist, by indexing again into to its specific location within alist.
1) Translate the following equation into a Python assignment statement 2) Write Python code that prints PLUS, MINUS, O ZERO, depending on the value stored in a variable named N. 3) What is printed by: 3 - 1 while 5: while 10 Print ) Page 1 of 9 4) Write a Python while loop that reads in integers until the user enters a negative number, then prints the sum of the numbers. 1-2 of 9 4) Write a Python while...
. Use what you learned from our First Python Program to write a Python program that will carry out the following tasks. Ask user provide the following information: unit price (for example: 2.5) quantity (for example: 4) Use the following formula to calculate the revenue: revenue = unit price x quantity Print the result in the following format on the console: The revenue is $___. (for example: The revenue is $10.0.) . . Use the following formula to calculate the...
Please answer this python questions.Thank you! Question Two Write a program that calculates the amount of money a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day, and continues to double each day. The program should ask the user for the number of days. Display a table showing what the salary was for each day, and then show the total pay at the end...
Write a program that does the following in Python Code: Write a new Class called Famous_Day_Born which is a subclass of Famous_Person. Add a method to calculate the day of the week the person was born and print out all of the corresponding information using the overridden print method. Use the following code below as a starting point. ////////////////////////////////////////////////////// from datetime import datetime class Famous_Person(object): def __init__(self, last, first, month,day, year): self.last = last self.first = first self.month = month...
5. (12 points) Consider the following code fragment (part of a program): int index 3; String dna "ACTGTCA char nucleotide dna.charAt (index); Matching: For each term below, write the letter of the ONE choice that best matches the term. Data types Variables Literals Object Method ーParameter nde x a. coumt, nucleotide, and d b. 3 and "ACTGTCA c. int, char, and String d. index e. charAt f. dna na 6. (10 points) a. Wrte a statement that assigns true to...
Java Write a Simple Program This question is about following the directions below. Failure to do so, results in lost credit. Write the definition of a method that takes in an integer number, and returns true if the number is prime, otherwise, returns false. A prime number is only divisible by itself and 1. Do not write the code for main here. The code must follow these steps in the order shown: 1. Name the method isPrime, and make it...
Hi, Looking for some help with this Python question as follows: Consider the following Python program: def fun(x, y): return x * y a = fun(2, 3) b = fun("2", 3) print(a, b) What does the function evaluate to? What would happen if we replace the last statement print a, b with print a + b? Thanks for any help. John