python学习笔记基础练习day1

python学前基础知识

 1.下载安装python3 (https://www.python.org/downloads/),默认安装

2.配置环境变量【右键计算机】--》【属性】--》【高级系统设置】--》【高级】--》【环境变量】--》【在第二个内容框中找到 变量名为Path 的一行,双击】 --> 【Python安装目录追加到变值值中】

3.安装pycharm,从setting--》file and code templates可以设置默认模板。

#_*_coding:utf-8_*_

hello world程序

print('hello word!')
#输出:hello word!

  变量

变量名首字母不能为数字

变量是用来被赋值的,指向的是内存特定的内存地址

name1= 'python'
name2 = name1
name1 = 'java'
print(name2)
#输出的是python

3种多行格式化输出

 1.

name = input('please input your name:')
age = input('please input your age:')
job = input('please input your job:')
salary = input('please input your salary:')
info = '''
-------------info of %s------------
name:%s
age:%s
job:%s
salary:%s'''%(name,name,age,job,salary)
print(info)

2.

name = input('username:')
age = input('age:')
salary = input('salary:')
info ='''
------------------name is {_name}----------------
username:{_name}
age:{_age}
salary:{_salary}
'''.format(_name = name,_age = age,_salary = salary)
print(info)

3.

name = input('username:')
age = input('age:')
salary = input('salary:')
info ='''
------------------name is {0}----------------
username:{0}
age:{1}
salary:{2}
'''.format(name,age,salary)
print(info)

python基础day1知识点附加

 python中不能把两个完全不同的东西加在一起但可以乘一个整数翻倍如:

print('l love money'+5) #输出是fail的
print('l love money'*5)#输出5遍i love money

但字符串是可以拼接的如:

print('s'+'pam') #输出是的spam

python基础day1练习题与解答

 1.要求用户输入数值0-100,如果小于50打印‘你输得对’如果大于50打印‘你输错了’

num = input('please input you number 0-100:')
num = int(num)
if num <= 50:
    print('你输对了')
else:
    print('你输错了')
View Code

2.猜年龄三次机会,年龄‘23’猜年龄大了小了都有提示‘young’,‘old’

_age = '23'
count = 0
while True:
    if count == 3:
        break
    age = input('guess age:')
    if age > _age :
        print('old')
    elif age < _age :
        print('young')
    else:
        print('good work!')
        break
    count = count +1
View Code

3.编写登录程序,用户有三次输错机会输错超过3次锁定,输入密码不可见

name = 'python'
key = '123@intel'
count = 0
while True:
    username = input('username:')
    password = input('password:')
    if count < 3:
        if username == name and password == key :
            print('welcome user %s'%(name))
        else:
            print('invalid username or password!')
            count +=1
    else:
        print('you have been locked!')
View Code


---恢复内容结束---

---恢复内容结束---

猜你喜欢

转载自www.cnblogs.com/pingdiguo/p/11441964.html