print('Yankees rule!')
print('But not in Boston!')
print('Yankees rule,', 'but not in Boston!')
Yankees rule! But not in Boston! Yankees rule, but not in Boston!
5
5
3.27
3.27
type(5)
int
type(3.0)
float
float(3)
3.0
int(3.9)
3
3+2
5
print(3+2)
5
5+3
8
5.0+3
8.0
5-3
2
5*3
15
5/2
2.5
5/2.0
2.5
5//2
2
5//2.0
2.0
5%2
1
2**3
8
1+5*3
16
(1+5)*3
18
pi = 3.14159
print(pi)
3.14159
pi_approx = 22/7
print(pi_approx)
3.142857142857143
pi = 3.14159
radius = 5
# công thức diện tích của hình tròn <- this is a comment
area = pi * (radius ** 2)
print(area)
78.53975
pi = 3.14159
radius = 2.2
# công thức diện tích của hình tròn <- this is a comment
area = pi * (radius ** 2)
print(area)
# thay đổi giá trị của bán kính <- another comment
# sử dụng các comment để giúp người khác hiểu bạn đang làm gì
radius = radius + 1 # tăng giá trị của biến lên 1 đơn vị
print(area) # diện tích chưa thay đổi
area = pi*(radius**2)
print(area)
15.205295600000001 15.205295600000001 32.169881600000004
#############################
#### AUTOCOMPLETE #######
#############################
# Spyder can autocomplete names for you
# start typing a variable name defined in your program and hit tab
# before you finish typing -- try it below
# define a variable
a_very_long_variable_name_dont_name_them_this_long_pls = 1
# below, start typing a_ve then hit tab... cool, right!
# use autocomplete to change the value of that variable to 1
# use autocomplete to write a line that prints the value of that long variable
# notice that Spyder also automatically adds the closed parentheses for you!
# Multiple assigment
x, y = 2, 3
x, y = y, x # swap variables
print('x =', x)
print('y =', y)
5 > 3
True
3 >= 5
False
3 < 5
True
5 <= 3
False
3 == 3
True
3 == 3.0
True
3 != 3.0
False
a = True
not a
False
a = True
b = False
a and b
False
a = True
b = False
a or b
True
x = int(input('Enter an integer:'))
if x % 2 == 0:
print('')
print('Even')
else:
print('')
print('Odd')
print('Done with conditional')
Enter an integer:3 Odd Done with conditional
x = int(input('Enter an integer:'))
if x % 2 == 0:
if x % 3 == 0:
print('Divisible by 2 and 3')
else:
print('Divisible by 2 and not by 3')
elif x % 3 == 0:
print('Divisible by 3 and not by 2')
else:
print('Indivisible by 2 and 3')
Enter an integer:6 Divisible by 2 and 3
x = 2
y = 3
z = 4
if x < y and x < z:
print('x is least')
elif y < z:
print('y is least')
else:
print('z is least')
x is least
x = float(input('Enter a number for x:'))
y = float(input('Enter a number for y:'))
if x == y:
print('x and y are equal')
if y != 0:
print('therefore, x / y is', x/y)
elif x < y:
print('x is smaller')
else:
print('y is smaller')
print('thanks!')
Enter a number for x:3 Enter a number for y:3 x and y are equal therefore, x / y is 1.0 thanks!
Write a program that examines three variables—x, y, and z—and prints the largest odd number among them. If none of them are odd, it should print a message to that effect.