python 1.1条件语句等基础

1、条件语句和基本数据类型 

    if       input=inp     else   elif   print('')

2、运算 + - * / % **

3、字符串 n1=‘“alex”  n2=‘root’  n3="""eric""" n4='''tony'''

4、循环 while

作业

 a、使用while循环输入123456 8910

n = 1

while n < 11:

    if  n == 7:

        pass

    else:

        print (n)

    n = n + 1

print ( '----end----' )

b、求1-100的所有数的和

n = 1

s = 0

while n < 101:

    s = s + n

    n = n + 1

print(s)

print('----end----')

c、输入1-100内的所有奇数

n = 1

while n <101:

    temp = n % 2

    if temp == 0:

        pass

    else:

       print(n)

    n = n + 1

print('----end----')

d、输出1-100内的所有偶数

n = 1

while n < 101:

    temp = n % 2

    if temp == 0:

        print(n)

    else:

        pass

    n = n + 1

print('----end----')

e、求1-2+3-4+5……99的所有数的和

n = 1

s = 0

while n < 100:

    temp = n % 2

    if temp == 1:

        s = s + n

    else:

        s = s - n

    n = n + 1

print(s)

 

 

        

 

 

 

posted @ 2018-05-16 21:13  ...阿哲  阅读(87)  评论(0)    收藏  举报