For age 14+
Onile Python Compiler
y = 1 # Assign 1 to variable y
radius = 1.0 # Assign 1.0 to variable radius
x = 5* (3/ 2) + 3* 2 # Assign the value of the expression to x
x = y + 1 # Assign the addition of y and 1 to x
area = radius * radius * 3.14159 # Compute area
i = j = k = 1 # which is equivalent to k = 1; then j = k; and then i = j
#variables should be declared first and then used
count = count + 1
>>> NameError: count is not defined
count = 1 # count is created
count = count + 1 # Now increment count
x = 1
y = 2
print("x = ", x, "y = ", y)
temp = x # Save x in a temp variable
x = y # Assign the value in y to x
y = temp # Assign the value in temp to y
print("x = ", x, "y = ", y)
number1, number2, number3 = eval(input("Enter three numbers separated by commas: "))
average = (number1 + number2 + number3) / 3
# Display result
print("The average of", number1, number2, number3, "is", average)
Numeric Data Types and Operators
The /, //, and **Operators
The / operator performs a float division that results in a floating number.
--- 4 / 2
--- 2 / 4
The // operator performs an integer division; the result is an integer, and any fractional part is truncated. For example,
--- 5 // 2
--- 2 // 4
To compute (a with an exponent of b) for any numbers a and b,
you can write a ** b in Python.
--- 2.3 ** 3.5
--- (-2.5) ** 2
2.8 What is wrong in the following statement?
2.9 What is x, y, and z after the following statement?
x = y = z =0
2.10 Assume that a = 1and b = 2. What is a and b after the following statement?
a, b = b, a
2.12 If today is Tuesday, what day of the week will it be in 100 days?
2.13What is the result of 25 / 4? How would you rewrite the expression if you wished the result to be an integer number?
write a program that obtains minutes and remaining seconds from an amount of time in seconds. For example, 500 seconds contains 8 minutes and 20 seconds.
Assume that a = 1, and that each expression is independent. What are the results ofthe following expressions?
a += 4
a -= 4
a *= 4
a /= 4
a //= 4
a %= 4
a = 56* a + 6
2.17 What does a conversion from a float to an integer do with the fractional part of the
float value? Does the int(value)function change the variable value?
2.18 Are the following statements correct? If so, show their printout.
value = 4.6
print(eval("4 * 5 + 2"))
The problem is to develop a program that displays the current time in Greenwich Mean Time(GMT) in the format hour:minute: second, such as 13:19:18. The time() function in the time module returns the current time in seconds with millisecond precision elapsed since the time 00:00:00 on January 1, 1970, GMT, as shown in Figure 2.1. This time is known as the UNIX epoch. The epoch is the point when time starts.1970 was the year when the UNIX operating system was formally introduced.
returns 1285543663.205, which means 1285543663 seconds and 205 milliseconds.