this is a test4
#coding=utf-8
counter = a = 100
miles = 1000.0
name = "echo"
print counter
print miles
print name
print a
str = 'Hello World!'
print str
print str[0]
print str[2:5]
print str[2:]
print str * 2
print str + "echo"
print "\n\n以下是python数据类型中的List——列表"
list = ['abcd',789,2.23,'echo',29.48]
tinylist = [123,'echo']
print list
print list[0]
print list[1:3]
print list[2:]
print tinylist * 2
print list + tinylist
print "\n\n以下是python数据类型中的Tuple——元组"
tuple = ('abcd',789,2.23,'echo',29.48)
tinytuple = (123,'echo')
print tuple
print tuple[0]
print tuple[1:3]
print tuple[2:]
print tinytuple * 2
print tuple + tinytuple
print "\n\n以下是python数据类型中的Dict——字典"
dict = {}
dict['one'] = "This is one"
dict[2] = "This is two"
tinydict = {'name':'echo','tel':15110275634,'address':'beijing'}
print dict['one']
print dict[2]
print tinydict
print tinydict.keys()
print tinydict.values()
a = 21
b = 10
c = 0
c = a + b
print "Line 1 - Value of c is ", c
c = a - b
print "Line 2 - Value of c is ", c
c = a * b
print "Line 3 - Value of c is ", c
c = a / b
print "Line 4 - Value of c is ", c
c = a % b
print "Line 5 - Value of c is ", c
a = 2
b = 3
c = a**b
print "Line 6 - Value of c is ", c
a = 10
b = 5
c = a//b
print "Line 7 - Value of c is ", c
a = 21
b = 10
c = 0
if ( a == b ):
print "Line 1 - a is equal to b"
else:
print "Line 1 - a is not equal to b"
if ( a != b ):
print "Line 2 - a is not equal to b"
else:
print "Line 2 - a is equal to b"
if ( a <> b ):
print "Line 3 - a is not equal to b"
else:
print "Line 3 - a is equal to b"
if ( a < b ):
print "Line 4 - a is less than b"
else:
print "Line 4 - a is not less than b"
if ( a > b ):
print "Line 5 - a is greater than b"
else:
print "Line 5 - a is not greater than b"
a = 5
b = 20
if ( a <= b ):
print "Line 6 - a is either less than or equal to b"
else:
print "Line 6 - a is neither less than nor equal to b"
if ( b <= a ):
print "Line 7 - a is either greater than or equal to b"
else:
print "Line 7 - a is neither greater than nor equal to b"
num = 2
if num == 3:
print "num=", num
elif num == 2:
print "num=", num
else:
print "There is no num"
num = 8
# 判断值是否在0~5或者10~15之间
if (num >= 0 and num <= 5) or (num >= 10 and num <= 15):
print 'hello'
else:
print 'undefine'
for letter in 'Python': # First Example
print 'Current Letter :', letter
fruits = ['banana', 'apple', 'mango']
for fruit in fruits: # Second Example
print 'Current fruit :', fruit
print "Good bye!"
fruits = ['banana','apple','mango']
for index in range(len(fruits)):
print 'Current fruit : ', fruits[index]
print "Good bye!"
for num in range(10,20):
for i in range(2,num):
if num%i == 0:
j = num / i
print '%d equals %d * %d' % (num,i,j)
break
else:
print num, 'is a prime number'
i = 2
while(i < 100):
j = 2
while(j < i):
if not(i%j):break
j += 1
if j == i :print i, " 是素数"
i += 1
print "Good bye"
The results:
100
1000.0
echo
100
Hello World!
H
llo
llo World!
Hello World!Hello World!
Hello World!echo
以下是python数据类型中的List——列表
['abcd', 789, 2.23, 'echo', 29.48]
abcd
[789, 2.23]
[2.23, 'echo', 29.48]
[123, 'echo', 123, 'echo']
['abcd', 789, 2.23, 'echo', 29.48, 123, 'echo']
以下是python数据类型中的Tuple——元组
('abcd', 789, 2.23, 'echo', 29.48)
abcd
(789, 2.23)
(2.23, 'echo', 29.48)
(123, 'echo', 123, 'echo')
('abcd', 789, 2.23, 'echo', 29.48, 123, 'echo')
以下是python数据类型中的Dict——字典
This is one
This is two
{'tel': 15110275634L, 'name': 'echo', 'address': 'beijing'}
['tel', 'name', 'address']
[15110275634L, 'echo', 'beijing']
Line 1 - Value of c is 31
Line 2 - Value of c is 11
Line 3 - Value of c is 210
Line 4 - Value of c is 2
Line 5 - Value of c is 1
Line 6 - Value of c is 8
Line 7 - Value of c is 2
Line 1 - a is not equal to b
Line 2 - a is not equal to b
Line 3 - a is not equal to b
Line 4 - a is not less than b
Line 5 - a is greater than b
Line 6 - a is either less than or equal to b
Line 7 - a is neither greater than nor equal to b
num= 2
undefine
Current Letter : P
Current Letter : y
Current Letter : t
Current Letter : h
Current Letter : o
Current Letter : n
Current fruit : banana
Current fruit : apple
Current fruit : mango
Good bye!
Current fruit : banana
Current fruit : apple
Current fruit : mango
Good bye!
10 equals 2 * 5
11 is a prime number
12 equals 2 * 6
13 is a prime number
14 equals 2 * 7
15 equals 3 * 5
16 equals 2 * 8
17 is a prime number
18 equals 2 * 9
19 is a prime number
2 是素数
3 是素数
5 是素数
7 是素数
11 是素数
13 是素数
17 是素数
19 是素数
23 是素数
29 是素数
31 是素数
37 是素数
41 是素数
43 是素数
47 是素数
53 是素数
59 是素数
61 是素数
67 是素数
71 是素数
73 是素数
79 是素数
83 是素数
89 是素数
97 是素数
Good bye
[Finished in 0.1s]

浙公网安备 33010602011771号