Question

In: Computer Science

Control Flow 1. What is the difference between 10 / 3 and 10 // 3? 2....

Control Flow

1. What is the difference between 10 / 3 and 10 // 3?

2. What is the result of 10 ** 3?

3. Given (x = 1), what will be the value of after we run (x += 2)?

4. How can we round a number?

5. What is the result of float(1)?

6. What is the result of bool(“False”)?

7. What is the result of 10 == “10”?

8. What is the result of “bag” > “apple”?

9. What is the result of not(True or False)?

10. Under what circumstances does the expression 18 <= age < 65 evaluate to True?

Primitive Types

1. What is a variable?

2. What are the primitive built-in types in Python?

3. When should we use “”” (tripe quotes) to define strings?

4. Assuming (name = “John Smith”), what does name[1] return?

5. What about name[-2]?

6. What about name[1:-1]?

7. How to get the length of name?

8. What are the escape sequences in Python?

9. What is the result of f“{2+2}+{10%3}”?

10. What does name.strip() do?

11. How can we check to see if name contains “John”?

12. What are the 3 types of numbers in Python?



Solutions

Expert Solution

Solution:

1.

/ is used for floating point division , it will produce floating point value as result

// is used for integer division , it will produce the quotientas result

Therefore,

10 / 3 = 3.3333333333333335

10 // 3 = 3

2.

** is the exponentiation operator in python which returns the given power to its exponent.

10 ** 3 = 1000

3.

x += 2 is interpreted as x = x + 2

Therefore,

x = 1 + 2

x = 3

4.

To round a number in python we use the function round(number , digits) where number the value that we need to round and digits specifies upto how many digis we need to round the number.

round(9.456,2) --> 9.46

round(9.456,1) --> 9.5

5.

float() function returns the floating point representation of its argument.

float(1) returns 1.0

6.

Since "False" is a string and when passed as an argument to the bool function it is interpreted as True and the bool returns True

bool("False") returns True

7.

Since one argument is string and another argument is integer the result would be always False.

10 == "10" returns False

8.

When the strings bag and apples are placed in the alphabetical order apples comes first and then bag. bag is greater than apples in this order.

Therefore,

"bag" > "apples" returns True

9.

or operator returns True if either of its operands is True and not operator returns complement of its operands value.

Now ,

(True or False) returns True

not ( True ) returns False

10.

The expression 18 <= age < 65 evaluates to true if the value of age is in between 18 to 65 including 18 and excluding 65.

Therefore , the values of age which evaluates the expression to True are

  18,19,20,--------------,63,64

I hope this would help........................:-))


Related Solutions

1. What is the difference between arguments, opinions and descriptions? 2. What is the difference between...
1. What is the difference between arguments, opinions and descriptions? 2. What is the difference between arguments and explanations, and what is the primary purpose of each?
Chapter 10 1) What is the difference between a normal profit and an economic profit? 2)...
Chapter 10 1) What is the difference between a normal profit and an economic profit? 2) What is an incentive system? 3) What is the principal-agent problem as applied to corporations? What are the three major ways that corporations can cope with the principal-agent problem? 4) What are the four types of markets? Give a brief description of each type. 5) Describe the conditions under which the monopoly exists. Give two examples. 6) What is the Herfindahl-Hirschman Index and what...
1)what is accounting 2) What is difference between financial accounting and cost accounting 3) What are...
1)what is accounting 2) What is difference between financial accounting and cost accounting 3) What are the parts of financial statement 4) what is the difference between income statement and balance sheet 5 ) sales 100,000 cost of goods sold 50,000 operating exp 10,000 ( compute net income for the company 6) sales return 10,000 sales discount 25,000 net sales 200,000 ( compute the gross sales ) 7 ) beginning inventory 10,000 total cost of purchases 200,000 ending inventory 50,000...
1-What is the difference between Discontinued Operations and Extraordinary Items? 2-What is the difference between Deferred...
1-What is the difference between Discontinued Operations and Extraordinary Items? 2-What is the difference between Deferred Charges and Unearned Revenue? 3-Which of the following is not a stock market ratio? A. Earnings per share B. Book value C. Working capital investment D. Dividend Yield
What is a nested case control study? What is the difference between a nested case control...
What is a nested case control study? What is the difference between a nested case control study and a case control study?
What is the difference between control limits and specification limits?
What is the difference between control limits and specification limits?
What is the difference between quality management and quality control?
What is the difference between quality management and quality control?
1. What is a merchandise company? 2. Describe the difference between wholesalers and retailers? 3.Describe the...
1. What is a merchandise company? 2. Describe the difference between wholesalers and retailers? 3.Describe the difference(s) between the periodic and perpetual inventory accounting system? 4.What is gross profit percentage? How is it used as an indicator of profitability?
2-3 sentences at least more is appreciated. 1. What is the difference between a homosexual orientation...
2-3 sentences at least more is appreciated. 1. What is the difference between a homosexual orientation and a heterosexual orientation? Define Bisexuality. 2. Explain how sexual orientation was viewed in the past and compare to how it is viewed now. Consider cultural and religious factors in your answers. You can choose one or two cultural views to explain your answers . 3. Describe the relationship between heredity, genetics make-up and predisposition and sexual orientation, specifically among twins. Do you think...
What is the difference between Cash Flow and Profit? A. Cash Flow is the cash collected...
What is the difference between Cash Flow and Profit? A. Cash Flow is the cash collected and paid in a company’s core operations. Profit tracks the revenue from customers and the costs of doing business. B. Profit tracks the cash collected and paid in a company’s core operations. That’s why it’s called the bottom line. Cash Flow is the change in cash and cash equivalents from one year to the next. C. Cash flow is found on the balance sheet...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT