python-note01

#!/usr/bin/python
# -*- coding: UTF-8 -*-
# 着是我创建的第一个py文件
# print函数输出内容   字符串、数字、含有运算符的表达式
'''
  Print函数输出到文件 注意事项   1>  有一个存在的盘符   2>  使用file =
  ex:ht=open('D:/text.txt','a+')      a代表的是 以读写的方式打开   如果文件存在在在基础上添加新的内容  不存在则重新创建
print('hello ht',file=ht)
fp.close()
'''
# fp=open('D:/text.txt','a+')
# print('hello',file=fp)
# fp.close()
# print('hello','pw')
'''
 转义字符   反斜杠+想要实现转移功能的字母 
 当 字符串中 包含换行  、回车、水平制表符、退格 等特殊字符时,也可以使用转义 字符串中包含换行、回车、水平测试表符
 换行 \n    回车\r    水平制表符\t  退格\b
 原字符  不希望字符中的转义字符起作用,就使用原字符, 就是在字符串之前 加上r或R  
 print(r'hello\nword')         #hello\nword
 #注意事项最后一个字符不能是反斜杠
print(r'hello\nworld\\')
'''
#  保留字(保留字)  它们都不能用作任何标识符名称
import  keyword
h=keyword.kwlist
# print(h)
"""
['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
"""
#数字类型   Int  bool  float  complex(复数)
'''
python抽奖小游戏逻辑实现
  1.导入随机数 
'''
#同一行显示多条语句
import sys; x = 'xiao~tian'; sys.stdout.write(x + '\n')
#抽奖小游戏
import random
random.random()
name_list = ['张三','李四','王五','赵六','王一','吴二','郑7','王8','冯9','陈0']
random.randint(0,len(name_list)-1)
name_list[random.randint(0,len(name_list)-1)]
sample=[]
while len(sample) < 1:
    name = name_list[random.randint(0,len(name_list)-1)]
    if name not in sample:
        sample.append(name)
print("中奖名单是:", sample)
#猜大小
from random import randint
num=randint(1,10)
print(num)
res=int (input("请输入你要猜的数字"))
if(res==num):
    print("猜对了")
elif(res>num):
    print("猜大了")
elif(res<=num):
    print("猜小了")
posted @ 2021-11-04 20:40  Gurad-your-heart  阅读(54)  评论(0)    收藏  举报