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...
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...
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...
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...
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
Please answer all the questions thank you 1) (Classes – 20 Points) Consider the following class declaration for Time to complete the questions below: DO NOT WRITE MORE THAN ASKED FOR. class Time private: int hours; int minutes; public: Time(); Time (int , int m = 0); void addMin(int m); void addHr(int h); void reset(int h = 0, int m = 0); Time operator+(const Time & t) const; Time operator-(const Time & t) const; Time operator*(double n) const; friend Time...
using this code to complete. it python 3.#Display Program Purpose print("The program will show how much money you will make working a job that gives a inputted percentage increase each year") #Declaration and Initialization of Variables userName = "" #Variable to hold user's name currentYear = 0 #Variable to hold current year input birthYear = 0 #Variable to hold birth year input startingSalary = 0 #Variable to hold starting salary input retirementAge = 0 #Variable to hold retirement age input...
Q1 SUMMER2020- nts python language Example Write a program to read an integer r then print a triangle with r number of rows using .asterisks Result Input 5 Hint: Use end= parameter of the print function to not add a newline to the end of the string * * * * * * * * * * * * 9 - عام python language Course Information o Course Material Assignments o example input Lab Exercises Quizzes Result 7.0 ACUTE 7.0...