python 基础学习1
‘‘‘import random #随机数标准库name ="let‘s go"age=11title=‘你好"python"‘content=‘"how old are you‘加油‘"print(type(age)) #打印age变量类型print(name)#输出name变量#age=input(‘请输入你的年龄‘) #input接收输入的值,且输入进来的都是string类型num=random.randint(1,10)#输出随机数print(num)‘‘‘#密码不回显getpass在pycharm中不生效#import getpass#password=getpass.getpass(‘请输入密码:‘)#print(password)#----------------------if 语法类型 if 条件 : else:#age=input(‘请输入年龄:‘)#age=int(age)#if age <18:# print(‘未成年人‘)#else:# print(‘成年人‘)#------------------多重if判断# score =input(‘请输入你的分数:‘)# score=int(score)# if score >=90:# print(‘成绩优秀‘)# elif score <90 and score >=80:# print(‘成绩优良‘)# elif score >=60:# print(‘成绩及格‘)# else:# print(‘成绩未及格‘)#--------------whille 循环 count计数器# n=10# count=0# while count <n:# print(count)# count +=1#-------------while else 判断## num =5## count =0# while count<3:# guess=input(‘请输入你猜得数字:‘)# guess=int(guess)# if guess <num:# print(‘猜小了‘)# elif guess >num:# print(‘猜大了‘)# else:# print(‘猜对了‘)# break# count +=1# else:# print(‘猜奖次数已用完‘)#------------for 循环#num=5#count=0 for循环中 count变量会自增 0-3# for count in range (3):# guess =input(‘请输入你猜得数字:‘)# guess=int(guess)# if guess <num:# print(‘猜小了‘)# elif guess>num:# print(‘猜大了‘)# else:# print(‘猜对了‘)# break# print(‘次数已用完‘)#---------------占位符 输出 %s 字符串 %d 整数 %.2f:保留两位小数 占位符 后面%(变量1,变量2)# import datetime# today1=datetime.date.today();# welcome= ‘欢迎光临今天得日期是:‘ + today1#print(welcom)#welcom1=‘欢迎光临今天得日期是:%s‘%(today1)#print(welcom1)username = input(‘请输入用户名‘)# welcome = ‘欢迎光临‘ + username #这种种方式,不推荐使用,浪费内存# print(welcome)welcome=‘欢迎光临{yourname}‘.format(yourname=username)print(welcome)
相关推荐
xirongxudlut 2020-06-01
elizabethxxy 2020-11-06
pythonxuexi 2020-10-30
retacnyue 2020-09-28
pythonxuexi 2020-09-06
Morelia 2020-09-04
zhaobig 2020-08-17
linkequa 2020-08-16
CloudXli 2020-08-14
kikaylee 2020-08-12
LowisLucifer 2020-08-09
xiesheng 2020-08-06
Tristahong 2020-08-05
CatherineC00 2020-08-01
Andrewjdw 2020-07-26
reallyr 2020-07-18
wordmhg 2020-07-16
yawei 2020-07-06