#!/usr/bin/env python3
print("hello world")
#数据类型
int("45")
str(912)
#[]使用
"Hard Times"[5]
#对象引用
x = "bule"
y = "green"
z = x
#元组使用逗号创建
tuple = ("Denmark", "Finland", "Norway","Sweden")
#in, not in 成员操作符
p = (4, "frog", 9, -33, 9, 2)
2 in p
"dog" not in p
#逻辑运算符 and or not,返回决定结果的操作数,不返回bool值
five = 5
two = 2
zero = 0
five and two
two and five
five and zero
#if语句
lines = 500
if lines < 1000:
print("small")
elif lines < 10000:
print("medium")
else :
print("large")
#while语句
while True:
item = get_next_item()
if not item:
break
process_item(item)
#for in语句
countries = ["Denmark", "Finland", "Norway","Sweden"]
for countrie in countries:
print(countrie)
#算数操作符+,-,*,/
5 + 6
#输出print
print("Type interges, each followed by Enter; or just Enter tofinish")
total = 0
count = 0
while True:
line = input("integer:")
if line:
try:
number = int (line)
except ValueError as Error:
print(Error)
continue
total += number
count += 1
else:
break
if count:
print("count = ", count,"total = ", total, "mean = ", total / count)
#函数创建及调用
def get_int(msg):
while True:
try:
i = int(input(msg))
return i
except ValueError as err:
print(err)
age = get_int("enter your age:")
#导入模块improt
import random
x = random.randint(1, 6)
y = random.choice(["apple", "banana", "cherry","durian"])