zoukankan      html  css  js  c++  java
  • python格式化输出基础知识(2)

    ---恢复内容开始---

    一:请输入名片  (姓名,年龄,职业,爱好)设计名片


    name=input('你的名字')

    age=input('你的年龄')

    job=input('你的工作')

    hobbie=input('你的爱好')

    msg=''' inof of %s

    name:%s

    age:%s

    job:%s

    hobbie:%s end ''' %(name,name,age,job,hobbie)

    print(msg)

    二:%的使用

    name=input('你的名字')
    age=input('你的年龄')
    height=input('你的身高')

    msg='''我叫%s,我的年龄是%d,学习进度是%%3,我的身高是%s, ''' %(name,int(age),height)
    print(msg)

    # 我的年龄是如果输入%s %(name,age,height)
    # 我的年龄是如果输入%d   %(name,int(age),height)

    三if条件语句

    '''
    一: if(空格) 条件语句:
    (tab键空格)tab结果
    else:
    (tab键空格)tab结果



    二: if elif
    if(空格)条件语句:
    (tab键空格)tab结果
    elif(空格)条件语句:
    (tab键空格)tab结果
            elif(空格)条件语句:
    (tab键空格)tab结果


                 三:   if(空格) 条件语句:

               (tab键空格)tab结果


    '''
    四 while循环

    写出1到9的循环
    count=0
    while count<9:
    count+=1
    print(count)


    写出1到10的循环
    count=0
    while count<10:
    count+=1
    print(count


    写出1到11的循环
    count=0
    while count<=10:
    count+=1
    print(count)
    一:求1到100的和
    列出数字1,2,3,4,,100
    加入while循环

    找关系:count=count+1
    sum=sum+count

    列出限定循环条件

    print()

    print(求和与while平级 循环在while子集 )

    解题步骤:
    count=1
    sum=0
    while count<=100:
    sum = sum + count
    count=count+1
    print(sum)

    奇数
    count=1
    sum=0
    while count<=100:
    sum = sum + count
    count=count+2
    print(sum)

    偶数
    count=2
    sum=0
    while count<=100:
    sum = sum + count
    count=count+2
    print(sum)

    1-2+3-4+....99

    count1=1
    sum1=0
    count2=2
    sum2=0
    while count1<100:
    sum1=sum1+count1
    count1=count1+2
    while count2<100:
    sum2=sum2+count2
    count2=count2+2
    sum=sum1-sum2

    print(sum)


     
     
     

















     

    ---恢复内容结束---

  • 相关阅读:
    指针数组和数组指针的区别 以及数组引用
    自定义触摸事件封装
    Android使用C++截屏并显示
    C++使用binder实例
    C++的友元类和友元函数实例
    使用C++在andrdoid上画贝塞尔曲线
    PowerManagerService分析(一)之PMS启动
    PowerManagerService分析(二)之updatePowerStateLocked()核心
    PowerManagerService分析(三)之WakeLock机制
    PowerManagerService分析(四)之亮屏流程分析
  • 原文地址:https://www.cnblogs.com/12121wdw/p/8045209.html
Copyright © 2011-2022 走看看