0% found this document useful (0 votes)
19 views

Programming Lab1

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Programming Lab1

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CSE 212 - Computer Programming

Fall 2022

Lab #1
Data Types and Expressions

Part I - Data types and Expressions Fundamentals


1. Indicate which of the following are valid numeric literals in Python.
(a) 1024
(b) 1,024
(c) 1024.0
(d) 0.25
(e) .45
(f) 0.25+10

2. Indicate which of the following exceed the range and/or precision of floating-point values that
can be represented in Python.
(a) 1.89345348392e+301

(b) 2.0424e-320

(c) 1.62123432632322e+300

(d) 1.323232435342327896452e-140

3. Which of the following would result in either overflow or underflow for the floating-point representation
scheme mentioned in the chapter.
(a) 6.25e+240*1.24e+10

(b) 6.25e+240/1.24e+10

(c) 2.24e+240*1.45e+300

(d) 2.24e-240/1.45e+300

4. Exactly what is output by print(format(24.893952, ’.3f’))?


(a) 24.894

(b) 24.893

(c) 2.48e1

1
5. Which of the following are valid string literals in Python?
(a) "Hello"

(b) ’hello’

(c) "Hello’

(d) ’Hello there’

6. How many lines of screen output is displayed by the following?


(a) 1

(b) 2

(c) 3

(d) 4

7. Which of the following are valid assignment statements, in which only variable k has already
been assigned a value?
(a) n=k+1

(b) n=n+1

(c) n+k=10

(d) n+1=1

8. What is the value of variable num after the following assignment statements are executed?
num = 0
num = num + 1
num += 5

9. Do variables num and k reference the same memory location after the following instructions are
executed? (YES/NO)
num = 10
k = num
num = num + 1

10. Which of the following are valid identifiers in Python?


(a) errors

(b) error count

(c) error-count

2
11. Which of the following are keywords in Python?
(a) and

(b) As

(c) while

(d) until

(e) NOT

12. Which one of the following is correct for reading and storing an integer value from the user?
(a) n = int input(’Enter:’)

(b) n = int(input(’Enter:’))

Part II - Using Test Cases for Debugging a Program


The following program accepts temperature in Fahrenheit from user and converts it to Celsius.
However, there are bugs in the code. Use the following test cases to debug the program, fix the
error and validate the updated code.

Test Cases (Expected Inputs/Outputs)


32 Fahrenheit ---> 0 Celsius
100 Fahrenheit ---> 37.8 Celsius
120.5 Fahrenheit ---> 49.2 Celsius

Program
# program greettng
print ( ’ This program will convert degrees Fahrenheit to Celsius ’)
# get temperature in Fahrenheit
fahren = int ( input ( " Enter degrees Fahrenheit : " ) )
# calc degrees Celsius
celsius = ( fahren - 32 * 5/9)
# output degrees celsius
print ( fahren , ’ degrees Fahrenheit equals ’ ,
format ( celsius , ’ .1 f ’) , ’ degrees Celsius ’)

You might also like