初学python,记录下自己的历程~
了解了一下python的基本概念,现在使用的比较多的就是python2.7
学习了if语句和两个经典的循环语句
#关于if语句的应用 name = raw_input(‘input name‘) age = input(‘input age‘) #也可以用input salary = raw_input(‘salary‘) #使用if语句永远只有一个结果,满足条件即结束 if age > 60: msg = ‘you are too old‘ elif age > 30: msg = ‘you are not young‘ else: msg = ‘you are still young‘ print‘‘‘ information of %s: name:%s age:%d salary:%s ________________________ %s ‘‘‘ %(name, name, age ,salary, msg)#必须一一对应
#关于for循环(猜年龄) real_age = 18 for i in range(10): age = input(‘age:‘) if age > real_age: print ‘think smaller‘ elif age < real_age: print ‘think bigger‘ else: print ‘you are right‘ break print ‘you still have %s shots‘ % (9 - i)
#关于while循环(选定打印的数) import sys num = 0 count = 0 while count <=1000: if count == num: print ‘there is the number‘, count while num <= count: num = input(‘which number do you want? inuput 0 to exist‘) if num == 0: sys.exit() if num <= count: print ‘it is over‘ else: print ‘loop:‘, count count += 1 else: print ‘loop:‘, count
时间: 2024-10-06 07:42:52