Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js

Objectives

  • becoming familiar with the inputting and outputting the data in Python
  • evaluating simple expressions

Scenario

Your task is to complete the code in order to evaluate the results of four basic arithmetic operations. 

The results have to be printed to the console. 

You may not be able to protect the code from a user who wants to divide by zero. That's okay, don't worry about it for now. 

Test your code - does it produce the results you expect ?

We won't show you any test data - that would be too simple. 

What I wrote:

vara = float(input("Input variable a number here: " ))# input a float value for variable a here
varb = float(input("Input variable b number here: "))# input a float value for variable b here


print("Variable a plus Variable b is", vara + varb)# output the result of addition here
print("Variable a minus Variable b is", vara - varb)# output the result of subtraction here
print("Variable a multiplied by Variable b is", vara * varb)# output the result of multiplication here
print("Variable a divided by Variable b is", vara / varb)# output the result of division here

print("\nThat's all, folks!")

LAB

Objectives

  • becoming familiar with the concepts 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.009999000199950014

Sample input: -5

Expected output:

 

y = -0.19258202567760344

Code I wrote:

x = float(input("Enter value for x: "))

y=1/(x+(1/(x+(1/(x+(1/x))))))# Write your code here.

print("y =", y)