Practice Quiz 1.1 - Intro to Variables

docx

School

Texas State University *

*We aren’t endorsed by this school

Course

5635

Subject

Mathematics

Date

Apr 3, 2024

Type

docx

Pages

4

Uploaded by JusticeHeatPuppy370

Report
Q No: 1 Correct Answer Marks: 1/1 What will be the datatype of the variable add ? a = 10 b = 5.1 add = a + b int float You Selected string long When any mathematical operation happens between int and float type variables, the output is always typecasted to float to store the decimal point values. This is known as implicit type conversion. In the given question, one variable is an integer and the other is a float. So, Python automatically converts the final output to float due to implicit type conversion. The below snippet can be used to verify the result. type(add) Q No: 2 Correct Answer Marks: 1/1 What will be the output of the following code? 5 == (3 + 2) SyntaxError: cannot assign to literal False True You Selected SyntaxError: unexpected EOF while parsing == operator compares the equality of two objects. The output of the given code will be True as the value of the left side expression (5) is equal to the right side expression (3 + 2 = 5). Q No: 3 Correct Answer Marks: 1/1
What will be the output of the following snippet? a = 3 print(a + (33)) 3 + 33 36 You Selected 3 + (33) TypeError: 'int' object is not callable In Python, the + operator can be used to add two numbers. The value of variable a is 3. a + 33 will be 36. The print() method prints the specified message to the screen. Q No: 4 Incorrect Answer Marks: 0/1 Which of the following snippets can be used to convert an float variable ' a' to integer? a = 3.5 float(a) You Selected type(a) int(a) Correct Option a = int In Python, the int() method is used to convert a string or floating-point value into an integer value. Q No: 5 Correct Answer Marks: 1/1 What will be the output of the following code snippet? a = '5a' int(a) '5a' 5a 5 invalid literal for int() with base 10: '5a' You Selected In Python, the int() method is used to convert a variable from a given datatype to an integer, provided the value stored in the variable consists of numbers only (should not include any characters). Q No: 6 Incorrect Answer Marks: 0/1
Which of the following code snippet can be used to calculate the area of a triangle with base = 10 and height = 5? Hint : Area of triangle = (base*height)/2 area = 0.5 ** 10 * 5 print("Area of triangle:", area) area = 0.5 * 10 * 5 print("Area of triangle:", area) Correct Option area = 10 * 5 print("Area of triangle:", area) area = 10 * 5 ** 0.5 print("Area of triangle:", area) You Selected The area of the triangle is calculated using the formula 0.5 * base * height. Here, base = 10 and height = 5. Hence, the area of the triangle will be 0.5 * 10 * 5. Q No: 7 Correct Answer Marks: 1/1 What will be the value of z in the following expression? v = 10 w = 25 x = 70 y = 2 z = (v + w) * (x / y) 1255.0 1225 1225.0 You Selected 1.225 The precedence of operators in python is defined as PEMDAS. P having the highest precedence and S having the lowest. P - Parentheses () E - Exponents, (**) MD - Multiplication and division (*, /, //, %) AS - Addition and Subtraction (+, -) The value of the z will be equal to (10 + 25) * (70 / 2) = 35 * 35.0 = 1225.0 So , the value of the z is calculated based on this precedence.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
So first, 10+25 and 70/2 will be solved(since, they are in parentheses) Next, both the values will be multiplied to get the final value