作者:奔跑的人儿 | 来源:互联网 | 2023-10-13 10:10
linux系统用vim编辑python不方便,我们在windows安装pycharm软件(百度找安装方法) 基础语法:importgetpassimportsys,os#os.sy
linux 系统用vim编辑python不方便,我们在windows安装 pycharm 软件(百度找安装方法)
基础语法:
import getpass
import sys,os
#os.system("df -h") #调用系统命令
#os.system(''.join(sys.argv[1:])) #把用户的输入的参数当作一条命令交给os.system来执行
_name = "xj"
_passwd = "123456"
name = input("你的名字是:" )
age = int(input("年龄:"))
print(type(age))
#passwd = getpass.getpass("请输入密码:")
passwd = input("请输入用户密码:")
info = '''
name = %s
age = %d
''' % (name,age)
print(name,age)
print(info)
print(passwd)
if_else 语句:
_name = "xj"
_passwd = "123456"
if _name == name and _passwd == passwd:
print("正确 {yonghu} ".format(yOnghu=name))
else:
print("错误")
while 语句:
age_of_xj = 29
count = 0
while count <3:
input_age = int((input("猜一个年龄:")))
if age_of_xj == input_age:
print("恭喜猜对了")
break
elif age_of_xj > input_age:
print("猜小了")
else:
print("猜大了")
count +=1
else:
print(" 糟糕,猜错三次了,没有机会了")
for 语句:
age_of_xj = 29
for n in (range(0,10)): #range(0,10,2) 每隔一个输出一个数字
print(n)
input_age = int((input("猜一个年龄:")))
if age_of_xj == input_age:
print("恭喜猜对了")
break
elif age_of_xj > input_age:
print("猜小了")
else:
print("猜大了")
else:
print(" 糟糕,猜错三次了,没有机会了")