linux 系统用vim编辑python不方便,我们在windows安装 pycharm 软件(百度找安装方法)
基础语法: import getpassimport 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 = %sage = %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 = 0while count < 3: input_age = int((input("猜一个年龄:"))) if age_of_xj == input_age: print("恭喜猜对了") break elif age_of_xj > input_age: print("猜小了") else: print("猜大了") count +=1else: 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(" 糟糕,猜错三次了,没有机会了")
原文地址:https://www.cnblogs.com/jim-xu/p/11660719.html
时间: 2024-10-01 07:13:09