2.1.6.10 LAB: Operators and expressions

LAB 

Estimated time

20 minutes

Level of difficulty

Intermediate

Objectives

  • becoming familiar with the concept of numbers, operators and arithmetic operations in Python;
  • understanding the precedence and associativity of Python operators, as well as the proper use of parentheses.

Scenario

Your task is to complete the code in order to evaluate the following expression:
 
The result should be assigned to y. Be careful - watch the operators and keep their priorities in mind. Don't hesitate to use as many parentheses as you need.
You can use additional variables to shorten the expression (but it's not necessary). Test your code carefully.

Test Data

Sample input: 1
Expected output:
y = 0.6000000000000001
Sample input: 10
Expected output:
y = 0.09901951266867294
Sample input: 100
Expected output:
y = 0.009999000199950014
Sample input: -5
Expected output:
y = -0.19258202567760344


x = float(input("Enter value for x: "))
# put your code here
print("y =", y)
  • Console 

Comments

  1. hola, yo lo realice de la siguiente forma
    x = float(input("Ingresa el valor para x: "))

    y=(((x*x)+(1*1))/(1*x))
    y1=((((x*y)+(1*1))/(1*y)))
    y2=(((x*y1)+(1*1))/(1*y1))
    y3=(1/y2)

    print("y =",y3)

    si lo quieres mas corto solo es remplazar las y saludos

    ReplyDelete

Post a Comment

Popular Posts