首页 > 编程语言 > 详细

python全栈开发NO.4作业

时间:2018-09-15 21:34:47      阅读:188      评论:0      收藏:0      [点我收藏+]

1.使用while循环输出1 2 3 4 5 6 8 9 10
答:count=0
       while count <11:
               if  count ==7
                     count+=1
                     cootinue

               print(count)
                count+=1

2.求1-100的所有数的和
答:s=0
       count=0
       while count <=100
             s = s+count
             count=count+1
             print(s)

3.输出1-100内的所有奇数
答:for i in range (1,100,2)
            print(i)

4.输出1-100内的所有偶数
答:count=1
    while count<=100
          if  count%2==0
              print(count)
          coumt+1

5.求1-2+3-4+5...99的所有数的和
答:e=1

       s=0

      while e <100:

             if e%2==0:

                     s-=e

              else:

                     s+=e

              e+=1

        print(s)

6:用户登录(三次机会重试)
答:print(‘start---’)
      count=0
       whine count<3:
                 name=input(‘your name---‘)
                 pwd=input(‘your password---‘)
                 if name ==‘tom‘ amd pwd==‘123‘
                       print(‘login successful‘)
                        break

                 else:
                      print(‘user or password’)
                      count+=1

7.猜年龄
答:count=0

       while count<3

               age=ipnut(‘my age?-----’)

                if age ==‘18‘ :

                  print(’恭喜猜对了‘)

                 break

              else:

                  print(‘user or parssword’)
                 count+=1

8.

  答:age_of_boy=18

         count=0

          while True:

               if  count==3

                    choice=input(‘继续(Y/y?)---)

                    if choice ==’Y‘ or choice=‘y’:

                          count=0

                   else:

                         break

            guess=int(input(‘----‘))
            if guess ==age of boy:

                print(‘恭喜猜对了’)

               break

                break

 

python全栈开发NO.4作业

原文:https://www.cnblogs.com/wuzhengzheng/p/9652262.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!