Solved–Sheet 02: Variables, Expressions, and Statements –Solution

$25.00 $14.00

State whether true or false:- 1) The best way to write a program is to immediately type in some code and then debug it until it works. 2) An algorithm can be written without using a programming language. 3) Programs no longer require modification after they are written and debugged. 4) Python identifiers must start…

You’ll get a: . zip file solution

 

 
Categorys:

Description

5/5 – (2 votes)

State whether true or false:-

1) The best way to write a program is to immediately type in some code and then debug it until it works.

2) An algorithm can be written without using a programming language.
3) Programs no longer require modification after they are written and debugged.
4) Python identifiers must start with a letter or underscore.
5) Keywords make good variable names.
6) Expressions are built from literals, variables, and operators.
7) In Python, x = x + 1 is a legal statement.

8) Python does not allow the input of multiple values with a single statement.
9) A counted loop is designed to iterate a specific number of times.

10) In a flowchart, diamonds are used to show statement sequences, and rectangles are used for decision points.

11) Information that is stored and manipulated by computers is called data.

12) Since floating-point numbers are extremely accurate, they should generally be used instead of integers.

13) Operations like addition and subtraction are defined in the math library.
14) The number of possible arrangements of n items is equal to n!

15) The sqrt function computes the squirt of a number.
16) The float data type is identical to the mathematical concept of a real number.
17) Computers represent numbers using base-2 (binary) representations.

18) A hardware float can represent a larger range of values than a hardware integer.

19) Type conversion functions such as float are a safe alternative to eval() for getting a number as user input.

Multiple Choice

1. Which of the following is not a step in the software development process?
a) specification
b) testing/Debugging
c) fee setting
d) maintenance
2. What is the correct Python formula for converting Celsius to Fahrenheit?
a) F = (9/5)*C + 32
b) F = 5/9*C- 32
c) F=B2-4AC
d) F = (212-32)/100

3. The process of describing exactly what a computer program will do to solve a problem is called

a) design
b) implementation
c) programming
d) specification
4. Which of the following is not a legal Python identifier?
a) Spam
b) spAm
c) 2spam

d) spam 4U
5. Which of the following are not used in expressions?
a) Variables
b) Statements
c) Operators
d) literals
6. Fragments of code that produce or calculate new data values are called
a) identifiers
b) expressions

c) productive clauses
d) assignment statements
7. Which of the following is not a built-in Python data type?
a) int
b) float
c) rational
d) string
8. Which of the following is not a built-in operation?
a) +

b) %
c) abs ()
d) sqrt ()
9. In order to use functions in the math library, a program must include
a) a comment
b) a loop
c) an operator
d) an import statement

10. The value of 4! is
a) 9
b) 24
c) 41
d) 120
11. The most appropriate data type for storing the value of pi is
a) Int
b) Float
c) Irrational

d) string

12. In a mixed-type expression involving ints and floats, Python will convert

a) floats to ints
b) ints to strings
c) both floats and ints to strings
d) ints to floats
13. Which of the following is not a Python type-conversion function?
a) float
b) round
c) int d) abs

Discussion:

1- Show the result of evaluating each expression. Be sure that the value is in the proper form to indicate its type (int or float). If the expression is illegal, explain why.

2- Translate each of the following mathematical expressions into an equivalent Python expression. You may assume that the math library has been imported (via import math).

Programming Exercises:
a) Write a program that converts temperatures from Fahrenheit to Celsius.

b) Write a program that converts distances measured in kilometers to miles. One kilometer is approximately 0.62 miles.

c) Write a program to perform a unit conversion of your own choosing. Make sure that the program prints an introduction that explains what it does.

d) Write a program to find the roots of the equation ax2+bx+c=0. You read the input parameters a, b, and c from the user emphasizing that the program finds only real roots.

e) Let a, b, c be the lengths of the sides of a triangle. The area is given by:

= √ ( − )( − )( − ), ℎ ℎ ℎ . Write a program to read the triangle sides and compute its area.