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

NEW Copy _ Python Test

Uploaded by

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

NEW Copy _ Python Test

Uploaded by

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

1

Python Test

Student

Institution

Course

Instructor

Date
2

PART 1

Question A

i. Code/Output

ii. Explanation

The recorded syntax error means that the Python interpreter reached the end of the print

statement while searching for the second double quotes that are expected to close the string

literal (Downey, 2012). The program ran into an error since it expected to get a closing quote to

execute successfully. The program broke the rule of enclosing a string literal with either double quotes

or single quotes at the start and end of the string.

Question B

i. Code/Output

ii. Explanation

A single asterisk (*) is used to perform multiple operations. A double asterisk (**) is used to perform an

exponentiation operation in mathematical calculations (Huang, 2022). The single quote (*) can also be

used to multiply numerical elements in a list of values and duplicate strings.

Question C

i. Code/Output
3

ii. Explanation

In the first case, leading zeros are not allowed for integer values. Therefore, 09 is not interpreted as 9 in

Python.

Question D

i. Code/Output

ii. Explanation

type(“67”) returns the type as a string since the number is enclosed with quotes ( Huang, 2022). Every

value enclosed using single or double quotes is interpreted as a string in Python. type(67) is then

interpreted as an integer since it is not enclosed with quotes (Downey, 2012).

PART 2

Question A

i. Code/Output

myage = 22
print(myage*2)

ii. Explanation

The operation (*) multiplied the age value (24) by 2 to get 48. It shows the use of simple math

operations.
4

Question B

i. Code/Output

city = "Kansas City"


country = "USA"
continent = "North America"
print("I Live in: " +city + ", " + country + " in " + continent)

The values are strings (enclosed using quotes). The output is concatenated using the “+,” which

combines multiple strings into a single output. This shows the concept of string manipulation.

Question C

i. Code/Output

exam_start_date = "2024-11-25"
exam_end_date = "2024-12-10"

ii. Explanation

The code is another example of representing dates as strings.

Question D

i. Code/Output

temperature = 3.0 #Degree Celsius


print("The current temperature is", temperature, "°C.")

ii. Explanation
5

The temperature value is stored as a float number (decimal point) since the temperature can take a

decimal value. This example shows the use of the floating number data type.
6

References

Downey, A. (2012). Think python (2nd Ed, pp 1-8). O'Reilly Media.

Huang, X. (2022). Introduction to Programming in Python. In Land Carbon Cycle Modeling (pp. 343-351).

CRC Press.

You might also like