hello.py

print("明天,你好!")
input("输入任意键继续")
View Code

 

整数平方值计算器:

print("此程序可以计算一个整数的平方值。")
print("************欢迎使用************")

print("\n\n")
tip="操作说明:\n输入数字查看平方值,\n输入exit退出程序:\n"

def compute():
    value = input(tip)
    if value=="exit":
        exit(1)
    else:
        print("结果:"+str(int(value)*int(value)))
    pass

while 1:
    compute()
    pass
View Code

 

  

数字四则计算和字符串查找、大小写转换

 

print("明天,你好!")


a=12
b=21
c=a+b
print(c)

c=b-a
print(c)
c=2*3
print(c)
c=4/2
print(c)

# 注释快捷键 ctrl + /
# c="明天"-"你好" 
# 计算是针对特定数据才有意义
# 解释器逐行顺序执行
# dddddddsersgaerrghads
print("hello world!")

# 大小写转换
print("hello WORLD!".lower())

print("hello world!".upper())
# print(1.upper())

# 字符串查找

print("**************")
# 下标 从0开始计数
print("hello world".find("hello"))

print("hello world".find("world"))
View Code

 

说反话的机器人:

robot = "机器人说:"

def answer(words):
    reversed_words = reversed(words)
    print(type(reversed_words))
    result = "".join(reversed_words)
    return result

while True:
    instruction = input("你说:")
    if instruction=="exit":
        exit(0)
    print(robot+answer(instruction))
View Code

 

年龄查询脚本和数据文件:

#encoding=utf-8
g_data={}

def loadData():
    file = open("personData.txt",encoding="utf-8")
    line = file.readline()
    while line:
        items = line.split(",")
        if len(items)>=2:
            g_data[items[0]]=items[1]
        line = file.readline()
    file.close()

loadData()

while True:
    instruction = input("请输入:\n")
    if instruction=="exit":
        exit(0)
        pass
    if instruction=="load":
        loadData()
        continue
    age = g_data.get(instruction)
    if age:
        print(instruction+"的年龄是"+age)
    else:
        print("没有找到"+instruction+"的相关信息")
View Code

 

小明,22
张三,23
李四,24
王五,25
赵六,26
小红,18
View Code

 

 

 

 

=====