Programming Lab1
Programming Lab1
Fall 2022
Lab #1
Data Types and Expressions
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
(b) 24.893
(c) 2.48e1
1
5. Which of the following are valid string literals in Python?
(a) "Hello"
(b) ’hello’
(c) "Hello’
(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
(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:’))
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 ’)